Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#23 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@arxigen đang làm issue này rồi.

Từ ngày 26/10/2026.

  • #25 của @arxigen — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, pytorch
Lĩnh vực
machine-learning

Hướng nghiên cứu

Bản sửa lỗi đã được viết đầy đủ: thay thế phép tính sinusoide float64 trong MOSSImageTransformer.forward bên trong pipeline_moss_image.py bằng phiên bản được tính trên CPU như trong diff, và áp dụng thay đổi tương tự cho các bản sao trong transformer/ và scheduler/. Trước tiên, hãy xác minh trên CPU rằng các đầu ra không thay đổi, sau đó chạy sinh dữ liệu với thiết bị MPS nếu có. Hoàn thành khi cả ba bản sao đã được vá và việc sinh dữ liệu tạo ra hình ảnh chính xác trên cả CPU và MPS.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
2.2k
Fork
114
Merge trung bình
9 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của OpenMOSS/MOSS-Image

Tất cả issue của OpenMOSS/MOSS-Image

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.