Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Apple Silicon (MPS): float64 timestep sinusoid fails — working 3-line fix

Aperta Adatta ai principianti
#23 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@arxigen ci sta già lavorando.

Dal 26/10/2026.

  • #25 di @arxigen — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

La correzione è completamente scritta: sostituisci il calcolo delle sinusoidi in float64 in MOSSImageTransformer.forward all'interno di pipeline_moss_image.py con la versione calcolata su CPU mostrata nel diff, e applica la stessa modifica alle copie sotto transformer/ e scheduler/. Verifica prima su CPU che gli output siano invariati, poi esegui la generazione con il dispositivo MPS se disponibile. Fatto quando le tre copie sono corrette e la generazione produce immagini corrette sia su CPU che su MPS.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

On Apple Silicon (PyTorch MPS), generation fails on the first step:

TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't
support float64.

The cause is the float64 timestep sinusoid in MOSSImageTransformer.forward
(pipeline_moss_image.py). MPS has no float64.

Fix (verified)

Compute the sinusoid on the CPU in float64 (numerically identical to training) and move
the float32 result back to the device:

-        freq = 10000 ** (-torch.arange(half, device=times.device, dtype=torch.float64) / half)
-        phase = times.double()[:, None] * freq
-        embedding = torch.cat((phase.cos(), phase.sin()), -1).float()
+        freq = 10000 ** (-torch.arange(half, device="cpu", dtype=torch.float64) / half)
+        phase = times.detach().cpu().double()[:, None] * freq
+        embedding = torch.cat((phase.cos(), phase.sin()), -1).float().to(times.device)

Important: use .cpu().double(), not .to("cpu", torch.float64). On MPS (torch 2.14.1),
torch.tensor([1000., 976., 24.], device="mps").to("cpu", torch.float64) silently returns
[0., 0., 0.]. Every timestep then becomes 0 and the output is pure noise, with no error.

Verification
  • MacBook Pro, M5 Pro, 64 GB; macOS 27.0.1; torch 2.14.1; diffusers 0.42.0.dev0;
    transformers 5.20.2; OpenMOSS-Team/MOSS-Image-SFT @ f972bd4
  • Same seed and prompt at 512×512, 10 steps, CFG 1: the MPS output matches the CPU
    reference image (MPS 4 s vs CPU 701 s).
  • 1024×1024, 25 steps, CFG 2.5: 89 s on MPS, correct output.
  • Every other component matched CPU on MPS in a layer-by-layer comparison: text
    encoder, attention, RoPE, embedders, all 42 blocks.
Notes for Mac users
  • Load with torch_dtype={"default": torch.bfloat16, "vae": torch.float32}, then
    pipe.to("mps").
  • causal_conv1d and flash-linear-attention are CUDA-only, so the text encoder uses
    transformers' reference kernels. That's slower but correct.
  • torchvision is required by the Qwen3-VL processor.

Please consider applying this in the repo (including the transformer/ and scheduler/
copies of the file) and listing Apple Silicon as supported.

Lingua principale
Python
Stelle
2.2k
Fork
114
Merge medio
9g 1h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OpenMOSS/MOSS-Image

Tutte le issue di OpenMOSS/MOSS-Image

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.