Repository navigation
feat(vllm): gate chat-shaped Prometheus collectors on embedding worker #9886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
956bef3
feat(vllm): gate chat-shaped Prometheus collectors on embedding worker
tzulingk 2fe2905
fix(vllm): guard model_load_time gauge + give _NoopStatLogger explici…
tzulingk 6528b5c
fix(vllm): address review comments on per-worker metric gating
tzulingk 9e89c41
chore(vllm): drop internal ticket id from model_load_time guard comment
tzulingk 40a1aa0
chore(vllm): make NoopStatLogger public for reuse
tzulingk e69b133
chore(vllm): isort fix for test_vllm_publisher import block
tzulingk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
components/src/dynamo/vllm/tests/test_vllm_publisher.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Unit tests for the vLLM stat-logger factory. | ||
|
|
||
| These tests focus on the embedding-worker gating path: vLLM workers run | ||
| either a chat/decode engine or a pooling (embedding) engine, and the | ||
| chat-shaped Prometheus collectors are only meaningful on the former. | ||
| The factory is the single seam where vLLM calls into dynamo per dp_rank, | ||
| so it is also the seam where the embedding worker must short-circuit | ||
| the chat-shaped pipeline. | ||
| """ | ||
|
|
||
| from types import SimpleNamespace | ||
| from unittest.mock import Mock | ||
|
|
||
| import pytest | ||
|
|
||
| import dynamo.vllm.publisher as publisher_mod | ||
| from dynamo.vllm.publisher import ( | ||
| DynamoStatLoggerPublisher, | ||
| StatLoggerFactory, | ||
| _NoopStatLogger, | ||
| ) | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.unit, | ||
| pytest.mark.vllm, | ||
| pytest.mark.core, | ||
| pytest.mark.gpu_0, | ||
| pytest.mark.pre_merge, | ||
| ] | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| def test_factory_returns_noop_logger_for_embedding_worker(monkeypatch): | ||
| """``create_stat_logger`` returns a ``_NoopStatLogger`` on the | ||
| embedding path -- no ``DynamoStatLoggerPublisher`` / | ||
| ``WorkerMetricsPublisher`` / NATS endpoint construction. | ||
|
|
||
| Why this matters: ``DynamoStatLoggerPublisher.__init__`` schedules a | ||
| ``create_endpoint`` task on the runtime and registers chat-shaped | ||
| publish callbacks. On a pooling engine there is no kv_cache_usage to | ||
| publish (vLLM never emits ``SchedulerStats``) and the endpoint is | ||
| never queried -- so the factory must not construct it at all. | ||
| """ | ||
|
|
||
| def _explode(*_a, **_kw): | ||
| raise AssertionError( | ||
| "embedding-worker path must not construct DynamoStatLoggerPublisher" | ||
| ) | ||
|
|
||
| monkeypatch.setattr(publisher_mod, "DynamoStatLoggerPublisher", _explode) | ||
|
|
||
| factory = StatLoggerFactory( | ||
| endpoint=SimpleNamespace(), | ||
| embedding_worker=True, | ||
| ) | ||
|
|
||
| logger = factory.create_stat_logger(dp_rank=0) | ||
|
|
||
| assert isinstance(logger, _NoopStatLogger) | ||
| # Embedding factory never tracks a created chat logger, so the | ||
| # downstream ``init_publish`` / ``set_num_gpu_blocks_all`` calls in | ||
| # the chat path are safe no-ops if anyone ever wires them on the | ||
| # embedding branch by mistake. | ||
| assert factory.created_logger is None | ||
|
|
||
|
|
||
| def test_noop_stat_logger_record_is_safe_with_none_stats(): | ||
| """vLLM calls ``record`` every iteration even when the engine has | ||
| nothing useful to report. The chat-path publisher returns early on | ||
| ``scheduler_stats is None``; the embedding noop must accept the same | ||
| shape (and the variadic mm/engine_idx args vLLM passes) without | ||
| raising.""" | ||
| logger = _NoopStatLogger() | ||
|
|
||
| # Mirrors the call shape from vllm/v1/metrics/loggers.py. | ||
| logger.record(None, None) | ||
| logger.record(None, None, None, 0) | ||
| logger.record( | ||
| scheduler_stats=None, | ||
| iteration_stats=None, | ||
| mm_cache_stats=None, | ||
| engine_idx=0, | ||
| ) | ||
| logger.log_engine_initialized() | ||
|
|
||
|
|
||
| def test_factory_embedding_flag_skips_component_gauges_assert(): | ||
| """On the chat path the factory asserts | ||
| ``component_gauges is not None`` because ``setup_vllm_engine`` is | ||
| responsible for setting it before vLLM invokes the factory. The | ||
| embedding path skips that step entirely (no chat-shaped gauges to | ||
| register), so the factory must not blow up when it stays None.""" | ||
| factory = StatLoggerFactory( | ||
| endpoint=SimpleNamespace(), | ||
| embedding_worker=True, | ||
| ) | ||
| assert factory.component_gauges is None | ||
|
|
||
| # Would AssertionError on the chat path; must succeed here. | ||
| logger = factory.create_stat_logger(dp_rank=0) | ||
| assert isinstance(logger, _NoopStatLogger) | ||
|
|
||
|
|
||
| def test_factory_default_is_chat_path(monkeypatch): | ||
| """Sibling check: the default (``embedding_worker=False``) still | ||
| constructs ``DynamoStatLoggerPublisher`` so the gating doesn't | ||
| accidentally swallow the chat path.""" | ||
| constructed = [] | ||
|
|
||
| def _fake_publisher(*args, **kwargs): | ||
| constructed.append(kwargs) | ||
| return Mock(spec=DynamoStatLoggerPublisher) | ||
|
|
||
| monkeypatch.setattr(publisher_mod, "DynamoStatLoggerPublisher", _fake_publisher) | ||
|
|
||
| endpoint = SimpleNamespace() | ||
| component_gauges = SimpleNamespace() | ||
| factory = StatLoggerFactory(endpoint=endpoint, component_gauges=component_gauges) | ||
|
|
||
| factory.create_stat_logger(dp_rank=3) | ||
|
|
||
| assert len(constructed) == 1 | ||
| assert constructed[0]["endpoint"] is endpoint | ||
| assert constructed[0]["dp_rank"] == 3 | ||
| assert constructed[0]["component_gauges"] is component_gauges | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.