Skip to content

fix: refactor: use CaptureLogger instead of assertLogs in randn_tensor test - #14501

Open
Ricardo-M-L wants to merge 3 commits into
huggingface:mainfrom
Ricardo-M-L:fix/randn-tensor-mps-device-comparison
Open

fix: refactor: use CaptureLogger instead of assertLogs in randn_tensor test#14501
Ricardo-M-L wants to merge 3 commits into
huggingface:mainfrom
Ricardo-M-L:fix/randn-tensor-mps-device-comparison

Conversation

@Ricardo-M-L

Copy link
Copy Markdown
Contributor

This PR addresses: refactor: use CaptureLogger instead of assertLogs in randn_tensor test

Ricardo-M-L and others added 3 commits April 27, 2026 22:51
… 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.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions github-actions Bot added size/S PR with diff < 50 LOC tests utils labels Aug 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @Ricardo-M-L, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S PR with diff < 50 LOC tests utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants