Skip to content

tutorials/ml: fix TMVA_SOFIE_ONNX tensor name for current PyTorch#21546

Open
Neeraj-x0 wants to merge 1 commit intoroot-project:masterfrom
Neeraj-x0:fix/sofie-onnx-tutorial-tensor-name
Open

tutorials/ml: fix TMVA_SOFIE_ONNX tensor name for current PyTorch#21546
Neeraj-x0 wants to merge 1 commit intoroot-project:masterfrom
Neeraj-x0:fix/sofie-onnx-tutorial-tensor-name

Conversation

@Neeraj-x0
Copy link

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:

  • Replaced hardcoded tensor name 16weight with 0weight in TMVA_SOFIE_ONNX.C
  • Updated all print statements referencing the tensor name for consistency
  • Regenerated tmva/sofie/test/input_models/Linear_16.onnx using current PyTorch

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

This PR fixes #21545

Copilot AI review requested due to automatic review settings March 10, 2026 07:22
@Neeraj-x0 Neeraj-x0 requested review from couet and lmoneta as code owners March 10, 2026 07:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.weight0weight after SOFIE name cleaning), fixing a runtime crash when querying tensor shapes/types.

Changes:

  • Updated the tutorial macro to query 0weight instead of the obsolete 16weight.
  • Updated tutorial print statements to match the new tensor name.
  • Regenerated tmva/sofie/test/input_models/Linear_16.onnx using 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.

Comment on lines +37 to +45
//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");
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Author

@Neeraj-x0 Neeraj-x0 Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')
@Neeraj-x0 Neeraj-x0 force-pushed the fix/sofie-onnx-tutorial-tensor-name branch from 36bd605 to 62f73f0 Compare March 10, 2026 07:28
@siliataider siliataider requested a review from sanjibansg March 10, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TMVA_SOFIE_ONNX.C tutorial fails with modern PyTorch due to tensor name mismatch

4 participants