Skip to content

Update PyTorch Example #2

@stocyr

Description

@stocyr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions