Skip to content

[Fix][Relax] Drop integer-indexed axes in the Torch FX importer - #20991

Open
DiadkoShmek wants to merge 1 commit into
apache:mainfrom
DiadkoShmek:DiadkoShmek/fix-fx-getitem-integer-index
Open

DiadkoShmek wants to merge 1 commit into
apache:mainfrom
DiadkoShmek:DiadkoShmek/fix-fx-getitem-integer-index

Conversation

@DiadkoShmek

Copy link
Copy Markdown

Fixes #20899.

The FX importer treats each integer in a tensor subscript as a length-one slice and keeps its axis. A bare integer also takes an early return that skips indexing. This can either reject valid Torch broadcasts (for example, a[..., 0] + b for shapes (3, 2, 4) and (3, 2)) or silently return the wrong rank when the operands remain broadcastable.

Normalize negative integer positions against the axis extent and squeeze exactly the axes selected by integers. Compute the output positions of None relative to those removed axes. Slice objects continue to retain their axes.

On 23a6dbe710dfcd445a090af1c49c8d7e8a57fb10, six new LLVM CPU tests through torch.compile failed and one slice-only control passed. All seven pass with the patch and match Torch eager exactly. The full Dynamo and FX test modules went from 189 passed and 7 skipped to 196 passed and 7 skipped, including the seven added tests. Six exported-program indexing-related tests passed on both versions. A manual check also matched eager for x[..., -1] on two input shapes using one dynamically compiled graph.

AI assistance (Codex) was used for the patch, tests, and verification.

Treat integer subscripts as rank-reducing selections. Normalize negative positions and keep new axes in their PyTorch positions after the selections.

This branch has not been deployed

No deployments
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.

[Bug] Incorrect handling of select dimension in torch frontend

1 participant