Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tests/models/test_deepseek_v4_vl_rocm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import torch
from torch import nn

from vllm.config import ParallelConfig
from vllm.model_executor.models.utils import WeightsMapper
from vllm.platforms import current_platform

Expand Down Expand Up @@ -100,7 +101,9 @@ def fake_factory(**kwargs):
n_shared_experts=None,
)
vllm_config = SimpleNamespace(
model_config=SimpleNamespace(hf_config=config), quant_config=None
model_config=SimpleNamespace(hf_config=config),
quant_config=None,
parallel_config=ParallelConfig(),
)

hash_moe = rocm_model.DeepseekV4MoE(vllm_config, prefix="model.layers.0.ffn")
Expand All @@ -115,6 +118,24 @@ def fake_factory(**kwargs):
assert factory_kwargs["image_sentinel_lo"] == IMAGE_SENTINEL_BASE_ID


def test_rocm_fse_rejects_data_parallel_deployment(
monkeypatch: pytest.MonkeyPatch,
) -> None:
from vllm.models.deepseek_v4.amd.model import _fuse_shared_experts_enabled

config = SimpleNamespace(n_shared_experts=1)

monkeypatch.setenv("VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS", "1")
with pytest.raises(ValueError, match="data parallelism"):
_fuse_shared_experts_enabled(config, ParallelConfig(data_parallel_size=2))

# Expert parallelism already disables FSE: no raise, FSE stays off.
assert not _fuse_shared_experts_enabled(
config, ParallelConfig(data_parallel_size=2, enable_expert_parallel=True)
)
assert _fuse_shared_experts_enabled(config, ParallelConfig())


def test_rocm_mtp_forwards_input_ids_for_vision_routing(
monkeypatch: pytest.MonkeyPatch,
) -> None:
Expand Down
25 changes: 21 additions & 4 deletions vllm/models/deepseek_v4/amd/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import vllm.envs as envs
from vllm._aiter_ops import rocm_aiter_ops
from vllm.config import VllmConfig, get_current_vllm_config
from vllm.config import ParallelConfig, VllmConfig
from vllm.distributed import (
get_pp_group,
get_tensor_model_parallel_rank,
Expand Down Expand Up @@ -504,11 +504,28 @@ def forward_modular(
return routed + shared_out


def _fuse_shared_experts_enabled(config) -> bool:
def _fuse_shared_experts_enabled(config, parallel_config: ParallelConfig) -> bool:
if (
getattr(config, "n_shared_experts", None)
and envs.VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS
and not parallel_config.enable_expert_parallel
and parallel_config.data_parallel_size > 1
):
# Fused shared experts are not supported under data parallelism:
# the fused path cannot load the FP8 shared expert into the MXFP4
# routed slot, which fails obscurely during weight loading. Fail
# fast with an actionable message instead.
raise ValueError(
"DeepSeek-V4 fused shared experts "
"(VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS=1) are not supported "
"with data parallelism (data_parallel_size > 1). Set "
"VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS=0 to run the shared "
"expert as an unfused FP8 MLP."
)
return bool(
getattr(config, "n_shared_experts", None)
and envs.VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS
and not get_current_vllm_config().parallel_config.enable_expert_parallel
and not parallel_config.enable_expert_parallel
)


Expand Down Expand Up @@ -586,7 +603,7 @@ def __init__(
# This should be cleaned up and use `resolve_layer_fused_shared_expert`.
self.fuse_heterogeneous_shared_expert = fuse_heterogeneous_shared_expert
fse_requested = (
_fuse_shared_experts_enabled(config)
_fuse_shared_experts_enabled(config, vllm_config.parallel_config)
and not self.fuse_heterogeneous_shared_expert
)
fse_compatible = False
Expand Down
Loading