[Bugfix] [diffusion] Fix cache-dit with sp-degree only#19965
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 critical bug affecting 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
Activity
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
This pull request fixes a bug related to using sp-degree with cache-dit by correctly retrieving parallelism information. The changes involve using get_sp_group() to access ulysses_world_size and ring_world_size, and updating the cache-dit backend to AUTO for better flexibility. The fix appears correct, but I've suggested a minor refactoring to avoid redundant function calls and improve code clarity.
| ulysses_size = get_sp_group().ulysses_world_size | ||
| ring_size = get_sp_group().ring_world_size |
There was a problem hiding this comment.
To improve readability and avoid calling get_sp_group() twice, you can store its result in a local variable and reuse it.
| ulysses_size = get_sp_group().ulysses_world_size | |
| ring_size = get_sp_group().ring_world_size | |
| sp_coord = get_sp_group() | |
| ulysses_size = sp_coord.ulysses_world_size | |
| ring_size = sp_coord.ring_world_size |
|
/tag-and-rerun-ci |
|
cc @DefTruth |
|
/tag-and-rerun-ci |
| if sp_group is not None: | ||
| ulysses_size = getattr(sp_group, "ulysses_world_size", None) | ||
| ring_size = getattr(sp_group, "ring_world_size", None) | ||
| ulysses_size = get_sp_group().ulysses_world_size |
There was a problem hiding this comment.
Why not just use sp_group? It's no longer None.
There was a problem hiding this comment.
Are you sure? I test it now and it still doesn't work on the latest version of slang from the main
There was a problem hiding this comment.
Which PR fix this issue?
There was a problem hiding this comment.
In my case (and #19955) the sp_group has no attributes "ulysses_world_size" and "ring_world_size"
There was a problem hiding this comment.
In my case (and #19955) the sp_group has no attributes "ulysses_world_size" and "ring_world_size"
@OrangeRedeng Hi~ I think you are right, the sp/tp_group inside _build_parallelism_config are assumed to be torch.distributed.ProcessGroup, but ProcessGroup has no attributes "ulysses_world_size" and "ring_world_size". The bug #19955 you has encountered maybe cause by errored sp/tp_group assigning logics at:
Maybe we should change these code snippets to:
sp_group = sp_group_candidate if has_sp else None
tp_group = tp_group_candidate if has_tp else None By the way, we should also fix the signature of _build_parallelism_config to avoid misleading developers with the wrong usage. From the old one:
sglang/python/sglang/multimodal_gen/runtime/cache/cache_dit_integration.py
Lines 100 to 103 in 484f53c
to the correctly signature:
def _build_parallelism_config(
sp_group: Optional[GroupCoordinator],
tp_group: Optional[GroupCoordinator],
): @OrangeRedeng Could you please take a try?
Also cc @mickqian
|
Also encounter the same error while using FLUX.1 with cache: File "/workspace/dev/vipshop/sglang/python/sglang/multimodal_gen/runtime/cache/cache_dit_integration.py", line 304, in enable_cache_on_transformer
parallelism_config = _build_parallelism_config(sp_group, tp_group)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/dev/vipshop/sglang/python/sglang/multimodal_gen/runtime/cache/cache_dit_integration.py", line 117, in _build_parallelism_config
return ParallelismConfig(
^^^^^^^^^^^^^^^^^^
File "<string>", line 26, in __init__
File "/workspace/dev/vipshop/cache-dit/src/cache_dit/parallelism/config.py", line 119, in __post_init__
raise ValueError(
ValueError: No parallelism is enabled. Please set ulysses_size, ring_size, or tp_size to enable parallelism.
[03-09 08:21:06] Failed to generate output for prompt 1: Error executing request 53f0ff81-08b2-4d81-8cdb-525b8eb653e0: No parallelism is enabled. Please set ulysses_size, ring_size, or tp_size to enable parallelism.
Traceback (most recent call last):
File "/workspace/dev/vipshop/sglang/python/sglang/multimodal_gen/runtime/utils/logging_utils.py", line 466, in log_generation_timer
yield timer
File "/workspace/dev/vipshop/sglang/python/sglang/multimodal_gen/runtime/entrypoints/diffusion_generator.py", line 209, in generate
raise Exception(f"{output_batch.error}")
Exception: Error executing request 53f0ff81-08b2-4d81-8cdb-525b8eb653e0: No parallelism is enabled. Please set ulysses_size, ring_size, or tp_size to enable parallelism.
[03-09 08:21:06] Generation failed for prompt 1/1: Error executing request 53f0ff81-08b2-4d81-8cdb-525b8eb653e0: No parallelism is enabled. Please set ulysses_size, ring_size, or tp_size to enable parallelism.
Traceback (most recent call last):
File "/workspace/dev/vipshop/sglang/python/sglang/multimodal_gen/runtime/entrypoints/diffusion_generator.py", line 209, in generate
raise Exception(f"{output_batch.error}")
Exception: Error executing request 53f0ff81-08b2-4d81-8cdb-525b8eb653e0: No parallelism is enabled. Please set ulysses_size, ring_size, or tp_size to enable parallelism.cache-dit introduces a new "post_init" check after v1.2.3 that throws an error if all parallel sizes are not valid. |
How to reproduce: SGLANG_CACHE_DIT_ENABLED=true \
sglang generate --model-path $FLUX_DIR \
--prompt "test prompt for checking bug" \
--dit-cpu-offload false \
--text-encoder-cpu-offload false \
--sp-degree 4 --num-gpus 4 |
|
@OrangeRedeng @mickqian Confirm this fix works as expected. However, this remains a hacky workaround; we should instead consider addressing the root cause by passing the correct parallel groups to the helper function. |
|
@DefTruth Thank you for your detailed response! I agree that the solution is temporary, and I will try to offer a new version of the fix ASAP |
|
@DefTruth Hi, I took a closer look at the code, first of all, as it turned out, we already have a lot of built-in (and partially unused) functions, such as |
cc @mickqian |
|
hey @OrangeRedeng , cleaning this up in: https://github.com/sgl-project/sglang/pull/20760/changes |
Hi @mickqian , we've rebased and retriggered CI. now all CIs passed, shall we merge this PR? |
|
@mickqian All CI (Nvidia + AMD) passed and PR is approved, ready for merge — SGLDHelper bot |
…9965) Co-authored-by: Mick <mickjagger19@icloud.com> Co-authored-by: ronnie_zheng <zl19940307@163.com>
…9965) Co-authored-by: Mick <mickjagger19@icloud.com> Co-authored-by: ronnie_zheng <zl19940307@163.com>
…9965) Co-authored-by: Mick <mickjagger19@icloud.com> Co-authored-by: ronnie_zheng <zl19940307@163.com>
…9965) Co-authored-by: Mick <mickjagger19@icloud.com> Co-authored-by: ronnie_zheng <zl19940307@163.com>
…9965) Co-authored-by: Mick <mickjagger19@icloud.com> Co-authored-by: ronnie_zheng <zl19940307@163.com>



