Hi MagnificentPig49 ,
Can you share a little bit more of your initial code? Where exactly do you call http://Task.in
thanks SuccessfulKoala55 , sorry that I can’t share the whole code but here is my main part
` import faulthandler
import logging
import torch
from argparse import ArgumentParser
from pytorch_lightning.callbacks import ModelCheckpoint
...
import os
from trains import Task
model_snapshots_path = 'mnt/trains'
if not os.path.exists(model_snapshots_path):
os.makedirs(model_snapshots_path)
task = Task.init(project_name='xl_trainer',
task_name='extending automagical Trains xl trianer',
output_uri=model_snapshots_path)
logger = task.get_logger()
def main(args):
` ` ('Got args: %s', args)
model = XLModelFactory().create_or_load(args)
...
if name == 'main':
parent_parser = ArgumentParser(add_help=False)
main(ResnetCIFAR10Model.add_model_specific_args(parent_parser).parse_args(nested=True)) `
Hi MagnificentPig49 I suspect it's the ResnetCIFAR10Model wrapper, is it your module ?
I simplified the code, just so I could test it, this one seems to work, feel free to add the missing argparser parts :)
` from argparse import ArgumentParser
from trains import Task
model_snapshots_path = 'mnt/trains'
task = Task.init(project_name='examples', task_name='test argparser', output_uri=model_snapshots_path)
logger = task.get_logger()
def main(args):
print('Got args: %s' % args)
if name == 'main':
parent_parser = ArgumentParser(add_help=False)
parent_parser.add_argument('--argparser_int_value', help='integer value', type=int, default=1)
main(parent_parser.parse_args()) `
AgitatedDove14 thanks but I’m not using argparse
, I’m using jsonargparse
you can see the simplified snippet herefrom jsonargparse import ArgumentParser from trains import Task model_snapshots_path = 'mnt/trains' task = Task.init(project_name='examples', task_name='test argparser', output_uri=model_snapshots_path) logger = task.get_logger() def main(args): print('Got args: %s' % args) if __name__ == '__main__': parent_parser = ArgumentParser(add_help=False) parent_parser.add_argument('--num_workers', help='integer value', type=int, default=1) parent_parser.add_argument('--gpus', help='integer value', type=int, default=0) parent_parser.add_argument('--max_epochs', help='integer value', type=int, default=1) parent_parser.add_argument('--visdom', action='store_true') main(parent_parser.parse_args())
MagnificentPig49 I was not aware of jsonargparse
from what I understand it's a nicer way to parse json configuration files, with argparser alike interface. Did I get that correctly?
Regrading the missing argparser, you are correct, the auto-magic is not working since jsonargparse
is calling an internal ArgParser function and not the external one (hence we miss it).
The quickest fix is adding the following line before you call parse_args()
:task.connect(parent_parser)
MagnificentPig49 is jsonargparse
popular, should we fix the auto-magic ?
Thanks AgitatedDove14 yes task.connect
worked. about jsonargparse
not sure how popular it is but in our case regular argparse
didn’t work and we find out jsonargparse
is working perfect. I guess will be beneficial to support that as well.
MagnificentPig49 I'll look into it, if it's very simple, it should not be a problem.