[Profiler] Add per-session profiling controls to Python and Rust frontends (#57875)
Signed-off-by: czhu <conway.zhu@cohere.com> Signed-off-by: Conway Zhu <conway.zhu@cohere.com> Co-authored-by: aoshen02 <aoshen@inferact.ai>
This commit is contained in:
@@ -122,8 +122,6 @@ def _validate_api_url(
|
||||
if isinstance(expected_suffixes, str):
|
||||
expected_suffixes = {expected_suffixes}
|
||||
|
||||
expected_suffixes = {*expected_suffixes, "profile"}
|
||||
|
||||
if not api_url.endswith(tuple(expected_suffixes)):
|
||||
raise ValueError(f"{api_name} URL must end with one of: {expected_suffixes}.")
|
||||
|
||||
@@ -158,6 +156,34 @@ def _get_headers(content_type: str | None = None) -> dict[str, str]:
|
||||
return headers
|
||||
|
||||
|
||||
async def async_request_profile(
|
||||
api_url: str,
|
||||
session: aiohttp.ClientSession,
|
||||
extra_headers: dict | None = None,
|
||||
) -> RequestFuncOutput:
|
||||
_validate_api_url(
|
||||
api_url,
|
||||
"Profiling API",
|
||||
{"start_profile", "stop_profile"},
|
||||
)
|
||||
|
||||
headers = _get_headers()
|
||||
if extra_headers:
|
||||
headers |= extra_headers
|
||||
|
||||
output = RequestFuncOutput()
|
||||
try:
|
||||
async with session.post(url=api_url, headers=headers) as response:
|
||||
output.success = response.status == 200
|
||||
if not output.success:
|
||||
output.error = response.reason or ""
|
||||
except Exception:
|
||||
exc_info = sys.exc_info()
|
||||
output.error = "".join(traceback.format_exception(*exc_info))
|
||||
|
||||
return output
|
||||
|
||||
|
||||
async def async_request_openai_completions(
|
||||
request_func_input: RequestFuncInput,
|
||||
session: aiohttp.ClientSession,
|
||||
|
||||
@@ -49,6 +49,7 @@ from vllm.benchmarks.lib.endpoint_request_func import (
|
||||
POOLING_BACKENDS,
|
||||
RequestFuncInput,
|
||||
RequestFuncOutput,
|
||||
async_request_profile,
|
||||
)
|
||||
from vllm.benchmarks.lib.ready_checker import wait_for_endpoint
|
||||
from vllm.benchmarks.lib.utils import (
|
||||
@@ -936,22 +937,10 @@ async def benchmark(
|
||||
|
||||
if profile:
|
||||
print("Starting profiler...")
|
||||
profile_input = RequestFuncInput(
|
||||
model=model_id,
|
||||
model_name=model_name,
|
||||
prompt=test_prompt,
|
||||
api_url=base_url + "/start_profile",
|
||||
prompt_len=test_prompt_len,
|
||||
output_len=test_output_len,
|
||||
logprobs=logprobs,
|
||||
multi_modal_content=test_mm_content,
|
||||
ignore_eos=ignore_eos,
|
||||
profile_output = await async_request_profile(
|
||||
base_url + "/start_profile",
|
||||
session,
|
||||
extra_headers=extra_headers,
|
||||
extra_body=test_extra_body,
|
||||
chat_messages=test_chat_messages,
|
||||
)
|
||||
profile_output = await request_func(
|
||||
request_func_input=profile_input, session=session
|
||||
)
|
||||
if profile_output.success:
|
||||
print("Profiler started")
|
||||
@@ -1469,16 +1458,10 @@ async def benchmark(
|
||||
|
||||
if profile:
|
||||
print("Stopping profiler...")
|
||||
profile_input = RequestFuncInput(
|
||||
model=model_id,
|
||||
prompt=test_prompt,
|
||||
api_url=base_url + "/stop_profile",
|
||||
prompt_len=test_prompt_len,
|
||||
output_len=test_output_len,
|
||||
logprobs=logprobs,
|
||||
)
|
||||
profile_output = await request_func(
|
||||
request_func_input=profile_input, session=session
|
||||
profile_output = await async_request_profile(
|
||||
base_url + "/stop_profile",
|
||||
session,
|
||||
extra_headers=extra_headers,
|
||||
)
|
||||
if profile_output.success:
|
||||
print("Profiler stopped")
|
||||
|
||||
Reference in New Issue
Block a user