Skip to content

Fix torch_dtype warning showing wrong value in from_single_file#13542

Open
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L:fix-single-file-torch-dtype-warning
Open

Fix torch_dtype warning showing wrong value in from_single_file#13542
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L:fix-single-file-torch-dtype-warning

Conversation

@Ricardo-M-L
Copy link
Copy Markdown
Contributor

What does this PR do?

In FromSingleFileMixin.from_single_file(), when an invalid torch_dtype is passed, the warning message always displays torch.float32 instead of the actual invalid value:

# Before (bug):
if torch_dtype is not None and not isinstance(torch_dtype, torch.dtype):
    torch_dtype = torch.float32  # reassigned BEFORE the warning
    logger.warning(
        f"Passed `torch_dtype` {torch_dtype} is not a `torch.dtype`. ..."
        # ^ always shows "torch.float32"
    )

This PR moves the reassignment after the warning so users can see what invalid value they actually passed:

# After (fix):
if torch_dtype is not None and not isinstance(torch_dtype, torch.dtype):
    logger.warning(
        f"Passed `torch_dtype` {torch_dtype} is not a `torch.dtype`. ..."
        # ^ now shows the actual invalid value (e.g. "float16", "bf16", etc.)
    )
    torch_dtype = torch.float32

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline?

Who can review?

@yiyixuxu @sayakpaul

The warning message intended to show the invalid torch_dtype value passed
by the user, but the variable was already reassigned to torch.float32
before the warning was logged. Move the reassignment after the warning
so the message correctly displays the original invalid value.
@github-actions github-actions Bot added single-file size/S PR with diff < 50 LOC labels Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

single-file size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant