mirror of
https://github.com/vllm-project/vllm.git
synced 2026-06-06 00:16:14 +00:00
[Deprecation] Deprecate functions as scheduled for v0.21.0 (#43358)
Signed-off-by: yewentao256 <zhyanwentao@126.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
@@ -201,43 +201,45 @@ The profiling traces generated by the continuous profiling workflow are publicly
|
||||
|
||||
The Python standard library includes
|
||||
[cProfile](https://docs.python.org/3/library/profile.html) for profiling Python
|
||||
code. vLLM includes a couple of helpers that make it easy to apply it to a section of vLLM.
|
||||
Both the `vllm.utils.profiling.cprofile` and `vllm.utils.profiling.cprofile_context` functions can be
|
||||
used to profile a section of code.
|
||||
code.
|
||||
|
||||
!!! note
|
||||
The `vllm.utils.profiling` helpers are deprecated and will be removed in
|
||||
`v0.21`. Please use Python's `cProfile` module directly instead.
|
||||
### Example usage - function call
|
||||
|
||||
### Example usage - decorator
|
||||
|
||||
The first helper is a Python decorator that can be used to profile a function.
|
||||
If a filename is specified, the profile will be saved to that file. If no filename is
|
||||
specified, profile data will be printed to stdout.
|
||||
If a filename is specified, the profile will be saved to that file. If no
|
||||
filename is specified, profile data can be printed to stdout.
|
||||
|
||||
```python
|
||||
from vllm.utils.profiling import cprofile
|
||||
import cProfile
|
||||
|
||||
|
||||
@cprofile("expensive_function.prof")
|
||||
def expensive_function():
|
||||
# some expensive code
|
||||
pass
|
||||
|
||||
|
||||
profiler = cProfile.Profile()
|
||||
profiler.runcall(expensive_function)
|
||||
profiler.dump_stats("expensive_function.prof")
|
||||
```
|
||||
|
||||
### Example Usage - context manager
|
||||
|
||||
The second helper is a context manager that can be used to profile a block of
|
||||
code. Similar to the decorator, the filename is optional.
|
||||
### Example usage - context manager style
|
||||
|
||||
```python
|
||||
from vllm.utils.profiling import cprofile_context
|
||||
import cProfile
|
||||
|
||||
|
||||
def another_function():
|
||||
# more expensive code
|
||||
pass
|
||||
|
||||
with cprofile_context("another_function.prof"):
|
||||
|
||||
profiler = cProfile.Profile()
|
||||
profiler.enable()
|
||||
try:
|
||||
another_function()
|
||||
finally:
|
||||
profiler.disable()
|
||||
profiler.dump_stats("another_function.prof")
|
||||
```
|
||||
|
||||
### Analyzing Profile Results
|
||||
|
||||
@@ -299,7 +299,3 @@ Example configuration:
|
||||
### Remove softmax from PoolingParams
|
||||
|
||||
We have already removed `softmax` and `activation` from PoolingParams. Instead, use `use_activation`, since we allow `classify` and `token_classify` to use any activation function.
|
||||
|
||||
### Remove `logit_bias` and `logit_scale`
|
||||
|
||||
`logit_bias` and `logit_scale` are deprecated aliases for `logit_mean` and `logit_sigma` respectively. When using `logit_scale`, it is automatically converted to `logit_sigma = 1/logit_scale`. These deprecated parameters will be removed in v0.21.
|
||||
|
||||
@@ -92,18 +92,6 @@ class PoolerConfig:
|
||||
activation((logit - logit_mean) / logit_sigma). Defaults to None.
|
||||
"""
|
||||
|
||||
# Deprecated aliases — will be removed in v0.21
|
||||
logit_bias: float | None = None
|
||||
"""
|
||||
Deprecated: Use logit_mean instead. Will be removed in v0.21.
|
||||
"""
|
||||
|
||||
logit_scale: float | None = None
|
||||
"""
|
||||
Deprecated: Use logit_sigma instead (note: logit_sigma = 1/logit_scale).
|
||||
Will be removed in v0.21.
|
||||
"""
|
||||
|
||||
## for reward models
|
||||
step_tag_id: int | None = None
|
||||
"""
|
||||
@@ -119,36 +107,6 @@ class PoolerConfig:
|
||||
"""
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
# Handle deprecated logit_bias → logit_mean
|
||||
if self.logit_bias is not None:
|
||||
if self.logit_mean is not None:
|
||||
raise ValueError(
|
||||
"Cannot set both `logit_bias` and `logit_mean`. "
|
||||
"`logit_bias` is deprecated, use `logit_mean` instead."
|
||||
)
|
||||
logger.warning(
|
||||
"`logit_bias` is deprecated and will be removed in v0.21. "
|
||||
"Use `logit_mean` instead."
|
||||
)
|
||||
self.logit_mean = self.logit_bias
|
||||
self.logit_bias = None
|
||||
|
||||
# Handle deprecated logit_scale → logit_sigma
|
||||
if self.logit_scale is not None:
|
||||
if self.logit_sigma is not None:
|
||||
raise ValueError(
|
||||
"Cannot set both `logit_scale` and `logit_sigma`. "
|
||||
"`logit_scale` is deprecated, use `logit_sigma` instead."
|
||||
)
|
||||
logger.warning(
|
||||
"`logit_scale` is deprecated and will be removed in v0.21. "
|
||||
"Use `logit_sigma` instead (logit_sigma = 1/logit_scale)."
|
||||
)
|
||||
if self.logit_scale == 0:
|
||||
raise ValueError("logit_scale cannot be 0 (division by zero)")
|
||||
self.logit_sigma = 1.0 / self.logit_scale
|
||||
self.logit_scale = None
|
||||
|
||||
if self.logit_sigma is not None and self.logit_sigma == 0:
|
||||
raise ValueError("logit_sigma cannot be 0 (division by zero)")
|
||||
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
from collections.abc import Callable
|
||||
from functools import wraps
|
||||
from typing import Any
|
||||
|
||||
from typing_extensions import deprecated
|
||||
|
||||
|
||||
@deprecated(
|
||||
"vllm.utils.profiling.cprofile_context() is deprecated and will be removed "
|
||||
"in v0.21. Use Python's cProfile module directly instead."
|
||||
)
|
||||
@contextlib.contextmanager
|
||||
def cprofile_context(save_file: str | None = None):
|
||||
"""Run a cprofile
|
||||
|
||||
Args:
|
||||
save_file: path to save the profile result. "1" or
|
||||
None will result in printing to stdout.
|
||||
"""
|
||||
import cProfile
|
||||
|
||||
prof = cProfile.Profile()
|
||||
prof.enable()
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
prof.disable()
|
||||
if save_file and save_file != "1":
|
||||
prof.dump_stats(save_file)
|
||||
else:
|
||||
prof.print_stats(sort="cumtime")
|
||||
|
||||
|
||||
@deprecated(
|
||||
"vllm.utils.profiling.cprofile() is deprecated and will be removed in "
|
||||
"v0.21. Use Python's cProfile module directly instead."
|
||||
)
|
||||
def cprofile(save_file: str | None = None, enabled: bool = True):
|
||||
"""Decorator to profile a Python method using cProfile.
|
||||
|
||||
Args:
|
||||
save_file: Path to save the profile result.
|
||||
If "1", None, or "", results will be printed to stdout.
|
||||
enabled: Set to false to turn this into a no-op
|
||||
"""
|
||||
|
||||
def decorator(func: Callable):
|
||||
@wraps(func)
|
||||
def wrapper(*args: Any, **kwargs: Any):
|
||||
if not enabled:
|
||||
# If profiling is disabled, just call the function directly.
|
||||
return func(*args, **kwargs)
|
||||
|
||||
with cprofile_context(save_file):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
Reference in New Issue
Block a user