Skip to content

[NPU] Fix HunyuanImage3 MoE EP+SP parallel mapping - #4344

Merged
Gaohan123 merged 33 commits into
vllm-project:mainfrom
Celeste-jq:npu-hunyuanimage3-dit-ep-sp-fix
Jul 2, 2026
Merged

Gaohan123 merged 33 commits into
vllm-project:mainfrom
Celeste-jq:npu-hunyuanimage3-dit-ep-sp-fix

Conversation

@Celeste-jq

@Celeste-jq Celeste-jq commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes NPU HunyuanImage3 fused MoE runtime failures when expert parallelism is enabled together with diffusion sequence parallelism. #3877. #4438 .

Root cause

HunyuanImage3 is a diffusion MoE model. vllm-omni has its own diffusion parallel dimensions:

TP  = tensor_parallel_size
SP  = sequence_parallel_size
CFG = cfg_parallel_size
DP  = data_parallel_size

vLLM FusedMoE, however, expects MoE expert placement to be expressed through its native dimensions:

MoE EP size = TP * PCP * DP

Before this patch, the NPU HunyuanImage3 fused MoE path did not consistently map diffusion SP/CFG into vLLM's MoE parallel semantics. This could make local expert placement and token dispatch disagree, causing runtime failures such as:

RuntimeError: shape '[8, 16]' is invalid for input of size 64

What this PR changes

This patch keeps the change in vllm-omni and does not modify vLLM or vllm-ascend.

For diffusion MoE models with enable_expert_parallel=True, vllm-omni maps:

diffusion TP       -> vLLM TP
diffusion SP       -> vLLM PCP
diffusion CFG * DP -> vLLM DP

So vLLM FusedMoE computes:

EP = TP * PCP * DP = TP * SP * CFG * DP

The mapping is gated on both:

od_config.is_moe
enable_expert_parallel

This avoids changing vLLM PCP/DP semantics for non-MoE models or for MoE models running with expert parallelism disabled.

Implementation details

  • In diffusion_worker.py, set vLLM prefill_context_parallel_size and adjusted data_parallel_size only for MoE + EP.
  • In parallel_state.py, expose diffusion _SP as vLLM _PCP, use cfg-dp as vLLM _DP when needed, and build vLLM _EP from tp-sp-cfg-dp.
  • In hunyuan_image3_transformer.py, let HunyuanImage3 FusedMoE use vLLM PCP only when EP is enabled; otherwise pass pcp_size=1 to avoid requiring a PCP group.
  • In platforms/npu/models/hunyuan_fused_moe.py, remove the previous effective-TP rewrite and keep only the NPU backend glue needed to sync vllm-ascend EP/MC2 state with vLLM's EP group.

Validation

Tested on 8 NPUs with HunyuanImage3 DiT-only offline serving.

TP4 + SP2 + EP enabled

Config highlights:

tensor_parallel_size: 4
sequence_parallel_size: 2
ulysses_degree: 2
ring_degree: 1
enable_expert_parallel: true
cfg_parallel_size: 1
data_parallel_size: 1

Expected MoE mapping:

vLLM TP  = 4
vLLM PCP = 2
vLLM DP  = 1
vLLM EP  = 8

Observed result:

e2e_requests                1
e2e_wall_time_ms            11,972.534
e2e_stage_0_wall_time_ms    11,970.978
denoise_step_latency_ms     239.397
image_pixels                1,048,576
output_unit_count           1
output_unit_type            image
stage_gen_time_ms           11,969.872

TP4 + SP2 + EP disabled

Config highlights:

tensor_parallel_size: 4
sequence_parallel_size: 2
ulysses_degree: 2
ring_degree: 1
enable_expert_parallel: false
cfg_parallel_size: 1
data_parallel_size: 1

Expected behavior:

No vLLM PCP/DP MoE mapping is enabled.
HunyuanImage3 FusedMoE uses pcp_size=1.

Observed result:

e2e_requests                1
e2e_wall_time_ms            9,407.734
e2e_stage_0_wall_time_ms    9,406.435
denoise_step_latency_ms     188.118
image_pixels                1,048,576
output_unit_count           1
output_unit_type            image
stage_gen_time_ms           9,405.898

Scope

The MoE parallel mapping is only enabled for diffusion MoE models when expert parallelism is enabled.

NPU-specific code only synchronizes vllm-ascend's MoE runtime state with the vLLM EP group and MC2 group. It does not redefine a separate NPU-only MoE formula.

GPU/XPU/default paths are not given a separate formula; the goal is to keep MoE TP/PCP/DP/EP semantics aligned across backends.

@Celeste-jq
Celeste-jq requested a review from gcanlin as a code owner June 11, 2026 08:32
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@Celeste-jq
Celeste-jq force-pushed the npu-hunyuanimage3-dit-ep-sp-fix branch from f4fa3e6 to 10662af Compare June 11, 2026 08:36
@Celeste-jq

Copy link
Copy Markdown
Contributor Author

@Celeste-jq
Celeste-jq force-pushed the npu-hunyuanimage3-dit-ep-sp-fix branch from 10662af to 616c695 Compare June 11, 2026 09:06
@Celeste-jq

Copy link
Copy Markdown
Contributor Author

@hsliuustc0106 PTAL

