Yes, it should be possible via torch.jit.script. Tracing via torch.jit.trace uses the passed input to trace all operations and might fail, if you are using different inputs in the deployment use case.