Skip to content

#36 - Fix to_device() incorrectly casting integer tensors when dtype is provided#37

Open
aniekannn wants to merge 1 commit intoNVlabs:mainfrom
aniekannn:fix/to_device-dtype-casting-issue-36
Open

#36 - Fix to_device() incorrectly casting integer tensors when dtype is provided#37
aniekannn wants to merge 1 commit intoNVlabs:mainfrom
aniekannn:fix/to_device-dtype-casting-issue-36

Conversation

@aniekannn
Copy link
Copy Markdown

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.

…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>
Copilot AI review requested due to automatic review settings January 24, 2026 03:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@aniekannn aniekannn marked this pull request as draft January 26, 2026 17:39
@aniekannn aniekannn marked this pull request as ready for review February 12, 2026 03:23
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.

2 participants