#36 - Fix to_device() incorrectly casting integer tensors when dtype is provided#37
Open
aniekannn wants to merge 1 commit intoNVlabs:mainfrom
Open
#36 - Fix to_device() incorrectly casting integer tensors when dtype is provided#37aniekannn wants to merge 1 commit intoNVlabs:mainfrom
aniekannn wants to merge 1 commit intoNVlabs:mainfrom
Conversation
…dtype is provided Only apply dtype conversion to floating-point tensors, preserving integer and boolean tensor dtypes. This prevents breaking Hugging Face model inputs (input_ids, attention_mask) when dtype is specified for mixed-precision inference. Fixes: Integer tensors now keep torch.long dtype when dtype parameter is provided, while float tensors are correctly cast to the target dtype. Signed-off-by: Aniekan Ekanem <117603178+aniekannn@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the to_device() helper function that was incorrectly casting integer tensors to the specified dtype, breaking Hugging Face model inputs like input_ids and attention_mask during mixed-precision inference.
Changes:
- Modified
to_device()to only apply dtype conversion to floating-point tensors - Added documentation clarifying that integer and boolean tensors preserve their original dtype
- Ensured backward compatibility when dtype parameter is None
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Only apply dtype conversion to floating-point tensors, preserving integer and boolean tensor dtypes. This prevents breaking Hugging Face model inputs (input_ids, attention_mask) when dtype is specified for mixed-precision inference.
Fixes: Integer tensors now keep torch.long dtype when dtype parameter is provided, while float tensors are correctly cast to the target dtype.