Convert model to torch script via scripting, got ---TypeError: cannot create weak reference to 'builtin_function_or_method' object

Solved. It is because I mistakenly delete the forward function. If you encountered the same problem,check your forward function and all the functions the forward function calls, make sure to add torch.jit.script decorator to the functions and torch.jit.script_method decorator to your module’s methods.