KEMBAR78
export: add explicit decomposition for aten.expand_copy and unit test by albertw7711 · Pull Request #161688 · pytorch/pytorch · GitHub
Skip to content

Conversation

@albertw7711
Copy link
Contributor

Fixes #161080
torch.export.export fails with TypeError: expand() got an unexpected keyword argument 'implicit' when calling torch.expand_copy(..., implicit=True). This happened because expand_copy = _make_copy_from_view(aten.expand) register aten. expand as the decomposition path for aten.expand_copy, which doesn’t accept the implicit argument.

I have added an explicit a decomposition for aten.expand_copy in torch/_decomp/decompositions.py to ignore the implicit argument, and a simple unit test to demonstrate the bug being fixed.

@pytorch-bot
Copy link

pytorch-bot bot commented Aug 28, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/161688

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 6 Pending

As of commit 47021d7 with merge base d636c18 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 28, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@albertw7711
Copy link
Contributor Author

albertw7711 commented Aug 28, 2025

hi sorry I am still not very familiar with the pr process. I will fix the other issues when I wake up tomorrow. Thanks. I am not sure if the changes in 30d971e are needed but I will just leave them there for now.

@albertw7711
Copy link
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Aug 28, 2025

@register_decomposition(aten.expand_copy)
@out_wrapper()
def expand_copy(self, size, *, implicit: bool = False):
Copy link
Contributor

Choose a reason for hiding this comment

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

expand also takes in implicit as a flag, so I think we should just add the flag to its decomposition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi I have spent several hours on this trying to trace down the root cause and attempting various fixes. However, it seems that the issue lies within python function binding. The schema is working fine as modifying it does not change anything and it was propagated properly throughout all the modules I have traced through. It was very interesting as it seems that the schema is effective in identifying unrecognized argument, but if the implicit keyword is used, the process would go further and break because it just randomly stops following the schema.

The latest commit I have submitted just straight up dereference the implicit argument since it's not used by aten anyway.

I hope this helps, sorry for not being able to do more.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think all you need to do is just add the implicit flag here and set a default value for it

@register_decomposition(aten.expand)
def expand(a: Tensor, *shape) -> Tensor:
from torch.fx.experimental.symbolic_shapes import guard_or_false, sym_or

Both expand and expand_copy accept implicit as an input, and since expand makes a copy view from expand_copy, we can fix it in the same place.

If there is another issue, you can paste the output here or start a new issue in the community :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you so much @can-gaa-hou! This fixes the problem completely and I will make sure to learn from this experience.
@angelayi @can-gaa-hou I think the pr can be merged now to close #161688.

@albertw7711 albertw7711 changed the title decomp: add decomposition for aten.expand_copy and unit test export: add explicit decomposition for aten.expand_copy and unit test Aug 29, 2025
Copy link
Contributor

@angelayi angelayi left a comment

Choose a reason for hiding this comment

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

thanks!

@albertw7711 albertw7711 requested a review from angelayi August 30, 2025 01:53
@albertw7711
Copy link
Contributor Author

@angelayi hi I really hope my first pr here can be accepted I am planning on making future contributions as well so if the code is still not up to standard please let me know much appreciated! Please approve the review otherwise.

@albertw7711
Copy link
Contributor Author

also it should be able pass all tests now and ready to merge :)

@angelayi
Copy link
Contributor

angelayi commented Sep 4, 2025

thanks!

@angelayi
Copy link
Contributor

angelayi commented Sep 4, 2025

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 4, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@albertw7711
Copy link
Contributor Author

Thanks everyone for being supportive! I will start working on a new issue.

markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
…pytorch#161688)

Fixes pytorch#161080
torch.export.export fails with TypeError: expand() got an unexpected keyword argument 'implicit' when calling torch.expand_copy(..., implicit=True). This happened because expand_copy = _make_copy_from_view(aten.expand) register aten. expand as the decomposition path for aten.expand_copy, which doesn’t accept the implicit argument.

I have added an explicit a decomposition for aten.expand_copy in torch/_decomp/decompositions.py to ignore the implicit argument, and a simple unit test to demonstrate the bug being fixed.
Pull Request resolved: pytorch#161688
Approved by: https://github.com/angelayi, https://github.com/can-gaa-hou
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
…pytorch#161688)

Fixes pytorch#161080
torch.export.export fails with TypeError: expand() got an unexpected keyword argument 'implicit' when calling torch.expand_copy(..., implicit=True). This happened because expand_copy = _make_copy_from_view(aten.expand) register aten. expand as the decomposition path for aten.expand_copy, which doesn’t accept the implicit argument.

I have added an explicit a decomposition for aten.expand_copy in torch/_decomp/decompositions.py to ignore the implicit argument, and a simple unit test to demonstrate the bug being fixed.
Pull Request resolved: pytorch#161688
Approved by: https://github.com/angelayi, https://github.com/can-gaa-hou
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
…pytorch#161688)

Fixes pytorch#161080
torch.export.export fails with TypeError: expand() got an unexpected keyword argument 'implicit' when calling torch.expand_copy(..., implicit=True). This happened because expand_copy = _make_copy_from_view(aten.expand) register aten. expand as the decomposition path for aten.expand_copy, which doesn’t accept the implicit argument.

I have added an explicit a decomposition for aten.expand_copy in torch/_decomp/decompositions.py to ignore the implicit argument, and a simple unit test to demonstrate the bug being fixed.
Pull Request resolved: pytorch#161688
Approved by: https://github.com/angelayi, https://github.com/can-gaa-hou
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
…pytorch#161688)

Fixes pytorch#161080
torch.export.export fails with TypeError: expand() got an unexpected keyword argument 'implicit' when calling torch.expand_copy(..., implicit=True). This happened because expand_copy = _make_copy_from_view(aten.expand) register aten. expand as the decomposition path for aten.expand_copy, which doesn’t accept the implicit argument.

I have added an explicit a decomposition for aten.expand_copy in torch/_decomp/decompositions.py to ignore the implicit argument, and a simple unit test to demonstrate the bug being fixed.
Pull Request resolved: pytorch#161688
Approved by: https://github.com/angelayi, https://github.com/can-gaa-hou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torch.export fails for expand_copy when implicit=True

5 participants