test-tube
test-tube copied to clipboard
Possibility to support python-fire?
I usually use python fire (https://github.com/google/python-fire), it creates the parser arguments by default looking at the function to be called. Is there any possibility of integrating this into the existing framework?
what do you mean usually? looks cool, can you share an example?
Here is an example
"""
main.py
"""
import fire
from utils import get_data
def main(exp_name, batch_size, num_workers):
print(f'Starting Experiment {exp_name}')
data = get_data(batch_size, num_workers)
if __name__ == '__main__':
fire.Fire(main)
Now, in my terminal, I can directly do this
python main.py "exp1" 32 8
This would directly pass the arguments to the main function without explicitly importing argparse
and is more succint. To be specific, it is like a wrapper around the argparse
and calls it internally.
In general, fire supports many other stuff like here: https://github.com/google/python-fire/blob/master/docs/guide.md. Though not all of it would be relevant to test-tube.
Interesting.... could you propose an example using test tube (ie: a dream use case)? I see this as an addition and not necessarily a replacement of argparse because most academic researchers use argparse right now so it's easy to integrate with their code (ie... not many changes)
Yeah, I meant this to be an addition. Here is a small example I am cooking up from your example. https://github.com/williamFalcon/test-tube/blob/master/examples/pytorch_hpc_example.py
The given code:
# set up our argparser and make the y_val tunable
parser = HyperOptArgumentParser(strategy='random_search')
parser.add_argument('--test_tube_exp_name', default='my_test')
parser.add_argument('--log_path', default='/some/path/to/log')
parser.opt_list('--y_val', default=12, options=[1, 2, 3, 4, 5, 6], tunable=True)
parser.opt_list('--x_val', default=12, options=[20, 12, 30, 45], tunable=True)
hyperparams = parser.parse_args()
can be rewritten as:
"""eg.py"""
def main(*args, **kwargs):
# cfg.json has a dictionary like {"strategy": "random_search"} and other default values
cfg = json.load(open('./cfg.json'))
cfg.update(kwargs)
# Use cfg to update hyperopt
pass
if __name__ = '__main__':
fire.Fire(main)
Now from my terminal I can simply call, python eg.py --y_val=5
and done. Makes the code way simpler I think.
There are other cool arguments parser libraries like http://docopt.org/ as well. We could generalize this issue by supporting json format parsed arguments, instead of relying on a specific format.