From d67f7f9fa270d14abf04abb8082e69643011c1c0 Mon Sep 17 00:00:00 2001 From: Casper Date: Thu, 19 Dec 2024 19:11:40 +0100 Subject: [PATCH] Accessible config as dict (#754) Here is a PR to make it *a bit easier* to observe the configuration across different experiments. This is generally useful for MLOps to observe the exact configuration of your training run. For example, this makes it easier for a user to extend the code and log the config in Weights & Biases: ``` wandb.init(config=job_config.to_dict()) ``` --- torchtitan/config_manager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/torchtitan/config_manager.py b/torchtitan/config_manager.py index 6c9e07fc..b92d00a4 100644 --- a/torchtitan/config_manager.py +++ b/torchtitan/config_manager.py @@ -52,6 +52,7 @@ class JobConfig: """ def __init__(self): + self.args_dict = None # main parser self.parser = argparse.ArgumentParser(description="torchtitan arg parser.") @@ -610,6 +611,9 @@ def __init__(self): action="store_true", ) + def to_dict(self): + return self.args_dict + def parse_args(self, args_list: list = sys.argv[1:]): args, cmd_args = self.parse_args_from_command_line(args_list) config_file = getattr(args, "job.config_file", None) @@ -647,6 +651,8 @@ def parse_args(self, args_list: list = sys.argv[1:]): for k, v in section_args.items(): args_dict[section][k] = v + self.args_dict = args_dict + for k, v in args_dict.items(): class_type = type(k.title(), (), v) setattr(self, k, class_type())