diffusers
de5fcf6f - fix(randn_tensor): compare device.type, not torch.device, when suppressing MPS info log (#13508)

Commit
13 days ago
fix(randn_tensor): compare device.type, not torch.device, when suppressing MPS info log (#13508) * fix(randn_tensor): compare device.type, not torch.device to str, when suppressing MPS info log When a CPU generator is passed with an MPS target, randn_tensor intentionally skips the 'generator was on cpu, tensor will be moved to <device>' info log — MPS doesn't support device-side generators, so the suggestion to create one on MPS would be misleading. The guard was written as `if device != "mps"`, but a few lines earlier `device` is coerced to a `torch.device` object, and `torch.device("mps") == "mps"` is False (torch.device's __eq__ with a string returns NotImplemented, falling back to identity — they're different types). Result: the guard is effectively always True, so MPS users get the spurious log whenever they pass a CPU generator — the opposite of the documented intent. Fix: compare `device.type` (a str) against "mps". Added a regression test in tests/others/test_utils.py that exercises both the MPS and non-MPS paths via `assertLogs` on the diffusers logger. * refactor: use CaptureLogger instead of assertLogs in randn_tensor test Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> Co-authored-by: YiYi Xu <yixu310@gmail.com>
Author
Parents
Loading