During training process, my console is swamped by Warning: Constant folding - Only steps=1 can be constant folded for opset >= 10 onnx::Slice op. Constant folding not applied. I tried a few variants of
warnings.filterwarnings(
"once",
message="Constant folding not applied",
)
in both util.py and train.py, to no effect.
Digging through the code, I have traced a lot of those warnigs to torch._C._jit_pass_onnx_graph_shape_type_inference(graph, params_dict, _export_onnx_opset_version) on line 252 of C:\Users\Dzenan\miniconda3\envs\deep_learning\Lib\site-packages\torch\onnx\utils.py. My PyTorch Version is 1.11.0. I assume that torch._C calls C or C++ code (Python debugger does not step into it). Maybe origination in C/C++ code makes those warnings funky, so they don’t get the same treatment as other Python warnings?
While the issue seems to be raised by PyTorch, I believe the ONNX code owners might not be looking into the discussion board a lot.
I don’t know why the warning is still raised even after you’ve used do_constant_folding=False, so feel free to comment on the open GitHub issue so that the code owners could see it.
A brute-force approach would be to rip out the warning from here and rebuild a custom PyTorch version in case you cannot filter it out.