Skip to content

Conversation

@alz95
Copy link

@alz95 alz95 commented Jan 27, 2025

Summary:
Recent versions of PyTorch (2.x) have removed the internal function torch.onnx._optimize_trace, causing an AttributeError in hiddenlayer. Additionally, subscript usage like torch_node[k] is no longer valid on torch._C.Node, resulting in a “TypeError: 'torch._C.Node' object is not subscriptable”.

This PR removes the _optimize_trace call in pytorch_builder.py and replaces torch_node[k] with the relevant attribute accessor methods (torch_node.f(k), torch_node.i(k), etc.). These changes allow hiddenlayer to generate graphs without error on PyTorch 2.x and Python 3.12.

Changes in this PR:

  • Comment out torch.onnx._optimize_trace(...).
  • Introduce a small loop to handle each attribute type in import_graph() (e.g. f, i, fs, is, s).
  • Keep the rest of the logic (e.g. shape inference) intact.

Testing:

  • Verified locally on PyTorch 2.0.1 / Python 3.12. The modified code no longer throws AttributeError or TypeError.
  • Should maintain compatibility with older PyTorch versions as well, though not extensively tested.

Notes:

  • This is intended as a minimal fix. If there are other parts of hiddenlayer that rely on removed/changed PyTorch APIs, further patches may be needed.
  • Please let me know if you have any questions or suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant