Skip to content
Snippets Groups Projects
Commit 31536873 authored by Bar's avatar Bar Committed by Neta Zmora
Browse files

Store qe_stats_file in output directory (#262)

Function log_execution_env_state is used to gather information about the execution environment and store this together with the experiment log.  Recently we've added saving the compression schedule YAML file in the same logs directory.
This commit expands the log_execution_env_state interface to accept a list of paths to arbitrary files that may contribute to the experiment configuration and that you (the experiment owner) deem important for recreating the experiment.

In the sample classifier_compression.py app, we now store both the compression schedule YAML file and quantization statistics collateral file (qe_stats_file).
parent a7635ea1
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,6 @@ This is helpful if you want to recreate an experiment at a later time, or if ...@@ -20,7 +20,6 @@ This is helpful if you want to recreate an experiment at a later time, or if
you want to understand the environment in which you execute the training. you want to understand the environment in which you execute the training.
""" """
import contextlib
import logging import logging
import logging.config import logging.config
import os import os
...@@ -41,16 +40,16 @@ except ImportError: ...@@ -41,16 +40,16 @@ except ImportError:
logger = logging.getLogger("app_cfg") logger = logging.getLogger("app_cfg")
def log_execution_env_state(config_path=None, logdir=None, gitroot='.'): def log_execution_env_state(config_paths=None, logdir=None, gitroot='.'):
"""Log information about the execution environment. """Log information about the execution environment.
File 'config_path' will be copied to directory 'logdir'. A common use-case Files in 'config_paths' will be copied to directory 'logdir'. A common use-case
is passing the path to a (compression) schedule YAML file. Storing a copy is passing the path to a (compression) schedule YAML file. Storing a copy
of the schedule file, with the experiment logs, is useful in order to of the schedule file, with the experiment logs, is useful in order to
reproduce experiments. reproduce experiments.
Args: Args:
config_path: path to config file, used only when logdir is set config_paths: path(s) to config file(s), used only when logdir is set
logdir: log directory logdir: log directory
git_root: the path to the .git root directory git_root: the path to the .git root directory
""" """
...@@ -89,21 +88,25 @@ def log_execution_env_state(config_path=None, logdir=None, gitroot='.'): ...@@ -89,21 +88,25 @@ def log_execution_env_state(config_path=None, logdir=None, gitroot='.'):
log_git_state() log_git_state()
logger.debug("Command line: %s", " ".join(sys.argv)) logger.debug("Command line: %s", " ".join(sys.argv))
if (logdir is None) or (config_path is None): if (logdir is None) or (config_paths is None):
return return
# clone configuration files to output directory # clone configuration files to output directory
configs_dest = os.path.join(logdir, 'configs') configs_dest = os.path.join(logdir, 'configs')
with contextlib.suppress(FileExistsError):
os.makedirs(configs_dest) if isinstance(config_paths, str) or not hasattr(config_paths, '__iter__'):
if os.path.exists(os.path.join(configs_dest, config_paths = [config_paths]
os.path.basename(config_path))): for cpath in config_paths:
logger.debug('{} already exists in logdir'.format( os.makedirs(configs_dest, exist_ok=True)
os.path.basename(config_path) or config_path))
else: if os.path.exists(os.path.join(configs_dest, os.path.basename(cpath))):
try: logger.debug('{} already exists in logdir'.format(
shutil.copy(config_path, configs_dest) os.path.basename(cpath) or cpath))
except OSError as e: else:
logger.debug('Failed to copy of config file: {}'.format(str(e))) try:
shutil.copy(cpath, configs_dest)
except OSError as e:
logger.debug('Failed to copy of config file: {}'.format(str(e)))
def config_pylogger(log_cfg_file, experiment_name, output_dir='logs'): def config_pylogger(log_cfg_file, experiment_name, output_dir='logs'):
......
...@@ -97,7 +97,9 @@ def main(): ...@@ -97,7 +97,9 @@ def main():
# Log various details about the execution environment. It is sometimes useful # Log various details about the execution environment. It is sometimes useful
# to refer to past experiment executions and this information may be useful. # to refer to past experiment executions and this information may be useful.
apputils.log_execution_env_state(args.compress, msglogger.logdir, gitroot=module_path) apputils.log_execution_env_state(
filter(None, [args.compress, args.qe_stats_file]), # remove both None and empty strings
msglogger.logdir, gitroot=module_path)
msglogger.debug("Distiller: %s", distiller.__version__) msglogger.debug("Distiller: %s", distiller.__version__)
start_epoch = 0 start_epoch = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment