how to save in pytorch an ONNX model with training (autograd) operations?
In pytorch, is it possible to save an ONNX model to file including the backward operations?
If not, is there any other way in pytorch to save the forward and backward graph as text (json, pbtxt ...)?
Any help will be appreciated.

it's possible if you wrap the model with ORTModule -
https://github.com/microsoft/onnxruntime-training-examples
There's flag to enable onnx model saving, for example:
model._save_onnx = True
model._save_onnx_prefix = 'MNIST'
However, the onnx graph from fw will be further optimized before generating bw graph. Thus it's specific to ORT, but the training results should be mathematically the same. If you are looking for just fw+bw graph, the output onnx is still a good reference. The onnx could be opened using Netron util - https://github.com/lutzroeder/Netron
