Merge remote-tracking branch 'origin/main' into sync/lesj/qwen4exp-bugfixes
Signed-off-by: lesj0610 <lesj0610@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import enum
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@@ -19,6 +20,7 @@ from vllm.logger import (
|
||||
_DATE_FORMAT,
|
||||
_FORMAT,
|
||||
_configure_vllm_root_logger,
|
||||
_use_color,
|
||||
enable_trace_function_call,
|
||||
init_logger,
|
||||
)
|
||||
@@ -72,6 +74,27 @@ def test_default_vllm_root_logger_configuration(monkeypatch):
|
||||
assert formatter.datefmt == _DATE_FORMAT
|
||||
|
||||
|
||||
def test_use_color_force_color(monkeypatch):
|
||||
"""FORCE_COLOR forces colored logs without a TTY, while NO_COLOR and an
|
||||
explicit VLLM_LOGGING_COLOR=0 take precedence over it."""
|
||||
monkeypatch.setattr(sys, "stdout", io.StringIO())
|
||||
monkeypatch.setattr(sys, "stderr", io.StringIO())
|
||||
for var in ("NO_COLOR", "FORCE_COLOR", "VLLM_LOGGING_COLOR"):
|
||||
monkeypatch.delenv(var, raising=False)
|
||||
|
||||
assert not _use_color()
|
||||
|
||||
monkeypatch.setenv("FORCE_COLOR", "1")
|
||||
assert _use_color()
|
||||
|
||||
monkeypatch.setenv("VLLM_LOGGING_COLOR", "0")
|
||||
assert not _use_color()
|
||||
monkeypatch.delenv("VLLM_LOGGING_COLOR")
|
||||
|
||||
monkeypatch.setenv("NO_COLOR", "1")
|
||||
assert not _use_color()
|
||||
|
||||
|
||||
def test_descendent_loggers_depend_on_and_propagate_logs_to_root_logger(monkeypatch):
|
||||
"""This test presumes that VLLM_CONFIGURE_LOGGING (default: True) and
|
||||
VLLM_LOGGING_CONFIG_PATH (default: None) are not configured and default
|
||||
|
||||
@@ -19,6 +19,7 @@ from vllm.config import (
|
||||
SpeculativeConfig,
|
||||
VllmConfig,
|
||||
)
|
||||
from vllm.distributed.ec_transfer.ec_connector.metrics import ECConnectorStats
|
||||
from vllm.distributed.kv_transfer.kv_connector.v1.hisparse.connector import (
|
||||
HiSparseConnector,
|
||||
HiSparseConnectorScheduler,
|
||||
@@ -5296,6 +5297,87 @@ def test_scheduler_kv_connector_stats():
|
||||
assert final_stats == expected_data
|
||||
|
||||
|
||||
def test_scheduler_ec_connector_stats():
|
||||
"""Test worker-side, scheduler-side, and combined EC connector stats."""
|
||||
|
||||
class GenericECConnectorStats(ECConnectorStats):
|
||||
def reset(self):
|
||||
self.data = {}
|
||||
|
||||
def aggregate(self, other: ECConnectorStats) -> ECConnectorStats:
|
||||
self.data.update(other.data)
|
||||
return self
|
||||
|
||||
def reduce(self) -> dict[str, int | float]:
|
||||
return {}
|
||||
|
||||
def is_empty(self) -> bool:
|
||||
return not self.data
|
||||
|
||||
test_cases = (
|
||||
({"worker": 1}, None, {"worker": 1}),
|
||||
(None, {"scheduler": 2}, {"scheduler": 2}),
|
||||
({"worker": 1}, {"scheduler": 2}, {"worker": 1, "scheduler": 2}),
|
||||
)
|
||||
|
||||
for worker_data, scheduler_data, expected_data in test_cases:
|
||||
scheduler = create_scheduler()
|
||||
worker_stats = (
|
||||
GenericECConnectorStats(data=worker_data) if worker_data else None
|
||||
)
|
||||
scheduler_stats = (
|
||||
GenericECConnectorStats(data=scheduler_data) if scheduler_data else None
|
||||
)
|
||||
scheduler.ec_connector = Mock()
|
||||
scheduler.ec_connector.take_unavailable_requests.return_value = set()
|
||||
scheduler.ec_connector.get_ec_connector_stats.return_value = (
|
||||
scheduler_stats if worker_stats is None else None
|
||||
)
|
||||
|
||||
def update_connector_output(
|
||||
ec_connector_output: ECConnectorOutput,
|
||||
scheduler=scheduler,
|
||||
scheduler_stats=scheduler_stats,
|
||||
):
|
||||
scheduler.ec_connector.get_ec_connector_stats.return_value = scheduler_stats
|
||||
|
||||
scheduler.ec_connector.update_connector_output.side_effect = (
|
||||
update_connector_output
|
||||
)
|
||||
|
||||
model_output = ModelRunnerOutput(
|
||||
req_ids=["req_0"],
|
||||
req_id_to_index={"req_0": 0},
|
||||
sampled_token_ids=[[123]],
|
||||
logprobs=None,
|
||||
prompt_logprobs_dict={},
|
||||
pooler_output=[None],
|
||||
ec_connector_output=ECConnectorOutput(ec_connector_stats=worker_stats)
|
||||
if worker_stats
|
||||
else None,
|
||||
)
|
||||
scheduler_output = SchedulerOutput(
|
||||
scheduled_new_reqs=[],
|
||||
scheduled_cached_reqs=None,
|
||||
num_scheduled_tokens={"req_0": 1},
|
||||
total_num_scheduled_tokens=1,
|
||||
scheduled_spec_decode_tokens={},
|
||||
scheduled_encoder_inputs={},
|
||||
num_common_prefix_blocks=[0],
|
||||
finished_req_ids=set(),
|
||||
free_encoder_mm_hashes=[],
|
||||
)
|
||||
|
||||
engine_core_outputs = scheduler.update_from_output(
|
||||
scheduler_output, model_output
|
||||
)
|
||||
|
||||
final_stats = next(
|
||||
iter(engine_core_outputs.values())
|
||||
).scheduler_stats.ec_connector_stats
|
||||
assert final_stats == expected_data
|
||||
|
||||
|
||||
def test_ec_connector_update_connector_output_called():
|
||||
"""Test that worker-side EC connector output is forwarded to the
|
||||
EC connector's update_connector_output hook."""
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Unit tests for the connector-agnostic EC connector metrics plumbing.
|
||||
|
||||
Covers only the base infra: no concrete connector type implements these
|
||||
hooks yet, so every assertion here is about the documented no-op defaults
|
||||
and the container contracts, mirroring the equivalent KV connector tests.
|
||||
"""
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.distributed.ec_transfer.ec_connector.base import ECConnectorRole
|
||||
from vllm.distributed.ec_transfer.ec_connector.example_connector import (
|
||||
ECExampleConnector,
|
||||
)
|
||||
from vllm.distributed.ec_transfer.ec_connector.metrics import (
|
||||
ECConnectorLogging,
|
||||
ECConnectorProm,
|
||||
ECConnectorStats,
|
||||
)
|
||||
from vllm.v1.outputs import ECConnectorOutput
|
||||
|
||||
pytestmark = pytest.mark.cpu_test
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def example_connector(tmp_path):
|
||||
config = Mock(spec=VllmConfig)
|
||||
config.ec_transfer_config = Mock()
|
||||
config.ec_transfer_config.get_from_extra_config = Mock(return_value=str(tmp_path))
|
||||
config.ec_transfer_config.is_ec_producer = True
|
||||
config.ec_transfer_config.is_ec_consumer = False
|
||||
return ECExampleConnector(vllm_config=config, role=ECConnectorRole.SCHEDULER)
|
||||
|
||||
|
||||
def test_base_stats_methods_raise_not_implemented():
|
||||
"""The base container has no aggregation logic of its own."""
|
||||
stats = ECConnectorStats()
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
stats.reset()
|
||||
with pytest.raises(NotImplementedError):
|
||||
stats.aggregate(stats)
|
||||
with pytest.raises(NotImplementedError):
|
||||
stats.reduce()
|
||||
with pytest.raises(NotImplementedError):
|
||||
stats.is_empty()
|
||||
|
||||
|
||||
def test_connector_hooks_default_to_none(example_connector):
|
||||
"""No connector type overrides these yet, so every hook is a no-op."""
|
||||
assert example_connector.get_ec_connector_stats() is None
|
||||
assert ECExampleConnector.build_ec_connector_stats() is None
|
||||
assert (
|
||||
ECExampleConnector.build_prom_metrics(
|
||||
vllm_config=Mock(spec=VllmConfig),
|
||||
metric_types={},
|
||||
labelnames=[],
|
||||
per_engine_labelvalues={},
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
|
||||
def test_ec_connector_output_is_empty_reflects_stats_field():
|
||||
output = ECConnectorOutput()
|
||||
assert output.is_empty()
|
||||
|
||||
output.ec_connector_stats = ECConnectorStats(data={"x": 1})
|
||||
assert not output.is_empty()
|
||||
|
||||
|
||||
def test_logging_and_prom_are_no_ops_without_ec_transfer_config():
|
||||
"""A normal run with no EC connector configured must stay silent."""
|
||||
logging = ECConnectorLogging(ec_transfer_config=None)
|
||||
logging.log() # Should not raise, nothing to log.
|
||||
|
||||
vllm_config = Mock(spec=VllmConfig)
|
||||
vllm_config.ec_transfer_config = None
|
||||
prom = ECConnectorProm(vllm_config, labelnames=[], per_engine_labelvalues={})
|
||||
assert prom.prom_metrics is None
|
||||
prom.observe({}) # Should not raise.
|
||||
@@ -5,6 +5,7 @@
|
||||
import pytest
|
||||
|
||||
from vllm.distributed.ec_transfer.ec_connector.base import ECConnectorWorkerMetadata
|
||||
from vllm.distributed.ec_transfer.ec_connector.metrics import ECConnectorStats
|
||||
from vllm.distributed.ec_transfer.ec_connector.utils import ECOutputAggregator
|
||||
from vllm.distributed.kv_transfer.kv_connector.utils import KVOutputAggregator
|
||||
from vllm.v1.outputs import (
|
||||
@@ -29,6 +30,16 @@ class FakeWorkerMeta(ECConnectorWorkerMetadata):
|
||||
return FakeWorkerMeta(self.saves + other.saves)
|
||||
|
||||
|
||||
class FakeConnectorStats(ECConnectorStats):
|
||||
"""Records merge order, mirroring FakeWorkerMeta above."""
|
||||
|
||||
def __init__(self, saves: list[str]):
|
||||
self.saves = saves
|
||||
|
||||
def aggregate(self, other: "FakeConnectorStats") -> "FakeConnectorStats":
|
||||
return FakeConnectorStats(self.saves + other.saves)
|
||||
|
||||
|
||||
def _worker_output(ec_output: ECConnectorOutput | None) -> ModelRunnerOutput:
|
||||
return ModelRunnerOutput(
|
||||
req_ids=[], req_id_to_index={}, ec_connector_output=ec_output
|
||||
@@ -38,19 +49,23 @@ def _worker_output(ec_output: ECConnectorOutput | None) -> ModelRunnerOutput:
|
||||
def test_aggregate_folds_every_rank_onto_output_rank():
|
||||
"""EC work done on any rank reaches the scheduler via output_rank's output.
|
||||
|
||||
The middle rank reports no worker metadata: it must neither seed nor clobber
|
||||
the accumulator.
|
||||
The middle rank reports no worker metadata or stats: it must neither seed
|
||||
nor clobber either accumulator.
|
||||
"""
|
||||
outputs = [
|
||||
_worker_output(
|
||||
ECConnectorOutput(
|
||||
finished_sending={"mm0"},
|
||||
ec_connector_stats=FakeConnectorStats(["mm0"]),
|
||||
ec_connector_worker_meta=FakeWorkerMeta(["mm0"]),
|
||||
)
|
||||
),
|
||||
_worker_output(ECConnectorOutput(finished_recving={"mm1"})),
|
||||
_worker_output(
|
||||
ECConnectorOutput(ec_connector_worker_meta=FakeWorkerMeta(["mm2"]))
|
||||
ECConnectorOutput(
|
||||
ec_connector_stats=FakeConnectorStats(["mm2"]),
|
||||
ec_connector_worker_meta=FakeWorkerMeta(["mm2"]),
|
||||
)
|
||||
),
|
||||
]
|
||||
|
||||
@@ -59,6 +74,7 @@ def test_aggregate_folds_every_rank_onto_output_rank():
|
||||
assert result is outputs[2]
|
||||
assert result.ec_connector_output.finished_sending == {"mm0"}
|
||||
assert result.ec_connector_output.finished_recving == {"mm1"}
|
||||
assert result.ec_connector_output.ec_connector_stats.saves == ["mm0", "mm2"]
|
||||
assert result.ec_connector_output.ec_connector_worker_meta.saves == ["mm0", "mm2"]
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ from vllm.v1.worker.gpu.ec_connector import NO_OP_EC_CONNECTOR, ActiveECConnecto
|
||||
pytestmark = pytest.mark.cpu_test
|
||||
|
||||
WORKER_META = object()
|
||||
CONNECTOR_STATS = object()
|
||||
|
||||
|
||||
def _scheduler_output() -> SimpleNamespace:
|
||||
@@ -38,6 +39,7 @@ def _connector(
|
||||
fake.is_consumer = is_consumer
|
||||
fake.get_finished.return_value = (None, None)
|
||||
fake.build_connector_worker_meta.return_value = WORKER_META
|
||||
fake.get_ec_connector_stats.return_value = CONNECTOR_STATS
|
||||
with patch("vllm.v1.worker.gpu.ec_connector.get_ec_transfer", return_value=fake):
|
||||
return ActiveECConnector(SimpleNamespace(), encoder_cache or {}), fake
|
||||
|
||||
@@ -72,6 +74,16 @@ def test_worker_meta_is_reported_on_context_exit():
|
||||
assert fake.clear_connector_metadata.called
|
||||
|
||||
|
||||
def test_connector_stats_are_reported_on_context_exit():
|
||||
"""Reported in the finally block, alongside the worker meta."""
|
||||
connector, fake = _connector()
|
||||
|
||||
with connector.maybe_get_output(_scheduler_output()) as output:
|
||||
assert output.ec_connector_stats is None
|
||||
|
||||
assert output.ec_connector_stats is CONNECTOR_STATS
|
||||
|
||||
|
||||
def test_v1_producer_receives_existing_encoder_cache():
|
||||
encoder_cache = {"mm_cached": None}
|
||||
fake = MagicMock(spec=ECConnectorBase)
|
||||
|
||||
@@ -1452,3 +1452,41 @@ def test_engine_core_proc_instantiation_cuda_empty(monkeypatch: pytest.MonkeyPat
|
||||
)
|
||||
|
||||
engine_core_proc.shutdown()
|
||||
|
||||
|
||||
def _ready_response_with_weight_transfer(weight_transfer_config):
|
||||
"""Build a ready response against a mock executor."""
|
||||
from vllm.v1.engine.core import EngineCoreProc
|
||||
|
||||
executor = MagicMock()
|
||||
executor.supports_draft_weight_updates.return_value = True
|
||||
|
||||
proc = MagicMock()
|
||||
proc.model_executor = executor
|
||||
proc.vllm_config = MagicMock()
|
||||
proc.vllm_config.weight_transfer_config = weight_transfer_config
|
||||
proc.vllm_config.lora_config = None
|
||||
proc.vllm_config.model_config.enable_sleep_mode = False
|
||||
proc.scheduler = MagicMock()
|
||||
|
||||
response = EngineCoreProc._make_ready_response(proc)
|
||||
return response, executor
|
||||
|
||||
|
||||
def test_ready_response_skips_draft_rpc_without_weight_transfer():
|
||||
"""No weight-transfer config: the executor must not be consulted."""
|
||||
response, executor = _ready_response_with_weight_transfer(None)
|
||||
|
||||
executor.supports_draft_weight_updates.assert_not_called()
|
||||
assert response.supports_draft_weight_updates is False
|
||||
|
||||
|
||||
def test_ready_response_queries_executor_with_weight_transfer():
|
||||
"""Weight transfer configured: the executor is still consulted."""
|
||||
weight_transfer_config = MagicMock()
|
||||
weight_transfer_config.backend = "nixl"
|
||||
|
||||
response, executor = _ready_response_with_weight_transfer(weight_transfer_config)
|
||||
|
||||
executor.supports_draft_weight_updates.assert_called_once()
|
||||
assert response.supports_draft_weight_updates is True
|
||||
|
||||
@@ -17,6 +17,7 @@ from vllm.distributed.kv_transfer.kv_connector.v1.offloading.scheduler import (
|
||||
SchedulerOffloadConfig,
|
||||
)
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.v1.core.kv_cache_utils import generate_scheduler_kv_cache_config
|
||||
from vllm.v1.kv_cache_interface import (
|
||||
FullAttentionSpec,
|
||||
HiddenStateCacheSpec,
|
||||
@@ -32,6 +33,8 @@ from vllm.v1.kv_cache_interface import (
|
||||
UniformTypeKVCacheSpecs,
|
||||
)
|
||||
from vllm.v1.kv_cache_spec_registry import KVCacheSpecRegistry
|
||||
from vllm.v1.kv_offload.file_mapper import FileMapper
|
||||
from vllm.v1.kv_offload.tiering.spec import TieringOffloadingSpec
|
||||
|
||||
|
||||
def _make_vllm_config(
|
||||
@@ -876,6 +879,43 @@ def test_canonical_layout_certifies_v2_model_runner():
|
||||
assert _parallelism_agnostic(groups, canonical=True, v2=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tp_size", [1, 2, 4])
|
||||
@pytest.mark.parametrize("scheduler", [False, True])
|
||||
def test_canonical_mla_dsa_rows_are_tp_independent(tp_size, scheduler):
|
||||
specs = {
|
||||
f"l{i}": _mla_spec(block_size=64, head_size=size, dtype=torch.uint8)
|
||||
for i, size in enumerate([656] * 4 + [132] * 3)
|
||||
}
|
||||
uniform = UniformTypeKVCacheSpecs(block_size=64, kv_cache_specs=specs)
|
||||
kv_cache_config = KVCacheConfig(
|
||||
num_blocks=4,
|
||||
kv_cache_tensors=[
|
||||
KVCacheTensor(
|
||||
size=4 * uniform.page_size_bytes,
|
||||
layers=list(specs),
|
||||
layer_stride=0,
|
||||
block_stride=uniform.page_size_bytes,
|
||||
)
|
||||
],
|
||||
kv_cache_groups=[KVCacheGroupSpec(list(specs), uniform)],
|
||||
)
|
||||
if scheduler:
|
||||
kv_cache_config = generate_scheduler_kv_cache_config([kv_cache_config])
|
||||
config = _make_vllm_config(
|
||||
tensor_parallel_size=tp_size,
|
||||
extra_config={"canonical_layout": True, "cpu_bytes_to_use": 196608 * 8},
|
||||
)
|
||||
config.cache_config.kv_cache_layout = "LBHNC"
|
||||
config.parallel_config.distributed_executor_backend = "mp"
|
||||
offloading_config = build_offloading_config(config, kv_cache_config)
|
||||
spec = TieringOffloadingSpec(offloading_config)
|
||||
assert spec.kv_bytes_per_chunk == 196608
|
||||
assert spec.num_chunks == 8
|
||||
mapper = FileMapper.from_offloading_spec("/cache", spec, parallel_agnostic=True)
|
||||
assert mapper.get_run_config()["tp_size"] == 1
|
||||
assert mapper.get_run_config()["replicated_layout"] is True
|
||||
|
||||
|
||||
def test_parallelism_agnostic_disabled_on_v2_model_runner():
|
||||
config = _make_vllm_config()
|
||||
config.use_v2_model_runner = True
|
||||
|
||||
@@ -97,6 +97,7 @@ def _make_worker(
|
||||
kv_cache_config: KVCacheConfig,
|
||||
replicated_layout: bool = False,
|
||||
rank: int = 0,
|
||||
canonical_layout: bool = False,
|
||||
):
|
||||
"""Create an OffloadingConnectorWorker with mocked dependencies."""
|
||||
from vllm.distributed.kv_transfer.kv_connector.v1.offloading.worker import (
|
||||
@@ -106,6 +107,7 @@ def _make_worker(
|
||||
spec = MagicMock(spec=OffloadingSpec)
|
||||
spec.replicated_layout = replicated_layout
|
||||
spec.config = MagicMock()
|
||||
spec.config.canonical_layout = canonical_layout
|
||||
spec.config.parallel.rank = rank
|
||||
spec.get_worker.return_value = MagicMock()
|
||||
|
||||
@@ -204,11 +206,13 @@ def test_prepare_store_kv_non_writer_marks_completed_without_submit():
|
||||
assert meta.completed_jobs == {7: 1}
|
||||
|
||||
|
||||
def test_prepare_store_kv_writer_submits_store():
|
||||
@pytest.mark.parametrize("rank,canonical_layout", [(0, False), (0, True), (1, True)])
|
||||
def test_prepare_store_kv_writer_submits_store(rank, canonical_layout):
|
||||
worker, _ = _make_worker(
|
||||
KVCacheConfig(num_blocks=0, kv_cache_tensors=[], kv_cache_groups=[]),
|
||||
replicated_layout=True,
|
||||
rank=0,
|
||||
rank=rank,
|
||||
canonical_layout=canonical_layout,
|
||||
)
|
||||
|
||||
worker.prepare_store_kv(_store_metadata(8))
|
||||
|
||||
Reference in New Issue
Block a user