Signed-off-by: Celeste-jq <591998922@qq.com>
@Celeste-jq
Celeste-jq force-pushed the npu-hunyuanimage3-dit-ep-sp-fix branch from 616c695 to 748f342 Compare June 12, 2026 07:50
@Celeste-jq
Celeste-jq marked this pull request as draft June 12, 2026 09:52
@Celeste-jq Celeste-jq closed this Jun 15, 2026
Signed-off-by: Celeste-jq <591998922@qq.com>
Signed-off-by: Celeste-jq <591998922@qq.com>
Signed-off-by: Celeste-jq <591998922@qq.com>
Signed-off-by: Celeste-jq <591998922@qq.com>
@Celeste-jq Celeste-jq changed the title [NPU] Fix HunyuanImage3 fused MoE runtime for EP+SP [NPU] Fix HunyuanImage3 MoE EP+SP parallel mapping Jun 16, 2026
@Celeste-jq Celeste-jq reopened this Jun 16, 2026
@Celeste-jq
Celeste-jq marked this pull request as ready for review June 16, 2026 08:23
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Signed-off-by: Celeste-jq <591998922@qq.com>
Comment thread vllm_omni/diffusion/distributed/parallel_state.py Outdated
@@ -1633,7 +1575,7 @@ def __init__(
prefix=f"{prefix}.experts",
enable_eplb=self.enable_eplb,
num_redundant_experts=self.n_redundant_experts,
pcp_size=1,
pcp_size=None if enable_expert_parallel else 1,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to set pcp_size, dp_size to correct number?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For EP=true, pcp_size/dp_size are intentionally left as None so vLLM FusedMoE reads them from the already initialized vLLM PCP/DP groups and then computes the MoE EP layout from those sizes.
For EP=false, pcp_size=1 is required to avoid querying an uninitialized PCP group.

Signed-off-by: Celeste-jq <591998922@qq.com>
@Celeste-jq
Celeste-jq force-pushed the npu-hunyuanimage3-dit-ep-sp-fix branch from 0e979bc to 32904c9 Compare June 16, 2026 12:31
Signed-off-by: Celeste-jq <591998922@qq.com>
@@ -64,6 +68,22 @@ def _init_mc2_group_for_diffusion(
)


def _sync_ascend_ep_group_for_diffusion() -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, assigning a value to _EP in vllm_ascend.distributed.parallel_state is meaningless, because Ascend uses _EP from vllm.distributed.parallel_state, and vllm.distributed.parallel_state.EP has already been assigned a value in vllm_omni/diffusion/distributed/parallel_state.py.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. done.

Signed-off-by: Celeste-jq <591998922@qq.com>

@Bounty-hunter Bounty-hunter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Celeste-jq

Copy link
Copy Markdown
Contributor Author

@hsliuustc0106 hsliuustc0106 added the ready label to trigger buildkite CI label Jun 29, 2026
@yenuo26

yenuo26 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

For further assurance, can we add NPU types to the hardware labels of the relevant test cases, or add E2E test cases for the corresponding scenarios, in subsequent PRs?

@hsliuustc0106 hsliuustc0106 removed the ready label to trigger buildkite CI label Jun 29, 2026
@jiangmengyu18

Copy link
Copy Markdown
Contributor

For further assurance, can we add NPU types to the hardware labels of the relevant test cases, or add E2E test cases for the corresponding scenarios, in subsequent PRs?

Sure, we'll address that in a subsequent PR. This PR is intended to be a general change that works for both GPU and NPU.

@hsliuustc0106 hsliuustc0106 added the ready label to trigger buildkite CI label Jun 30, 2026
)

_EXPERT_PARALLEL_GROUP_RANKS = None
if enable_expert_parallel:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dropped the old od_config.is_moe guard. Non-MoE diffusion configs with enable_expert_parallel=True now create vLLM PCP/DP/EP state instead of failing fast, even though this remap should be MoE-only. Please keep the remap gated on both EP and od_config.is_moe, and add a regression test for non-MoE + EP.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Gaohan123 Gaohan123 removed the ready label to trigger buildkite CI label Jul 2, 2026
@Gaohan123
Gaohan123 requested a review from xuechendi as a code owner July 2, 2026 03:12

@Gaohan123 Gaohan123 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks

@Gaohan123 Gaohan123 added the ready label to trigger buildkite CI label Jul 2, 2026
@Gaohan123
Gaohan123 enabled auto-merge (squash) July 2, 2026 03:27
@Gaohan123
Gaohan123 merged commit a25636d into vllm-project:main Jul 2, 2026
7 of 9 checks passed
Celeste-jq added a commit to Celeste-jq/vllm-omni-npu-pr that referenced this pull request Jul 2, 2026
wkutak pushed a commit to wkutak/vllm-omni-cosmos-genai-nim that referenced this pull request Jul 13, 2026
Signed-off-by: Celeste-jq <591998922@qq.com>
Signed-off-by: Wojciech Kutak <wkutak@nvidia.com>
khairulkabir1661 pushed a commit to khairulkabir1661/vllm-omni that referenced this pull request Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NPU PR related to Ascend NPU omni code related to omni models ready label to trigger buildkite CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: HunyuanImage3 DiT on NPU with EP+SP fails in fused MoE token dispatcher reshape

6 participants