Motivation
Fix bug from #19955 issue, now sp-degree only works correctly
Modifications
Change
getattr(sp_group, "ulysses_world_size", None)toget_sp_group().ulysses_world_size, the same withring_world_size, changeParallelismBackend.NATIVE_PYTORCHtoParallelismBackend.AUTOAccuracy Tests
No influence
Benchmarking and Profiling
SP-degree only gives best performance (If there is enough memory)
sp-degree 4/tp-size 2:
SGLANG_CACHE_DIT_FN=2 SGLANG_CACHE_DIT_BN=1 SGLANG_CACHE_DIT_WARMUP=4 SGLANG_CACHE_DIT_RDT=0.4 SGLANG_CACHE_DIT_MC=4 SGLANG_CACHE_DIT_TAYLORSEER=true SGLANG_CACHE_DIT_TS_ORDER=2 SGLANG_CACHE_DIT_ENABLED=true sglang generate --model-path ./Wan2.2-T2V-A14B-Diffusers-w8a8/ --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." --height 720 --width 1280 --tp-size 2 --sp-degree 4 --num-gpus 8 --num-frames 81 --num-inference-steps 40 --port 30088sp-degree 8/tp-size 1 (sp-degree only scenario):
SGLANG_CACHE_DIT_FN=2 SGLANG_CACHE_DIT_BN=1 SGLANG_CACHE_DIT_WARMUP=4 SGLANG_CACHE_DIT_RDT=0.4 SGLANG_CACHE_DIT_MC=4 SGLANG_CACHE_DIT_TAYLORSEER=true SGLANG_CACHE_DIT_TS_ORDER=2 SGLANG_CACHE_DIT_ENABLED=true sglang generate --model-path ./Wan2.2-T2V-A14B-Diffusers-w8a8/ --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." --height 720 --width 1280 --tp-size 1 --sp-degree 8 --num-gpus 8 --num-frames 81 --num-inference-steps 40 --port 30088Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci