Fix for PyTorch 2.x: Remove _optimize_trace
call & fix torch_node attribute access
#104
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Recent versions of PyTorch (2.x) have removed the internal function
torch.onnx._optimize_trace
, causing anAttributeError
in hiddenlayer. Additionally, subscript usage liketorch_node[k]
is no longer valid ontorch._C.Node
, resulting in a “TypeError: 'torch._C.Node' object is not subscriptable”.This PR removes the
_optimize_trace
call inpytorch_builder.py
and replacestorch_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:
torch.onnx._optimize_trace(...)
.import_graph()
(e.g.f
,i
,fs
,is
,s
).Testing:
AttributeError
orTypeError
.Notes: