-
Notifications
You must be signed in to change notification settings - Fork 309
[train] Enable RayPrometheusStatLogger for async vLLM engine #900
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
CharlieFRuan
merged 4 commits into
NovaSky-AI:main
from
DataDog:kanwang/ray-metrics-collector
Jan 26, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ac8721e
[train] Enable RayPrometheusStatLogger for async vLLM engine
kanwang 6213a78
Update skyrl-train/skyrl_train/inference_engines/vllm/vllm_engine.py
kanwang 34cee4b
Add test for RayPrometheusStatLogger import failure scenario
kanwang 78952e9
fix format
kanwang 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
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
Empty file.
Empty file.
103 changes: 103 additions & 0 deletions
103
skyrl-train/tests/cpu/inf_engines/vllm/test_ray_prometheus_stats.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,103 @@ | ||
| """ | ||
| Test for RayPrometheusStatLogger integration in the vLLM engine. | ||
|
|
||
| Run with: | ||
| uv run --isolated --extra dev pytest tests/cpu/inf_engines/vllm/test_ray_prometheus_stats.py | ||
| """ | ||
|
|
||
| from unittest.mock import patch, MagicMock | ||
| import sys | ||
|
|
||
|
|
||
| class TestRayPrometheusStatLoggers: | ||
| """Test cases for _create_ray_prometheus_stat_loggers method.""" | ||
|
|
||
| def test_create_ray_prometheus_stat_loggers_v1_available(self): | ||
| """Test that RayPrometheusStatLogger is returned when vLLM v1 API is available.""" | ||
| # Create a mock for the v1 RayPrometheusStatLogger | ||
| mock_stat_logger = MagicMock() | ||
| mock_stat_logger.__name__ = "RayPrometheusStatLogger" | ||
|
|
||
| mock_ray_wrappers = MagicMock() | ||
| mock_ray_wrappers.RayPrometheusStatLogger = mock_stat_logger | ||
|
|
||
| # Patch the import to return our mock | ||
| with patch.dict(sys.modules, {"vllm.v1.metrics.ray_wrappers": mock_ray_wrappers}): | ||
| from skyrl_train.inference_engines.vllm.vllm_engine import AsyncVLLMInferenceEngine | ||
|
|
||
| # Create a minimal instance without actually initializing the engine | ||
| engine = object.__new__(AsyncVLLMInferenceEngine) | ||
|
|
||
| result = engine._create_ray_prometheus_stat_loggers() | ||
|
|
||
| # Should return a list with the stat logger class | ||
| assert result is not None | ||
| assert isinstance(result, list) | ||
| assert len(result) == 1 | ||
| assert result[0] == mock_stat_logger | ||
|
|
||
| def test_create_ray_prometheus_stat_loggers_v1_unavailable(self): | ||
| """Test that None is returned when vLLM v1 API is not available.""" | ||
| # By setting the module to None in sys.modules, the import will fail. | ||
| with patch.dict(sys.modules, {"vllm.v1.metrics.ray_wrappers": None}): | ||
| from skyrl_train.inference_engines.vllm.vllm_engine import AsyncVLLMInferenceEngine | ||
|
|
||
| # Create a minimal instance without actually initializing the engine | ||
| engine = object.__new__(AsyncVLLMInferenceEngine) | ||
|
|
||
| with patch("skyrl_train.inference_engines.vllm.vllm_engine.logger") as mock_logger: | ||
| result = engine._create_ray_prometheus_stat_loggers() | ||
|
|
||
| assert result is None | ||
| mock_logger.warning.assert_called_once() | ||
| assert "not available in this vLLM version" in mock_logger.warning.call_args[0][0] | ||
|
|
||
|
|
||
| class TestConfigIntegration: | ||
| """Test that configuration flows correctly through the stack.""" | ||
|
|
||
| def test_config_default_value(self): | ||
| """Test that enable_ray_prometheus_stats defaults to False in config.""" | ||
| from omegaconf import OmegaConf | ||
|
|
||
| # Load the base config | ||
| config_content = """ | ||
| generator: | ||
| enable_ray_prometheus_stats: false | ||
| """ | ||
| cfg = OmegaConf.create(config_content) | ||
| assert cfg.generator.enable_ray_prometheus_stats is False | ||
|
|
||
| def test_config_can_be_enabled(self): | ||
| """Test that enable_ray_prometheus_stats can be set to True.""" | ||
| from omegaconf import OmegaConf | ||
|
|
||
| config_content = """ | ||
| generator: | ||
| enable_ray_prometheus_stats: true | ||
| """ | ||
| cfg = OmegaConf.create(config_content) | ||
| assert cfg.generator.enable_ray_prometheus_stats is True | ||
|
|
||
|
|
||
| class TestKwargsHandling: | ||
| """Test that enable_ray_prometheus_stats is properly handled in kwargs.""" | ||
|
|
||
| def test_enable_ray_prometheus_stats_popped_from_kwargs(self): | ||
| """Test that enable_ray_prometheus_stats is properly popped from kwargs.""" | ||
| # This test verifies the configuration flows correctly | ||
| kwargs = {"enable_ray_prometheus_stats": True, "other_param": "value"} | ||
|
|
||
| # Pop should remove it from kwargs (same logic as in _create_engine) | ||
| enable_stats = kwargs.pop("enable_ray_prometheus_stats", False) | ||
| assert enable_stats is True | ||
| assert "enable_ray_prometheus_stats" not in kwargs | ||
| assert kwargs == {"other_param": "value"} | ||
|
|
||
| def test_enable_ray_prometheus_stats_defaults_to_false(self): | ||
| """Test that enable_ray_prometheus_stats defaults to False when not present.""" | ||
| kwargs = {"other_param": "value"} | ||
|
|
||
| enable_stats = kwargs.pop("enable_ray_prometheus_stats", False) | ||
| assert enable_stats is False | ||
| assert kwargs == {"other_param": "value"} | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great that you've added tests for the success case. To make the tests more robust, consider adding a test case for the failure scenario where
RayPrometheusStatLoggercannot be imported (e.g., on older vLLM versions). This would verify that the method correctly returnsNoneand logs a warning.You could add a test like this to
TestRayPrometheusStatLoggers: