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.