Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PyTorch Example #2

Open
stocyr opened this issue Apr 22, 2020 · 1 comment
Open

Update PyTorch Example #2

stocyr opened this issue Apr 22, 2020 · 1 comment

Comments

@stocyr
Copy link

stocyr commented Apr 22, 2020

The PyTorch example could use some improvement:

  • It doesn't reflect the latest API anymore: the experiment.log_metric1 signature has swapped xandy`.
  • When using multiprocessing for data loading (that's common practice with PyTorch's torch.utils.data.DataLoader), its problematic to execute expressions outside an if __name__ == '__main__' clause (at least on Windows): it starts multiple experiments...
  • I usually want to have my training script also be possible to launch from console. What do you think of the proposed snipped for merging both sets of arguments/options?
from collections import ChainMapdef main():
    # Training settings
    parser = argparse.ArgumentParser(description='PyTorch MNIST Example',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--batch-size', type=int, default=64, metavar='N',
                        help='input batch size for training')
    # More arguments...
    args = parser.parse_args()
    experiment = deepkit.experiment()
    # Merge CLI arguments (low priority) with experiment hyperparameters (high priority)
    args = argparse.Namespace(**ChainMap(experiment.full_config(), vars(args)))
    # Update merged arguments back to experiment server
    for key, val in vars(args).items():
        experiment.set_config(key, val)
    # Capsule the experiment handle into `args` as well, so distribution to train() and test() methods is easy
    args.experiment = experiment
@marcj
Copy link
Member

marcj commented May 15, 2020

Looks good, thanks! If you would like to provide a PR I'd love to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants