[diffusion] fix: fix accuracy for some image models#20679
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a specific issue within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request correctly introduces the num_replicated_prefix parameter to the USPAttention call, using seq_len_txt. This ensures that replicated text tokens are handled appropriately within the attention mechanism, which is crucial for maintaining correct attention weights in a distributed setup. The change aligns with the intended functionality of the USPAttention module.
|
/tag-and-rerun-ci |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
4 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
Thanks for fixing this SP precision issue, here are some quantized test results on our side for reference Worst-case
|
| Model | Metric | Before | After | Result |
|---|---|---|---|---|
| Z-Image-Turbo | model_output | 0.5039 | 1.0000 | ✅ Fixed (exact match) |
| Z-Image-Turbo | prev_sample_mean | 0.7694 | 1.0000 | ✅ Fixed (exact match) |
| Qwen-Image | model_output | 0.8616 | 1.0000 | ✅ Fixed (exact match) |
| Qwen-Image | prev_sample_mean | 0.8825 | 1.0000 | ✅ Fixed (exact match) |
Motivation
Modifications
Qwen-Image: align CFG with official diffusers by introducingtrue_cfg_scale, enabling CFG whentru e_cfg_scale > 1, and matching the official true-CFG norm rescale.Qwen-Image-Edit: respect negative-image, so the uncond branch really usesnegative_prompt.Qwen-Image-Edit: keep Qwen2.5-VL vision rotary frequencies in fp32(aligned with diffusers) to reduce encoder driftQwen-Image-Editwithulysses-degree=2: shard rope of condition-image together with rope of noisy-image, and buildzero_cond_tmodulation indices from local SP sequence lengths.Z-Image: fix prompt/tokenization and dtype by using rendered chat-template prompts, bf16 text encoding, and fp32 latent sampling/scheduler state.Z-Image with SP/Ulysses: stop sharding caption tokens (condition shouldn't be sharded), keep caption as a replicated suffix in joint attention, and fix the local/global RoPE offsets so multi-GPU stays aligned with single-GPURepro
Qwen-Image
with
--ulysses-degree 2:Qwen-Image-Edit
abs_diff (1-gpu vs diffusers):

with
--ulysses-degree 2:Z-Image-Turbo
with
--ulysses-degree=2:Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci