[Refactor] Reject unknown diffusion config fields (#5172)

Signed-off-by: TaffyOfficial <2324465096@qq.com>
Signed-off-by: zuiho <2324465096@qq.com>
Signed-off-by: Gao Han <hgaoaf@connect.ust.hk>
Co-authored-by: TaffyOfficial <2324465096@qq.com>
Co-authored-by: Gao Han <hgaoaf@connect.ust.hk>
This commit is contained in:
authored and GitHub committed 2026-09-19 15:37:34 +00:00
1 parent f90c267ffb
commit 698f716012
13 files changed
+716 -254

No files matched your search

+190 -64
View File
@@ -4,6 +4,7 @@
from __future__ import annotations
import warnings
from dataclasses import fields
from inspect import Parameter, signature
from multiprocessing.reduction import ForkingPickler
@@ -24,6 +25,7 @@ from vllm.config import SchedulerConfig as VllmSchedulerConfig
from tests.helpers.stage_config import get_deploy_config_path
from vllm_omni.config import omni_config as omni_config_module
from vllm_omni.config.config_factory import StageConfigFactory
from vllm_omni.config.omni_config import (
BaseVllmOmniStageConfig,
OmniStageCacheConfig,
@@ -150,6 +152,30 @@ def test_nested_stage_override_deep_merges_structured_model_config() -> None:
assert model_config["policy_server_config"]["action_space"] == "joint_position"
def _build_single_diffusion_config(
*,
cli_overrides: dict | None = None,
engine_extras: dict | None = None,
) -> VllmOmniConfig:
pipeline = PipelineConfig(
model_type="diffusion-owner-test",
stages=(
StagePipelineConfig(
stage_id=0,
model_stage="diffusion",
execution_type=StageExecutionType.DIFFUSION,
final_output=True,
),
),
)
deploy_stages = [StageDeployConfig(stage_id=0, engine_extras=engine_extras)] if engine_extras is not None else []
return VllmOmniConfig.from_pipeline_config(
pipeline,
user_deploy_config=DeployConfig(async_chunk=False, stages=deploy_stages),
cli_overrides=cli_overrides,
)
@pytest.mark.parametrize("model_type", sorted(OMNI_PIPELINES))
def test_vllm_omni_config_from_pipeline_config_matches_merge_pipeline_deploy(model_type: str):
pipeline = _resolve_pipeline_or_skip(model_type)
@@ -475,7 +501,7 @@ def test_from_pipeline_config_normalizes_nested_parallel_config_aliases(field_na
assert "data_parallel_master_ip" in stage.parallel_config._omni_explicit_fields
def test_from_pipeline_config_accepts_diffusion_only_cli_fields_for_diffusion_stage():
def test_from_pipeline_config_keeps_global_kv_cache_dtype_outside_diffusion_stage():
stage = _from_pipeline_key(
"dreamzero",
deploy_config_path="dreamzero_tp1_cfg2",
@@ -483,11 +509,57 @@ def test_from_pipeline_config_accepts_diffusion_only_cli_fields_for_diffusion_st
).stage_by_id(0)
assert isinstance(stage, VllmOmniDiffusionStageConfig)
assert stage.diffusion_config.diffusion_kv_cache_dtype == "fp8"
assert stage.diffusion_config.diffusion_kv_cache_dtype is None
def test_stage_cli_field_selection_defers_ownership_validation_until_sources_are_merged():
assert omni_config_module._stage_cli_overrides(0, {"enable_lora": True}) == {"enable_lora": True}
assert omni_config_module._stage_cli_overrides(
0,
{"enable_lora": True},
) == {"enable_lora": True}
@pytest.mark.parametrize(
("cli_overrides", "expected_dtype"),
[
({}, torch.float32),
({"dtype": None}, torch.float32),
({"dtype": "float16"}, torch.float16),
({"dtype": "auto"}, torch.bfloat16),
({"stage_0_dtype": "bfloat16"}, torch.bfloat16),
],
)
def test_diffusion_deploy_dtype_survives_unset_cli_overrides(cli_overrides, expected_dtype):
stage = _build_single_diffusion_config(
engine_extras={"dtype": "float32", "cache_backend": "tea_cache"},
cli_overrides=cli_overrides,
).stage_by_id(0)
assert stage.diffusion_config.dtype == expected_dtype
assert stage.diffusion_config.cache_backend == "tea_cache"
@pytest.mark.parametrize(
"coordination_kwargs",
[
{"omni_master_address": "127.0.0.1", "omni_master_port": 30000},
{"omni_dp_size_local": 2, "omni_heartbeat_timeout": 60.0, "omni_lb_policy": "random"},
],
)
def test_diffusion_ingress_routes_coordination_fields_away(coordination_kwargs):
normalize = omni_config_module.normalize_and_validate_diffusion_engine_ingress_kwargs
assert normalize({**coordination_kwargs, "enable_sleep_mode": True}, stage_id=0) == {"enable_sleep_mode": True}
with pytest.raises(ValueError, match="omni_master_unknown_field"):
normalize({**coordination_kwargs, "omni_master_unknown_field": "unknown"}, stage_id=0)
def test_diffusion_ingress_defers_defaults(monkeypatch):
monkeypatch.setenv("DIFFUSION_CACHE_BACKEND", "tea_cache")
assert omni_config_module.normalize_and_validate_diffusion_engine_ingress_kwargs({}, stage_id=0) == {}
assert omni_config_module.normalize_and_validate_diffusion_engine_ingress_kwargs(
{"dtype": None, "cache_backend": None}, stage_id=0
) == {"dtype": None, "cache_backend": None}
@pytest.mark.parametrize(
@@ -1415,18 +1487,19 @@ def test_diffusion_config_from_kwargs_reuses_legacy_normalization(monkeypatch):
monkeypatch.setenv("DIFFUSION_CACHE_BACKEND", "TEA_CACHE")
monkeypatch.setattr(current_omni_platform, "is_cuda", lambda: True)
cfg = omni_config_module._DiffusionConfigProjection.from_kwargs(
diffusion_attention_backend="flash_attn",
fa_deterministic=True,
kv_cache_dtype="fp8",
kv_cache_skip_steps="0-1",
kv_cache_skip_layers=[2],
static_lora_scale=0.25,
diffusion_kv_mode="paged_scheduler",
diffusion_kv_max_rows_per_request=2,
diffusers_load_kwargs=None,
diffusers_call_kwargs=None,
)
with pytest.warns(FutureWarning):
cfg = omni_config_module._DiffusionConfigProjection.from_kwargs(
diffusion_attention_backend="flash_attn",
fa_deterministic=True,
kv_cache_dtype="fp8",
kv_cache_skip_steps="0-1",
kv_cache_skip_layers=[2],
static_lora_scale=0.25,
diffusion_kv_mode="paged_scheduler",
diffusion_kv_max_rows_per_request=2,
diffusers_load_kwargs=None,
diffusers_call_kwargs=None,
)
assert cfg.diffusion_attention_config.default.backend == "flash_attn"
assert cfg.fa_deterministic is True
@@ -1463,47 +1536,6 @@ def test_diffusion_config_none_values_preserve_dataclass_defaults():
assert config.enable_sleep_mode is False
@pytest.mark.parametrize(
("canonical_key", "alias_key", "canonical_value", "alias_value"),
[
("lora_scale", "static_lora_scale", 0.75, 0.25),
(
"quantization_config",
"diffusion_quantization_config",
{"method": "canonical"},
{"method": "diffusion-alias"},
),
(
"quantization_config",
"quantization",
{"method": "canonical"},
"legacy-alias",
),
("diffusion_kv_cache_dtype", "kv_cache_dtype", "fp8", "fp16"),
("diffusion_kv_cache_skip_steps", "kv_cache_skip_steps", "0-1", "2-3"),
("diffusion_kv_cache_skip_layers", "kv_cache_skip_layers", "1-2", "3-4"),
("streaming_output", "diffusion_streaming_output", False, True),
],
)
def test_diffusion_alias_conflicts_prefer_canonical_key(
canonical_key,
alias_key,
canonical_value,
alias_value,
):
from vllm_omni.diffusion.data import normalize_omni_diffusion_kwargs
normalized = normalize_omni_diffusion_kwargs(
{
canonical_key: canonical_value,
alias_key: alias_value,
}
)
assert normalized[canonical_key] == canonical_value
assert alias_key not in normalized
def test_from_pipeline_config_normalizes_diffusion_config_aliases_from_engine_args(tmp_path, monkeypatch):
from vllm_omni.platforms import current_omni_platform
@@ -1528,10 +1560,11 @@ def test_from_pipeline_config_normalizes_diffusion_config_aliases_from_engine_ar
)
)
stage = _from_pipeline_key(
"dreamzero",
deploy_config_path=str(deploy_path),
).stage_by_id(0)
with pytest.warns(FutureWarning):
stage = _from_pipeline_key(
"dreamzero",
deploy_config_path=str(deploy_path),
).stage_by_id(0)
assert isinstance(stage, VllmOmniDiffusionStageConfig)
assert stage.diffusion_config.diffusion_attention_config.default.backend == "flash_attn"
@@ -1544,7 +1577,10 @@ def test_from_pipeline_config_normalizes_diffusion_config_aliases_from_engine_ar
from vllm_omni.engine.stage_init_utils import build_engine_args_dict_from_omni_stage_config
engine_args = build_engine_args_dict_from_omni_stage_config(stage, model=str(tmp_path))
od_config = OmniDiffusionConfig.from_kwargs(**engine_args)
diffusion_kwargs = omni_config_module.extract_diffusion_stage_config_kwargs(
engine_args, stage_id=stage.stage_id, include_engine_adapter_metadata=True
)
od_config = OmniDiffusionConfig.from_kwargs(**diffusion_kwargs)
assert od_config.kv_transfer_config.engine_id == "dit-engine-1"
@@ -1697,10 +1733,8 @@ def test_video_output_transport_survives_stage_override_filtering() -> None:
def test_video_output_transport_reaches_default_diffusion_stage() -> None:
from vllm_omni.engine.async_omni_engine import AsyncOmniEngine
transport = {"enable_device_postprocess": True}
stages = AsyncOmniEngine._create_default_diffusion_stage_cfg(
stages = StageConfigFactory.create_default_diffusion(
{
"model": "unused",
"model_class_name": "UnknownPipeline",
@@ -1830,3 +1864,95 @@ def test_diffusion_quantization_origin_survives_projection_and_transport(monkeyp
restored = ForkingPickler.loads(ForkingPickler.dumps(cfg))
assert restored.quantization_config_is_auto_detected is not explicit
assert restored.quantization_config.w4a8_fallback_steps == ([] if explicit else [37])
@pytest.mark.parametrize(
"factory",
[
omni_config_module._DiffusionConfigProjection.from_kwargs,
pytest.param(
lambda **kwargs: __import__(
"vllm_omni.diffusion.data",
fromlist=["OmniDiffusionConfig"],
).OmniDiffusionConfig.from_kwargs(**kwargs),
id="runtime-config",
),
],
)
def test_diffusion_config_entrypoints_reject_unknown_none(factory):
with pytest.raises((ValueError, ValidationError), match="enable_sleep_mod"):
factory(enable_sleep_mod=None)
def test_diffusion_config_projection_rejects_unknown_none():
with pytest.raises(ValueError, match="enable_sleep_mod"):
omni_config_module._DiffusionConfigProjection.from_kwargs(enable_sleep_mod=None)
def test_runtime_diffusion_config_rejects_unknown_none():
from vllm_omni.diffusion.data import OmniDiffusionConfig
with pytest.raises(ValueError, match="enable_sleep_mod"):
OmniDiffusionConfig.from_kwargs(enable_sleep_mod=None)
def test_direct_diffusion_aliases_promote_none_and_reject_real_conflicts(monkeypatch):
from vllm_omni.diffusion import data as diffusion_data
from vllm_omni.diffusion.data import OmniDiffusionConfig
monkeypatch.setattr(diffusion_data, "build_quant_config", lambda config: config)
with pytest.warns(FutureWarning) as warnings:
config = OmniDiffusionConfig.from_kwargs(
quantization={"method": "example"},
quantization_config=None,
kv_cache_dtype="fp8",
diffusion_kv_cache_dtype=None,
enable_sleep_mode=False,
request_batch_max_wait_ms=0.0,
)
warning_messages = [str(warning.message) for warning in warnings]
assert any("quantization" in message for message in warning_messages)
assert any("kv_cache_dtype" in message for message in warning_messages)
assert config.quantization_config == {"method": "example"}
assert config.diffusion_kv_cache_dtype == "fp8"
assert config.enable_sleep_mode is False
assert config.request_batch_max_wait_ms == 0.0
with pytest.raises(ValueError, match=r"quantization.*quantization_config"):
OmniDiffusionConfig.from_kwargs(quantization="fp8", quantization_config={"method": "example"})
def test_structured_diffusion_stage_rejects_unknown_engine_extra():
with pytest.raises(ValueError, match=r"stage 0.*enable_sleep_mod"):
_build_single_diffusion_config(engine_extras={"enable_sleep_mod": None})
with pytest.raises(ValueError, match=r"stage 0.*enable_sleep_mod"):
_build_single_diffusion_config(cli_overrides={"enable_sleep_mod": None})
with pytest.raises(ValueError, match=r"stage 0.*enable_sleep_mod"):
_build_single_diffusion_config(cli_overrides={"stage_0_enable_sleep_mod": None})
with pytest.raises(ValueError, match=r"no structured config owner: parallel_config\.unknown_field"):
_build_single_diffusion_config(engine_extras={"parallel_config": {"unknown_field": 1}})
def test_structured_diffusion_stage_keeps_shared_globals_outside_diffusion():
with warnings.catch_warnings(record=True) as caught:
stage = _build_single_diffusion_config(
cli_overrides={"kv_cache_dtype": "fp8", "seed": 7},
).stage_by_id(0)
assert stage.diffusion_config.diffusion_kv_cache_dtype is None
assert not any(issubclass(warning.category, FutureWarning) for warning in caught)
@pytest.mark.parametrize(
("field_name", "config_kwargs"),
[
("seed", {"cli_overrides": {"stage_0_seed": None}}),
("kv_cache_dtype", {"engine_extras": {"kv_cache_dtype": "fp8"}}),
],
)
def test_structured_diffusion_stage_rejects_explicit_shared_engine_field(field_name, config_kwargs):
with pytest.raises(ValueError, match=rf"stage 0.*{field_name}"):
_build_single_diffusion_config(**config_kwargs)
+51
View File
@@ -0,0 +1,51 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""Check the sleep/wake E2E topology before loading large BAGEL weights."""
import pytest
from tests.entrypoints.test_omni_sleep_mode import _sleep_deploy_config
from vllm_omni.config.omni_config import (
VllmOmniConfig,
VllmOmniDiffusionStageConfig,
extract_diffusion_stage_config_kwargs,
)
from vllm_omni.config.pipeline_registry import resolve_pipeline_config
from vllm_omni.config.stage_config import load_deploy_config
from vllm_omni.diffusion.data import OmniDiffusionConfig
from vllm_omni.engine.stage_init_utils import build_engine_args_dict_from_omni_stage_config
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
@pytest.mark.parametrize("diffusion_only,tp_size", [(False, 1), (False, 2), (True, 2)])
def test_sleep_deploy_resolves_expected_stages(diffusion_only, tp_size):
deploy = load_deploy_config(_sleep_deploy_config(diffusion_only=diffusion_only, tp_size=tp_size))
pipeline = resolve_pipeline_config(deploy.pipeline or "bagel")
config = VllmOmniConfig.from_pipeline_config(pipeline, user_deploy_config=deploy)
assert len(config.stage_configs) == (1 if diffusion_only else 2)
for stage in config.stage_configs:
is_diffusion = diffusion_only or stage.stage_id == 1
assert isinstance(stage, VllmOmniDiffusionStageConfig) == is_diffusion
# Keep BAGEL's batch budget: a single multimodal item needs 8625 tokens.
assert stage.scheduler_config.max_num_batched_tokens == 32768
assert stage.model_config.enable_sleep_mode is True
assert stage.parallel_config.tensor_parallel_size == tp_size
assert stage.runtime_config.devices == ",".join(str(stage.stage_id * tp_size + rank) for rank in range(tp_size))
if not is_diffusion:
assert stage.cache_config.gpu_memory_utilization == 0.8
if is_diffusion:
engine_args = build_engine_args_dict_from_omni_stage_config(stage, "test-bagel")
terminal = OmniDiffusionConfig.from_kwargs(
**extract_diffusion_stage_config_kwargs(
engine_args, stage_id=stage.stage_id, include_engine_adapter_metadata=True
)
)
assert terminal.enable_sleep_mode is True
assert terminal.parallel_config.tensor_parallel_size == tp_size
if not diffusion_only:
assert config.stage_by_id(1).stage_pipeline_config.input_sources == (0,)
assert deploy.stages[1].input_connectors["from_stage_0"] == "shared_memory_connector"