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

Saving hyperparams in yaml file for Tensorboard for #521 #657

Merged
merged 7 commits into from
Aug 29, 2022
Merged
Changes from all 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
17 changes: 15 additions & 2 deletions src/accelerate/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
# Provide a project dir name, then each type of logger gets stored in project/{`logging_dir`}

import os
import time
from abc import ABCMeta, abstractmethod, abstractproperty
from typing import List, Optional, Union

import yaml

from .logging import get_logger
from .utils import LoggerType, is_comet_ml_available, is_tensorboard_available, is_wandb_available

Expand Down Expand Up @@ -142,7 +145,8 @@ def tracker(self):

def store_init_configuration(self, values: dict):
"""
Logs `values` as hyperparameters for the run. Should be run at the beginning of your experiment.
Logs `values` as hyperparameters for the run. Should be run at the beginning of your experiment. Stores the
hyperparameters in a yaml file for future use.

Args:
values (Dictionary `str` to `bool`, `str`, `float` or `int`):
Expand All @@ -151,7 +155,16 @@ def store_init_configuration(self, values: dict):
"""
self.writer.add_hparams(values, metric_dict={})
self.writer.flush()
logger.info("Stored initial configuration hyperparameters to TensorBoard")
project_run_name = time.time()
dir_name = os.path.join(self.logging_dir, str(project_run_name))
os.makedirs(dir_name, exist_ok=True)
with open(os.path.join(dir_name, "hparams.yml"), "w") as outfile:
try:
yaml.dump(values, outfile)
except yaml.representer.RepresenterError:
logger.error("Serialization to store hyperparameters failed")
raise
logger.info("Stored initial configuration hyperparameters to TensorBoard and hparams yaml file")

def log(self, values: dict, step: Optional[int] = None, **kwargs):
"""
Expand Down