tutorials/ml: fix TMVA_SOFIE_ONNX tensor name for current PyTorch#21546
tutorials/ml: fix TMVA_SOFIE_ONNX tensor name for current PyTorch#21546Neeraj-x0 wants to merge 1 commit intoroot-project:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the TMVA SOFIE ONNX tutorial and its companion test artifact to align with tensor naming produced by current PyTorch/ONNX exports (e.g., 0.weight → 0weight after SOFIE name cleaning), fixing a runtime crash when querying tensor shapes/types.
Changes:
- Updated the tutorial macro to query
0weightinstead of the obsolete16weight. - Updated tutorial print statements to match the new tensor name.
- Regenerated
tmva/sofie/test/input_models/Linear_16.onnxusing a current PyTorch export.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tutorials/machine_learning/TMVA_SOFIE_ONNX.C | Updates the hardcoded tensor queried by the tutorial to match current PyTorch naming. |
| tmva/sofie/test/input_models/Linear_16.onnx | Updates the test ONNX model artifact to match current PyTorch export output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| //Checking if tensor already exist in model | ||
| std::cout<<"\n\nTensor \"16weight\" already exist: "<<std::boolalpha<<model.CheckIfTensorAlreadyExist("16weight")<<"\n\n"; | ||
| std::vector<size_t> tensorShape = model.GetTensorShape("16weight"); | ||
| std::cout<<"Shape of tensor \"16weight\": "; | ||
| std::cout<<"\n\nTensor \"0weight\" already exist: "<<std::boolalpha<<model.CheckIfTensorAlreadyExist("0weight")<<"\n\n"; | ||
| std::vector<size_t> tensorShape = model.GetTensorShape("0weight"); | ||
| std::cout<<"Shape of tensor \"0weight\": "; | ||
| for(auto& it:tensorShape){ | ||
| std::cout<<it<<","; | ||
| } | ||
| std::cout<<"\n\nData type of tensor \"16weight\": "; | ||
| SOFIE::ETensorType tensorType = model.GetTensorType("16weight"); | ||
| std::cout<<"\n\nData type of tensor \"0weight\": "; | ||
| SOFIE::ETensorType tensorType = model.GetTensorType("0weight"); |
There was a problem hiding this comment.
CheckIfTensorAlreadyExist("0weight") is only printed, but GetTensorShape("0weight")/GetTensorType("0weight") are called unconditionally. If a user passes a different ONNX file (via inputFile) that doesn’t contain this tensor, the tutorial will still throw a runtime_error and abort. Consider branching on the boolean result and either skipping the shape/type queries or emitting a clearer message / early return when the tensor is absent.
There was a problem hiding this comment.
Fixed in the latest commit ,the shape/type queries are now guarded
by the boolean result of CheckIfTensorAlreadyExist(). If the tensor is absent
(e.g. when a custom ONNX file is passed), the tutorial now prints a clear message
and skips the queries instead of throwing a runtime_error.
The tutorial hardcoded tensor name '16weight' which was generated by
an older PyTorch version. Current PyTorch Sequential modules produce
tensors named '0weight', '2weight', '4weight' (dot stripped by SOFIE).
Updated TMVA_SOFIE_ONNX.C to use '0weight' and regenerated Linear_16.onnx
using current PyTorch to keep tutorial and test model in sync.
Fixes: tutorial crash with runtime_error on GetTensorShape('16weight')
36bd605 to
62f73f0
Compare
The tutorial hardcoded tensor name '16weight' which was generated by an older
PyTorch version. Current PyTorch Sequential modules produce tensors named
'0weight', '2weight', '4weight' (dot stripped by SOFIE).
Updated TMVA_SOFIE_ONNX.C to use '0weight' and regenerated Linear_16.onnx
using current PyTorch to keep tutorial and test model in sync.
Fixes: tutorial crash with runtime_error on GetTensorShape('16weight')
This Pull request:
Changes or fixes:
16weightwith0weightin TMVA_SOFIE_ONNX.CChecklist:
This PR fixes #21545