Skip to content

fix: preserve multi-value shape tensor inputs - #4477

Open
zupengwang wants to merge 1 commit into
pytorch:mainfrom
zupengwang:fix/shape-tensor-list-3202
Open

fix: preserve multi-value shape tensor inputs#4477
zupengwang wants to merge 1 commit into
pytorch:mainfrom
zupengwang:fix/shape-tensor-list-3202

Conversation

@zupengwang

Copy link
Copy Markdown

Description

get_torch_tensor() assumed every shape tensor contained one value and always returned the first optimized shape value. Multi-value shape tensors were therefore converted to a scalar and could not be used for SymInt[] arguments such as aten.full's size.

This change preserves the existing scalar behavior for one-element shape tensors and returns the full optimized shape as a list for multi-element shape tensors. It also updates the related type annotations and adds a focused regression test.

No new dependencies are required.

Fixes #3202

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Validation

  • Targeted Dynamo runtime, converter, and partitioning tests: 44 passed on each of two RTX 3090 GPUs
  • Eager, torch.export, and TensorRT FP32/FP16 comparisons with static and dynamic shapes: maximum absolute error 0 on both GPUs
  • Changed-file pre-commit hooks, mypy, Ruff, Black, py_compile, and git diff --check

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation (not applicable: this does not change a user-facing API)
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified (left to maintainers and repository automation; no review was requested)

@meta-cla meta-cla Bot added the cla signed label Aug 11, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Aug 11, 2026
@zupengwang
zupengwang marked this pull request as ready for review August 11, 2026 14:01
@narendasan
narendasan requested a review from zewenli98 August 11, 2026 17:10

@zewenli98 zewenli98 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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

Labels

cla signed component: api [Python] Issues re: Python API component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug] shape tensor is a list instead of integer

2 participants