Last active
October 16, 2020 22:51
-
-
Save pseeth/32d6a63d8b16cae3efc0871b254a8b85 to your computer and use it in GitHub Desktop.
ArgBind demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argbind | |
from typing import List | |
@argbind.bind() | |
def train(epochs : int = 50): | |
"""Run training. | |
Parameters | |
---------- | |
epochs : int, optional | |
Number of epochs, by default 50 | |
""" | |
print('train', epochs) | |
@argbind.bind() | |
def evaluate(save_folder : str = 'folder'): | |
"""Run evaluation. | |
Parameters | |
---------- | |
save_folder : str, optional | |
Where to save, by default '.' | |
""" | |
print('evaluate', save_folder) | |
@argbind.bind() | |
def run(stages : List[str] = ['train', 'evaluate']): | |
"""Run stages. | |
Parameters | |
---------- | |
stages : List[str], optional | |
Which stages to run, by default 'train' | |
""" | |
for stage in stages: | |
stage_fn = globals()[stage] | |
stage_fn() # will do train | |
if __name__ == "__main__": | |
args = argbind.parse_args() | |
with argbind.scope(args): | |
run() |
❯ python demo.py --train.epochs=10 --evaluate.save_folder=different_folder --args.save demo.yml
train 10
evaluate different_folder
❯ python demo.py --args.load demo.yml
train 10
evaluate different_folder
Contents of demo.yml
:
evaluate.save_folder: different_folder
run.stages:
- train
- evaluate
train.epochs: 10
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a simple demonstration of a multi-stage program using ArgBind. There are two stages, train and evaluate, each of which can be accessed via the bound
run
function. Here's the help text:All the help text is generated from the docstring. The arguments are scoped like
func.arg
. Here's some sample runs: