diff options
author | Marcin Chrzanowski <m@m-chrzan.xyz> | 2021-05-27 19:59:03 +0200 |
---|---|---|
committer | Marcin Chrzanowski <m@m-chrzan.xyz> | 2021-05-27 19:59:03 +0200 |
commit | 03c817412c638c905dea6c1a1967691f3ced57b8 (patch) | |
tree | fb60d8b7a1a94341aab1548f95a37a8d9f3c9112 /util | |
parent | 3e4924d0dcec2eba4f3019b55178cd1c3b70a474 (diff) |
Add configurable run script
Diffstat (limited to 'util')
-rw-r--r-- | util/parse_config.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/util/parse_config.py b/util/parse_config.py new file mode 100644 index 0000000..00a4fd4 --- /dev/null +++ b/util/parse_config.py @@ -0,0 +1,31 @@ +import yaml + +def parse_file(file): + with open(file) as file: + return parse_yaml(yaml.safe_load(file)) + +def parse_model_config(yaml): + required_verbatim_params = ['hidden_dim', 'd_ff', 'n_layers', 'num_heads'] + config = { key: yaml[key] for key in required_verbatim_params } + + config['input_dim'] = yaml['n_tokens'] + config['output_dim'] = yaml['max_count'] + 1 + + if 'use_positional' in yaml: + config['use_positional'] = yaml['use_positional'] + if 'use_feedforward' in yaml: + config['use_feedforward'] = yaml['use_feedforward'] + + return config + +def parse_train_config(yaml): + required_verbatim_params = [ + 'lr', 'num_steps', 'batch_size', 'n_tokens', 'seqlen', 'max_count' + ] + config = { key: yaml[key] for key in required_verbatim_params } + return config + +def parse_yaml(yaml): + model_config = parse_model_config(yaml) + train_config = parse_train_config(yaml) + return model_config, train_config |