The result generated by trace immediately is different with the result generated by trace loaded

Marxlp: <p>pytorch version: 2.0.1+cu117</p>
<p>after I downgrade the version to 1.8.2 the problem solved</p>
<p>I traced a model and do the inference by three ways:</p>
<pre data-code-wrap="python"><code class="lang-python"># trace model
traced_model = torch.jit.trace(traceable_model, exaample_input, check_tolerance=1e-9)
</code></pre>
<pre data-code-wrap="python"><code class="lang-python"># pytorch model
expected_outputs = traceable_model(*example_input)
# run inference immediately
traced_outputs = traced_model(*example_input)
</code></pre>
<pre data-code-wrap="python"><code class="lang-python"># dump model
dumped_model_path = args.output_path
logger.info("Dump TorchScript model to: {}.".format(dumped_model_path))
traced_model.save(dumped_model_path)
logger.info("loading from {}".format(dumped_model_ppath)
# load and inference
pt_model = torch.jit.load(dumped_model_path)
pt_outputs = pt_model(*example_input)
</code></pre>
<p>comparing the result</p>
<pre data-code-wrap="python"><code class="lang-python">def compare(expected_outputs, traced_outputs):
    names = ('anchors', ' scores', ' attr_scores', 'box_delta')
	error = 0
	for name, item1, item2 in zip(names, expected_outputss, traced_outputs)
		print('name:', name)
		for o1, o2 in zip(item1, item2):
			if isinstance(o1, torch.Size):
				assert torch.eq(torch.as_tensor(o1), o2).all(), "{} oHiffers {}.".format(o1, o2)
				continue
			elif isinstance(o1, torch.Tensor):
				if o1.dtype == torch.bool:
					diff = o1 ^ o2
				else:
					diff = torch.abs(o1 - o2)
				logger.info(f'max diff: {torch.max(diff)}, {torch.max(diff/torch.min(torch.abs(o1), torch.abs(o2)))}}')
				error += diff.sum()
			else:
				logger.warning("unrecognized data type {} for data {}. Skiip compute tracing error on this data.".format
				type(o1), o1
		if error &gt; 0:
			logger.warning("Errors on example input is {}.".format(error)
</code></pre>
<pre><code class="lang-auto">compare_diff(expected_outputs, traced_outputs)   # different
logger.info('comparing pt outputs and excepted outputs')
compare_diff(pt_outputs, excepted_outputs)    # no diff
</code></pre>
<p>As shown below, <code>excepted_outputs</code> is same as <code>pt_outputs</code>, but not equal to <code>traced_outputs</code>.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/9/8929df464f2b1610590cc98f7bcc2c32b6c21fdf.png" data-download-href="https://discuss.pytorch.org/uploads/default/8929df464f2b1610590cc98f7bcc2c32b6c21fdf" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/9/8929df464f2b1610590cc98f7bcc2c32b6c21fdf_2_488x499.png" alt="image" data-base62-sha1="jzp7HfxlmMpPAN2QfFOeOzrBkbZ" width="488" height="499" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/9/8929df464f2b1610590cc98f7bcc2c32b6c21fdf_2_488x499.png, https://discuss.pytorch.org/uploads/default/optimized/3X/8/9/8929df464f2b1610590cc98f7bcc2c32b6c21fdf_2_732x748.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/8/9/8929df464f2b1610590cc98f7bcc2c32b6c21fdf.png 2x" data-dominant-color="272B29"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">881×901 149 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>