Repository navigation
MOSS-Image: build the float64 timestep sinusoid on the CPU off CUDA - #14929
Conversation
MPS has no float64, so the first denoise step raised on Apple Silicon. CUDA and CPU keep computing it in place, bitwise as before.
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45dc8ee76b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| embedding = torch.cat((phase.cos(), phase.sin()), -1).float() | ||
| where = _float64_device(times.device) | ||
| freq = 10000 ** (-torch.arange(half, device = where, dtype = torch.float64) / half) | ||
| phase = times.to(where, torch.float64)[:, None] * freq |
There was a problem hiding this comment.
Move to CPU before casting the timestep to float64
On the MPS path this change is intended to repair, times is still an MPS tensor, so .to(where, torch.float64) requests a dtype-converting MPS-to-CPU copy. Supported PyTorch releases such as 2.13 reject this operation, while 2.14.0 can silently return uninitialized data, meaning the first denoise step still fails or computes corrupt timestep phases; the upstream MPS report specifically identifies x.cpu().to(torch.float64) as the safe ordering. Move the tensor to CPU while retaining float32, then cast it to float64 there.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7c17a6f: the timestep is moved to the CPU as float32 first and cast to float64 there (times.to(where).double()), the ordering pytorch/pytorch#197715 identifies as safe.
|
|
||
| def _float64_device(device): | ||
| """Where the float64 timestep sinusoid is built: MPS (and Arc XPUs) have no float64, so off CUDA it is the CPU.""" | ||
| return device if device.type in ("cuda", "cpu") else torch.device("cpu") |
There was a problem hiding this comment.
Retain XPU float64 when the selected device supports it
When Studio runs on a supported Intel Data Center GPU Max/PVC device, this blanket type check sends the sinusoid to the CPU even though that XPU has native FP64; the repository explicitly recognizes PVC as an XPU device, and Intel documents its FP64 execution capability. This adds an accelerator-to-host-to-accelerator synchronization to every transformer invocation and changes the backend used for the transcendental calculation unnecessarily. Query the selected XPU's FP64 capability (PyTorch exposes get_device_properties(...).has_fp64) and fall back only for devices such as Arc that actually lack it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7c17a6f: an XPU whose get_device_properties reports has_fp64 keeps the sinusoid on the device; only XPUs without float64 (Arc) and MPS use the CPU. Added parametrized cases for both XPU kinds.
…p it on XPUs with float64 [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
MOSSImageTransformer._time_modulation(#14552) builds the timestep sinusoid in float64 on the model's device:MPS has no float64 (https://docs.pytorch.org/docs/main/notes/mps.html, double precision types), and
PYTORCH_ENABLE_MPS_FALLBACKdoes not cover dtypes, so on Apple Silicon the first denoise step of a MOSS-Image safetensors render raises. Studio routes MOSS safetensors on MPS to this in-tree pipeline (sd.cpp on MPS is opt-in throughUNSLOTH_DIFFUSION_SD_CPP_MPS), so every Mac render of it fails. Intel Arc XPUs have no native float64 either.Change
The sinusoid is built on the model's device on CUDA, CPU and XPUs that report
has_fp64(Data Center GPU Max), exactly as before (bitwise the reference there), and on the CPU everywhere else (MPS, Arc XPUs), then moved over as float32. The timestep is moved to the CPU before the float64 cast, since a dtype-converting copy out of MPS into a float64 CPU tensor fails or, on torch 2.14, writes nothing (pytorch/pytorch#197715). The value fed to the time MLP is float32 in every case, as in the reference.Tests
studio/backend/tests/test_diffusion_moss_image.py:test_timestep_sinusoid_keeps_float64_off_mps: MPS and an XPU without float64 map to the CPU; CUDA, CPU and an XPU with float64 stay in place. Fails on main, passes here.test_diffusion_moss_image.py+test_diffusion_moss_fused.py: 49 passed, 1 skipped on this branch (CPU).Not covered: a real Apple Silicon render; this host has no Mac. The MPS failure is from the code path and the PyTorch MPS dtype documentation, not a run.