-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[Core] Enable command line logging for LLMEngine #25610
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import time | ||||||||||||||||||||||||||||||
| from collections.abc import Mapping | ||||||||||||||||||||||||||||||
| from copy import copy | ||||||||||||||||||||||||||||||
| from typing import Any, Callable, Optional, Union | ||||||||||||||||||||||||||||||
|
|
@@ -31,8 +32,7 @@ | |||||||||||||||||||||||||||||
| from vllm.v1.engine.parallel_sampling import ParentRequest | ||||||||||||||||||||||||||||||
| from vllm.v1.engine.processor import Processor | ||||||||||||||||||||||||||||||
| from vllm.v1.executor.abstract import Executor | ||||||||||||||||||||||||||||||
| from vllm.v1.metrics.loggers import (PrometheusStatLogger, StatLoggerBase, | ||||||||||||||||||||||||||||||
| StatLoggerFactory) | ||||||||||||||||||||||||||||||
| from vllm.v1.metrics.loggers import StatLoggerFactory, StatLoggerManager | ||||||||||||||||||||||||||||||
| from vllm.v1.metrics.reader import Metric, get_metrics_snapshot | ||||||||||||||||||||||||||||||
| from vllm.v1.metrics.stats import IterationStats | ||||||||||||||||||||||||||||||
| from vllm.v1.worker.worker_base import WorkerBase | ||||||||||||||||||||||||||||||
|
|
@@ -74,9 +74,6 @@ def __init__( | |||||||||||||||||||||||||||||
| self.cache_config = vllm_config.cache_config | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| self.log_stats = log_stats | ||||||||||||||||||||||||||||||
| self.stat_logger: Optional[StatLoggerBase] = None | ||||||||||||||||||||||||||||||
| if self.log_stats: | ||||||||||||||||||||||||||||||
| self.stat_logger = PrometheusStatLogger(vllm_config) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| executor_backend = ( | ||||||||||||||||||||||||||||||
| self.vllm_config.parallel_config.distributed_executor_backend) | ||||||||||||||||||||||||||||||
|
|
@@ -122,6 +119,15 @@ def __init__( | |||||||||||||||||||||||||||||
| log_stats=self.log_stats, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| self.logger_manager: Optional[StatLoggerManager] = None | ||||||||||||||||||||||||||||||
| if self.log_stats: | ||||||||||||||||||||||||||||||
| self.logger_manager = StatLoggerManager( | ||||||||||||||||||||||||||||||
| vllm_config=vllm_config, | ||||||||||||||||||||||||||||||
| custom_stat_loggers=stat_loggers, | ||||||||||||||||||||||||||||||
| enable_default_loggers=log_stats, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| self.logger_manager.log_engine_initialized() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if not multiprocess_mode: | ||||||||||||||||||||||||||||||
| # for v0 compatibility | ||||||||||||||||||||||||||||||
| self.model_executor = self.engine_core.engine_core.model_executor # type: ignore | ||||||||||||||||||||||||||||||
|
|
@@ -269,10 +275,13 @@ def step(self) -> Union[list[RequestOutput], list[PoolingRequestOutput]]: | |||||||||||||||||||||||||||||
| self.engine_core.abort_requests(processed_outputs.reqs_to_abort) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # 4) Record stats | ||||||||||||||||||||||||||||||
| if self.stat_logger is not None: | ||||||||||||||||||||||||||||||
| if self.logger_manager is not None: | ||||||||||||||||||||||||||||||
| assert outputs.scheduler_stats is not None | ||||||||||||||||||||||||||||||
| self.stat_logger.record(scheduler_stats=outputs.scheduler_stats, | ||||||||||||||||||||||||||||||
| iteration_stats=iteration_stats) | ||||||||||||||||||||||||||||||
| self.logger_manager.record( | ||||||||||||||||||||||||||||||
| scheduler_stats=outputs.scheduler_stats, | ||||||||||||||||||||||||||||||
| iteration_stats=iteration_stats, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| self.do_log_stats_with_interval() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return processed_outputs.request_outputs | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -315,6 +324,20 @@ def get_tokenizer(self) -> AnyTokenizer: | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return self.tokenizer | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def do_log_stats(self) -> None: | ||||||||||||||||||||||||||||||
| """Log stats if logging is enabled.""" | ||||||||||||||||||||||||||||||
| if self.logger_manager: | ||||||||||||||||||||||||||||||
| self.logger_manager.log() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def do_log_stats_with_interval(self) -> None: | ||||||||||||||||||||||||||||||
| """Log stats when the time interval has passed.""" | ||||||||||||||||||||||||||||||
| now = time.time() | ||||||||||||||||||||||||||||||
| if not hasattr(self, "_last_log_time"): | ||||||||||||||||||||||||||||||
| self._last_log_time = now | ||||||||||||||||||||||||||||||
| if now - self._last_log_time >= envs.VLLM_LOG_STATS_INTERVAL: | ||||||||||||||||||||||||||||||
| self.do_log_stats() | ||||||||||||||||||||||||||||||
| self._last_log_time = now | ||||||||||||||||||||||||||||||
|
Comment on lines
+332
to
+339
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def add_lora(self, lora_request: LoRARequest) -> bool: | ||||||||||||||||||||||||||||||
| """Load a new LoRA adapter into the engine for future requests.""" | ||||||||||||||||||||||||||||||
| return self.engine_core.add_lora(lora_request) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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
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.
For better code clarity and to ensure all instance attributes are initialized in one place, it's recommended to initialize
_last_log_timehere within theif self.log_stats:block. This avoids lazy initialization in thedo_log_stats_with_intervalmethod, makes the class's attributes more explicit, and improves overall maintainability.