Skip to content

Bug: randn_tensor MPS info-log suppression never triggers (compares torch.device to string) #14642

Description

@Ricardo-M-L

Describe the bug

In src/diffusers/utils/torch_utils.py, randn_tensor suppresses the CPU-generator info log on MPS with:

if device != "mps":
    logger.info(...)

device is a torch.device object, so the comparison to the string "mps" is always True - the log fires even on MPS targets where it's meant to be suppressed. This has been silently broken since the check was introduced in #1902.

Reproduction

import torch
from diffusers.utils import torch_utils

gen = torch.Generator(device="cpu")
torch_utils.randn_tensor((1, 2), generator=gen, device=torch.device("mps"), dtype=torch.float32)
# -> info log "The passed generator was created on 'cpu'..." still prints

Expected behavior

Compare device.type != "mps" instead. Fix + regression test in PR #14501 (rebase of approved-but-unmerged #13508).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions