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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
torch.jit.trace
fails claiming "forward method already defined"
#65611
Comments
Remove |
That does remove the error, but it's not unreasonable to use a module that was intended to be scripted in a module that is then traced -- this is a toy version of my error case. It's an unexpected behavior that marking a function as being available for jit scripting export would clash with tracing. |
I'm not familiar with the internals of PyTorch, but my guess would be that since a scripted function/module produces custom kernels that are the fusion of (mostly) many element-wise ops, it's impossible for jit.trace to trace the operations in such functions/modules. Which is in my opinion why you can't use something that was scripted inside something that you intend to trace. |
To be clear, the module had not yet been scripted -- that function was merely marked as an entrypoint if the module were to be scripted. So at this point it is a fully standard torch.nn.Module. My point is more that it's an undocumented incompatibility and, therefore, either an unintended side effect (bug) or at a minimum an undocumented failure mode (needs documentation). |
I agree this behaviour does need to be documented here https://pytorch.org/docs/stable/jit.html#torch.jit.export, it was a headache for me too when I first stumbled on that error. |
馃悰 Bug
torch.jit.trace
fails tracking a normal module with error "RuntimeError: method 'torch.dl_research.pytorch.projects.guidance.full_model.___torch_mangle_56.FullGuidanceModel.forward' already defined."To Reproduce
Steps to reproduce the behavior:
Simplified version of model which reproduces behavior:
Expected behavior
trace
should produce a scripted module without error.Environment
conda
,pip
, source): pipAdditional context
The text was updated successfully, but these errors were encountered: