torchdistill.misc
torchdistill.misc.log
- torchdistill.misc.log.set_basic_log_config()[source]
Sets a default basic configuration for logging.
- torchdistill.misc.log.setup_log_file(log_file_path)[source]
Sets a file handler with
log_file_pathto write a log file.- Parameters:
log_file_path (str) – log file path.
- class torchdistill.misc.log.TrainingTracker(engine, **kwargs)[source]
A thin wrapper around an experiment tracking library (trackio or wandb). The library is imported lazily so that it stays an optional dependency.
- Parameters:
engine (str) – tracking library name (‘trackio’ or ‘wandb’).
kwargs (dict) – keyword arguments passed to the library’s
initfunction (e.g.,project,name,config). See the external references below for available arguments.
An example to instantiateTrainingTrackerand log metrics with it.tracker = TrainingTracker( 'trackio', project='torchdistill-cifar10', name='resnet18-kd-run1', config={'train': {'num_epochs': 182}, 'student_model': 'resnet18'} ) tracker.log({'train/loss': 0.512, 'train/lr': 0.1}, step=100) tracker.log({'val/acc1': 92.3, 'epoch': 0}, step=391) tracker.finish()
See also
Trackio documentation (
trackio.init) forengine='trackio'wandb.init reference for
engine='wandb'
- torchdistill.misc.log.setup_tracker(tracker_config, run_config=None)[source]
Sets up a
TrainingTrackerfromtracker_config.- Parameters:
tracker_config (dict or None) – tracker configuration with ‘engine’ (‘trackio’ or ‘wandb’) and optional ‘kwargs’ passed to the library’s
initfunction. If None or its ‘engine’ is None, no tracker is set up.run_config (dict or None) – run configuration (e.g., loaded yaml config) to be logged as the run’s config.
- Returns:
training tracker if configured and this is the main process, None otherwise.
- Return type:
TrainingTracker or None
An example (partial) YAML config whosetrackerentry is passed tosetup_tracker()astracker_config.kwargsis passed as-is totrackio.init/wandb.init.tracker: engine: 'trackio' kwargs: project: 'torchdistill-cifar10' name: 'resnet18-kd-run1'
An example to set up aTrainingTrackerwith the YAML config above.config = yaml_util.load_yaml_file('/path/to/the/yaml/config/above.yaml') tracker = setup_tracker(config.get('tracker', None), run_config=config) # Equivalent dict-based setup without a YAML file tracker = setup_tracker( {'engine': 'trackio', 'kwargs': {'project': 'torchdistill-cifar10', 'name': 'resnet18-kd-run1'}}, run_config=config )
See also
Trackio documentation (
trackio.init) forengine: 'trackio'wandb.init reference for
engine: 'wandb'
- class torchdistill.misc.log.TrainingTrackerReader(engine, wandb_entity=None)[source]
A read-side companion to
TrainingTrackerthat loads metrics logged with trackio or wandb back aspandas.DataFrame. The libraries are imported lazily so that they stay optional dependencies.- Parameters:
engine (str) – tracking library name (‘trackio’ or ‘wandb’).
wandb_entity (str or None) – wandb entity (user or team name). Used only if
engine= ‘wandb’. If None, the default entity of the wandb API key is used.
An example to load the run history logged with theTrainingTrackerexample.reader = TrainingTrackerReader('trackio') history = reader.load_run_history('torchdistill-cifar10', 'resnet18-kd-run1') # `history` is a pandas.DataFrame with 'step', 'relative_time', and metric columns # such as 'train/loss' and 'val/acc1' print(history[history['val/acc1'].notna()][['epoch', 'val/acc1']])
See also
Trackio documentation for
engine='trackio'wandb public API reference for
engine='wandb'
- load_run_history(project, run_name)[source]
Loads the metric history of a run as a
pandas.DataFrame, one row per logged step. Engine-specific columns are normalized so that ‘step’ and ‘relative_time’ (seconds since the first log) are available for both engines, in addition to the logged metric columns.- Parameters:
project (str) – project name used at logging time.
run_name (str) – run name used at logging time.
- Returns:
metric history of the run.
- Return type:
pandas.DataFrame
- class torchdistill.misc.log.SmoothedValue(window_size=20, fmt=None)[source]
A deque-based value object tracks a series of values and provides access to smoothed values over a window or the global series average. The original implementation is https://github.com/pytorch/vision/blob/main/references/classification/utils.py
- Parameters:
window_size (int) – window size.
fmt (str or None) – text format.
- class torchdistill.misc.log.MetricLogger(delimiter='\t', tracker=None, tracker_prefix='', tracker_start_step=0)[source]
A metric logger with
SmoothedValue. The original implementation is https://github.com/pytorch/vision/blob/main/references/classification/utils.py- Parameters:
delimiter (str) – delimiter in a log message.
tracker (TrainingTracker or None) – training tracker to log metrics with. If None, no tracking is done.
tracker_prefix (str) – prefix prepended to metric names when logging with
tracker(e.g., ‘train/’).tracker_start_step (int) – global step at which this logger’s iterations start.
- update(**kwargs)[source]
Updates a metric dict whose values are
SmoothedValue.- Parameters:
kwargs (dict) – keys and values.
- add_meter(name, meter)[source]
Add a new metric name and value.
- Parameters:
name (str) – metric name.
meter (SmoothedValue) – smoothed value.