Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] ltorch.to to return a copy, when copy=True #1775

Merged
merged 2 commits into from
Feb 19, 2025

Conversation

khushi-411
Copy link
Contributor

Before submitting
  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

What does this PR do?

Fixes #1291

Earlier

>>> import torch
>>> import thunder
>>> from thunder.torch import to
>>> a = torch.tensor([1.0, 2.0, 3.0])
>>> def foo(a):
...     return a.to(copy=True)
... 
>>> jfoo = thunder.jit(foo)
>>> result = jfoo(a)
>>> assert result is not a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
>>> 

Now

>>> import torch
>>> import thunder
>>> from thunder.torch import to
>>> a = torch.tensor([1.0, 2.0, 3.0])
>>> def foo(a):
...     return a.to(copy=True)
... 
>>> jfoo = thunder.jit(foo)
>>> result = jfoo(a)
>>> assert result is not a
>>> 

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

🎉 🎉

Copy link
Collaborator

@crcrpar crcrpar left a comment

Choose a reason for hiding this comment

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

The diff looks good to me.
Could you update the title so that it explains which of what op is fixed?

@khushi-411 khushi-411 changed the title [fix] copy when self=True [fix] ltorch.to to return a copy, when copy=True Feb 19, 2025
@khushi-411
Copy link
Contributor Author

Hi @crcrpar! Thank you for reviewing the PR!

Could you update the title so that it explains which of what op is fixed?

Sure, I've updated the title.

Copy link
Collaborator

@t-vi t-vi left a comment

Choose a reason for hiding this comment

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

@t-vi t-vi enabled auto-merge (squash) February 19, 2025 12:08
@khushi-411
Copy link
Contributor Author

Thanks so much for reviewing the PR, @crcrpar @riccardofelluga @t-vi!

@t-vi t-vi merged commit 92a6adb into Lightning-AI:main Feb 19, 2025
49 checks passed
@khushi-411 khushi-411 deleted the fix_copy branch February 19, 2025 13:21
riccardofelluga added a commit that referenced this pull request Feb 21, 2025
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.

ltorch.to could return self even if copy=True
4 participants