Restoring a saved model created by architecture search


I have a model whose architecture is found by a search method. Many such models are saved as checkpoints, but it’s challenging to restore and run them again because the exact architecture was programmatically determined. Each time I would want to load one of the checkpoints, it would require re-writing by hand the model architecture to exactly fit the particular one of the checkpoint file.

It would be wonderful if there were a way to do this:

module = SomeModule()
checkpoint = torch.load(checkpoint_file)

In principle this could be done by saving the architecture configuration and building a parser, though it would get hairy for custom objects and expressions, where markup isn’t as expressive as code.

Is there a canonical way of doing this?

It seems a reasonably popular request: