Torchscript back to eager

Hi everyone,

is there an easy way to convert a torchscripted model back to an eager model ?

Example:

eager_model = MyModel()
scripted_model = torch.jit.script(eager_model)
recovered_eager_model = some_function(scripted_model)  ### could not find anything about it in the docs

No, and it is strongly advised that you keep your source code around when doing stuff with JITed models.

That said, you can probably get a reduced model by walking the traced module, setting the children in init and using the .forward of each module.
This would get you something you can run and re-trace, but you loose how it was built (i.e. the inits).

Fun fact: In building a PyTorch-TVM bridge I built a PyTorch autograd function (but with TVM as backend instead of calling PyTorch) corresponding to the traced model.

Best regards

Thomas

1 Like