Skip to content

Compilation with LabelTensors fails in PyTorch 2.8 due to incorrect runtime_type inference #621

@GiovanniCanali

Description

@GiovanniCanali

Describe the bug
After upgrading to PyTorch 2.8.0, compilation involving LabelTensor fails due to incorrect inference of runtime_type in the torch compilation pipeline. This results in a RuntimeError during the backward pass.

To Reproduce
Upgrade to PyTorch 2.8.0 and run:

pytest tests/test_solver/test_pinn.py

You might also want to upgrade torchvision.

Expected behavior
All tests should pass successfully, and compilation should handle LabelTensor without metadata mismatches.

Output

RuntimeError: 
E               During the backward, we encountered a tensor subclass where we guessed its
E               metadata incorrectly.
E               
E               Expected metadata: None, expected type: <class 'torch.Tensor'>
E               
E               Runtime metadata: None, runtime type: <class 'pina.label_tensor.LabelTensor'>
E               
E               shape: torch.Size([1, 1])
E               To fix this, your tensor subclass must implement the dunder method __force_to_same_metadata__.

Additional context

  • Implementing __force_to_same_metadata__ in LabelTensor did not resolve the issue.
  • This might be related to changes introduced in the compilation pipeline in PyTorch 2.8.
  • The issue was not observed in PyTorch 2.7.x.

Metadata

Metadata

Labels

bugSomething isn't workinghigh priorityHigher priority

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions