Will torch.jit.script change the output of model?

I have converted a model to scipt module using torch.jit.scipt. However, I find there is some difference between the output of the original model and the output of the scripted model like:

model.eval()
scripted_model = torch.jit.script(model)

# there is some difference between output and scripted_output
output = model(inputs)
scripted_output = scripted_model(inputs)

Each element has an average difference of 1e-6

Is this phenomenon normal?

Yes, this small difference is expected due to the limited precision for float32.

2 Likes

Thans for your fast reply:)