@Rizhao_Cai I don’t remember the exact code/bug in my code since its been a few months old. But basically somewhere in the code I was detaching the tensor from the graph that PyTorch uses to compute auto-grads.
Example:
tensor_I_want_in_my_graph = torch.FloatTensor([1])
modified_tensor = tensor_I_want_in_my_graph.detach()
...

As a result of .detach() pyTorch removes that tensor from backprop calculation and the pyTorch to ONNX export treats such a tensor as a constant tensor and just remembers the values instead of remembering the mathematical operation.
Documentation of detach() method 2
The .data operation is a bit different. Since each tensor is an object of class Tensor(), it has a property .data which contains the values of the tensor. I am not sure about the exporting behavior of .data in pyTorch + ONNX. You can do a small experiment to test it out.