Conversation
The pipeline passes a 0-dim sigma (`t/1000`), so the `len(sigma.shape) == 0`
branch rebuilds it with `torch.tensor([sigma.item()])`, which has no `device`
argument and therefore always lands on CPU.
A few lines later:
noisy_image = self.latent_image * (1.0 - sigma) + self.noise * sigma
mixes that CPU tensor with device-resident latents and raises:
RuntimeError: Expected all tensors to be on the same device,
but found at least two devices, mps:0 and cpu!
Reproduced on Apple Silicon (MPS) with qwen_image_20B inpainting; the same
mismatch applies to any non-CPU device.
Passing `device=sigma.device` changes placement only. `torch.tensor([x.item()])`
infers float32 regardless of the input dtype, so the numerics are unchanged --
unlike `sigma.unsqueeze(0)`, which would preserve bf16 and silently alter the
precision of the sigma schedule.
Verified end-to-end on MPS (qwen_image_20B, 512x512, video_prompt_type "VA",
model_mode 2): completes cleanly, and the mask is correctly respected -- mean
absolute difference from the source image is 51.8 inside the mask vs 0.96
outside.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Author
|
Reopening, closed by mistake. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Inpainting crashes on any non-CPU device that isn't the default, e.g. Apple Silicon:
Traceback:
Cause
The pipeline passes
t/1000, which is a 0-dim tensor, so this branch fires:torch.tensor(...)withoutdevice=allocates on CPU regardless of wheresigmacame from. Line 142 then multiplies device-resident latents by that CPUtensor.
Note this is a shape-
(1,)tensor, not a 0-dim one, so it does not qualify forPyTorch's CPU-scalar promotion and the op genuinely fails.
Fix
I used
device=rather thansigma.unsqueeze(0)deliberately:torch.tensor([x.item()])infers float32 regardless of the input dtype, soadding
device=changes placement only and leaves numerics identical.unsqueeze(0)would preserve bf16 and silently change the precision of thesigma schedule downstream.
shared/inpainting/was checked for the same pattern — this is the onlydevice-less tensor construction.
utils.py:270,280,293already passdevice=y0.device.Verification
Apple M4 Pro / MPS, torch 2.13.0,
qwen_image_20B, 512x512,video_prompt_type: "VA",model_mode: 2, 3 steps.Before: crashes at the first LanPaint call.
After: completes in ~1m07s, exit 0, no errors in the log.
To confirm the mask is genuinely respected rather than the run merely not
crashing, mean absolute pixel difference from the source image:
The masked region is regenerated; the rest is preserved (0.96 is JPEG noise).
Not exercised: the
IS_FLUX/IS_FLOWbranches and Flux/Wan inpainting. Thechanged line runs before that branch, so they are covered by the same fix, but I
only ran the Qwen path.
🤖 Generated with Claude Code