Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sg 646 rename logs #667

Merged
merged 7 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/super_gradients/common/auto_logging/auto_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _setup_default_logging(self, log_level: str = None) -> None:
# Therefore the log file will have the parent PID to being able to discriminate the logs corresponding to a single run.
timestamp = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())
self._setup_logging(
filename=os.path.expanduser(f"~/sg_logs/sg_logs_{os.getppid()}_{timestamp}.log"),
filename=os.path.expanduser(f"~/sg_logs/logs_{os.getppid()}_{timestamp}.log"),
copy_already_logged_messages=False,
filemode="w",
log_level=log_level,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, data_connection_location: str = "local", data_connection_cred
"""
super().__init__()
self.tb_events_file_prefix = "events.out.tfevents"
self.log_file_prefix = "log_"
self.log_file_prefix = "experiment_logs_"
self.latest_checkpoint_filename = "ckpt_latest.pth"
self.best_checkpoint_filename = "ckpt_best.pth"

Expand Down
24 changes: 17 additions & 7 deletions src/super_gradients/common/sg_loggers/base_sg_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

logger = get_logger(__name__)

EXPERIMENT_LOGS_PREFIX = "experiment_logs"
LOGGER_LOGS_PREFIX = "logs"
CONSOLE_LOGS_PREFIX = "console"


class BaseSGLogger(AbstractSGLogger):
def __init__(
Expand Down Expand Up @@ -120,16 +124,22 @@ def _make_dir(self):
@multi_process_safe
def _init_log_file(self):
time_string = time.strftime("%b%d_%H_%M_%S", time.localtime())
# There are two log files, since the regular log_file_path used for `manual` logging of configs/other info
self.log_file_path = f"{self._local_dir}/log_{time_string}.txt"
self.log_full_file_path = f"{self._local_dir}/sg_logs_{time_string}.txt"
self.console_sink_path = f"{self._local_dir}/console_{time_string}.txt"
AutoLoggerConfig.setup_logging(filename=self.log_full_file_path, copy_already_logged_messages=True)

# Where the experiment related info will be saved (config and training/validation results per epoch_
self.experiment_log_path = f"{self._local_dir}/{EXPERIMENT_LOGS_PREFIX}_{time_string}.txt"

# Where the logger.log will be saved
self.logs_path = f"{self._local_dir}/{LOGGER_LOGS_PREFIX}_{time_string}.txt"

# Where the console prints/logs will be saved
self.console_sink_path = f"{self._local_dir}/{CONSOLE_LOGS_PREFIX}_{time_string}.txt"

AutoLoggerConfig.setup_logging(filename=self.logs_path, copy_already_logged_messages=True)
ConsoleSink.set_location(filename=self.console_sink_path)

@multi_process_safe
def _write_to_log_file(self, lines: list):
with open(self.log_file_path, "a" if os.path.exists(self.log_file_path) else "w") as log_file:
with open(self.experiment_log_path, "a" if os.path.exists(self.experiment_log_path) else "w") as log_file:
for line in lines:
log_file.write(line + "\n")

Expand Down Expand Up @@ -243,7 +253,7 @@ def upload(self):
self.model_checkpoints_data_interface.save_remote_tensorboard_event_files(self.experiment_name, self._local_dir)

if self.save_logs_remote:
log_file_name = self.log_file_path.split("/")[-1]
log_file_name = self.experiment_log_path.split("/")[-1]
self.model_checkpoints_data_interface.save_remote_checkpoints_file(self.experiment_name, self._local_dir, log_file_name)

@multi_process_safe
Expand Down
4 changes: 2 additions & 2 deletions src/super_gradients/common/sg_loggers/clearml_sg_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def upload(self):
self.task.upload_artifact(name=name, artifact_object=self._get_tensorboard_file_name())

if self.save_logs:
name = self.log_file_path.split("/")[-1]
self.task.upload_artifact(name=name, artifact_object=self.log_file_path)
name = self.experiment_log_path.split("/")[-1]
self.task.upload_artifact(name=name, artifact_object=self.experiment_log_path)

@multi_process_safe
def add_checkpoint(self, tag: str, state_dict: dict, global_step: int = 0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from typing import Optional

from super_gradients.common.abstractions.abstract_logger import get_logger
from super_gradients.common.sg_loggers.base_sg_logger import BaseSGLogger
from super_gradients.common.sg_loggers.base_sg_logger import BaseSGLogger, EXPERIMENT_LOGS_PREFIX, LOGGER_LOGS_PREFIX, CONSOLE_LOGS_PREFIX
from super_gradients.common.environment.ddp_utils import multi_process_safe
from super_gradients.common.plugins.deci_client import DeciClient

logger = get_logger(__name__)


TENSORBOARD_EVENTS_PREFIX = "events.out.tfevents"
LOGS_PREFIX = "log_"


class DeciPlatformSGLogger(BaseSGLogger):
Expand Down Expand Up @@ -74,7 +73,10 @@ def upload(self):
raise ValueError("Provided directory does not exist")

self._upload_latest_file_starting_with(start_with=TENSORBOARD_EVENTS_PREFIX)
self._upload_latest_file_starting_with(start_with=LOGS_PREFIX)
self._upload_latest_file_starting_with(start_with=EXPERIMENT_LOGS_PREFIX)
self._upload_latest_file_starting_with(start_with=LOGGER_LOGS_PREFIX)
self._upload_latest_file_starting_with(start_with=CONSOLE_LOGS_PREFIX)
self._upload_folder_files(folder_name=".hydra")

@multi_process_safe
def _upload_latest_file_starting_with(self, start_with: str):
Expand All @@ -91,3 +93,19 @@ def _upload_latest_file_starting_with(self, start_with: str):
most_recent_file_path = max(files_path, key=os.path.getctime)
self.platform_client.save_experiment_file(file_path=most_recent_file_path)
logger.info(f"File saved to Deci platform: {most_recent_file_path}")

@multi_process_safe
def _upload_folder_files(self, folder_name: str):
"""
Upload all the files of a given folder.

:param folder_name: Name of the folder that contains the files to upload
"""
folder_path = os.path.join(self.checkpoints_dir_path, folder_name)

if not os.path.exists(folder_path):
return

for file in os.listdir(folder_path):
self.platform_client.save_experiment_file(file_path=f"{folder_path}/{file}")
logger.info(f"File saved to Deci platform: {folder_path}/{file}")
2 changes: 1 addition & 1 deletion src/super_gradients/common/sg_loggers/wandb_sg_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def upload(self):
wandb.save(glob_str=self._get_tensorboard_file_name(), base_path=self._local_dir, policy="now")

if self.save_logs_wandb:
wandb.save(glob_str=self.log_file_path, base_path=self._local_dir, policy="now")
wandb.save(glob_str=self.experiment_log_path, base_path=self._local_dir, policy="now")

@multi_process_safe
def add_checkpoint(self, tag: str, state_dict: dict, global_step: int = 0):
Expand Down