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 Tensor.to() #90

Merged
merged 5 commits into from
Feb 20, 2024
Merged

Fix Tensor.to() #90

merged 5 commits into from
Feb 20, 2024

Conversation

dacorvo
Copy link
Collaborator

@dacorvo dacorvo commented Feb 19, 2024

There were several issues with Tensor.to() in quanto Tensor subclasses.

First, the PackedTensor and QbitsTensor dispatch for Tensor.to() were not implemented.

Second, when moving an entire nn.Module, pytorch does not only call Tensor.to() on the weight/bias, but also tries to do a shallow copy into the existing weight/bias.

Adding a proper dispatch at the function level to tag the QTensor class as incompatible with shallow copy solves the issue.

dacorvo and others added 3 commits February 19, 2024 14:30
By overriding a native tensor method, we prevent torch from blindly assigning
the content of a QTensor to another using Tensor.data.
Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks for fixing issues with respect to .to to make things easier with transformers integration !

@dacorvo dacorvo merged commit da0315f into main Feb 20, 2024
3 checks passed
@dacorvo dacorvo deleted the tensor_to branch February 20, 2024 07:10
Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Wow ! Thanks for the fix, I learn a lot through your PR =)

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.

3 participants