[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:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
aa6138169f
commit
c02c758ea4
@@ -201,43 +201,45 @@ The profiling traces generated by the continuous profiling workflow are publicly
|
|||||||
|
|
||||||
The Python standard library includes
|
The Python standard library includes
|
||||||
[cProfile](https://docs.python.org/3/library/profile.html) for profiling Python
|
[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.
|
code.
|
||||||
Both the `vllm.utils.profiling.cprofile` and `vllm.utils.profiling.cprofile_context` functions can be
|
|
||||||
used to profile a section of code.
|
|
||||||
|
|
||||||
!!! note
|
### Example usage - function call
|
||||||
The `vllm.utils.profiling` helpers are deprecated and will be removed in
|
|
||||||
`v0.21`. Please use Python's `cProfile` module directly instead.
|
|
||||||
|
|
||||||
### Example usage - decorator
|
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.
|
||||||
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.
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from vllm.utils.profiling import cprofile
|
import cProfile
|
||||||
|
|
||||||
|
|
||||||
@cprofile("expensive_function.prof")
|
|
||||||
def expensive_function():
|
def expensive_function():
|
||||||
# some expensive code
|
# some expensive code
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
profiler = cProfile.Profile()
|
||||||
|
profiler.runcall(expensive_function)
|
||||||
|
profiler.dump_stats("expensive_function.prof")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example Usage - context manager
|
### Example usage - context manager style
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from vllm.utils.profiling import cprofile_context
|
import cProfile
|
||||||
|
|
||||||
|
|
||||||
def another_function():
|
def another_function():
|
||||||
# more expensive code
|
# more expensive code
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with cprofile_context("another_function.prof"):
|
|
||||||
|
profiler = cProfile.Profile()
|
||||||
|
profiler.enable()
|
||||||
|
try:
|
||||||
another_function()
|
another_function()
|
||||||
|
finally:
|
||||||
|
profiler.disable()
|
||||||
|
profiler.dump_stats("another_function.prof")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Analyzing Profile Results
|
### Analyzing Profile Results
|
||||||
|
|||||||
@@ -299,7 +299,3 @@ Example configuration:
|
|||||||
### Remove softmax from PoolingParams
|
### 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.
|
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.
|
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
|
## for reward models
|
||||||
step_tag_id: int | None = None
|
step_tag_id: int | None = None
|
||||||
"""
|
"""
|
||||||
@@ -119,36 +107,6 @@ class PoolerConfig:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
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:
|
if self.logit_sigma is not None and self.logit_sigma == 0:
|
||||||
raise ValueError("logit_sigma cannot be 0 (division by zero)")
|
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