forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] add vllm_test_utils (vllm-project#10659)
Signed-off-by: youkaichao <youkaichao@gmail.com>
- Loading branch information
1 parent
9406353
commit 334d64d
Showing
14 changed files
with
113 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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,7 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='vllm_test_utils', | ||
version='0.1', | ||
packages=['vllm_test_utils'], | ||
) |
This file contains 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,8 @@ | ||
""" | ||
vllm_utils is a package for vLLM testing utilities. | ||
It does not import any vLLM modules. | ||
""" | ||
|
||
from .blame import BlameResult, blame | ||
|
||
__all__ = ["blame", "BlameResult"] |
This file contains 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,53 @@ | ||
import contextlib | ||
import dataclasses | ||
import sys | ||
import traceback | ||
from typing import Callable, Generator | ||
|
||
|
||
@dataclasses.dataclass | ||
class BlameResult: | ||
found: bool = False | ||
trace_stack: str = "" | ||
|
||
|
||
@contextlib.contextmanager | ||
def blame(func: Callable) -> Generator[BlameResult, None, None]: | ||
""" | ||
Trace the function calls to find the first function that satisfies the | ||
condition. The trace stack will be stored in the result. | ||
Usage: | ||
```python | ||
with blame(lambda: some_condition()) as result: | ||
# do something | ||
if result.found: | ||
print(result.trace_stack) | ||
""" | ||
result = BlameResult() | ||
|
||
def _trace_calls(frame, event, arg=None): | ||
nonlocal result | ||
if event in ['call', 'return']: | ||
# for every function call or return | ||
try: | ||
# Temporarily disable the trace function | ||
sys.settrace(None) | ||
# check condition here | ||
if not result.found and func(): | ||
result.found = True | ||
result.trace_stack = "".join(traceback.format_stack()) | ||
# Re-enable the trace function | ||
sys.settrace(_trace_calls) | ||
except NameError: | ||
# modules are deleted during shutdown | ||
pass | ||
return _trace_calls | ||
|
||
sys.settrace(_trace_calls) | ||
|
||
yield result | ||
|
||
sys.settrace(None) |