Skip to content

Commit

Permalink
Accessible config as dict (#754)
Browse files Browse the repository at this point in the history
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())
```
  • Loading branch information
casper-hansen authored Dec 19, 2024
1 parent e8977b0 commit d67f7f9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions torchtitan/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class JobConfig:
"""

def __init__(self):
self.args_dict = None
# main parser
self.parser = argparse.ArgumentParser(description="torchtitan arg parser.")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit d67f7f9

Please sign in to comment.