Skip to content

Commit 5be55aa

Browse files
zhanghw0354zhanghaiwen
authored andcommitted
[Main][Feat]Set the Profiler parameters through environment variables consistent with vLLM (vllm-project#2608)
### What this PR does / why we need it? Currently, when performing profiling in vLLM-Ascend, if you need to obtain the Python call stack, you have to manually modify the code. The code location is: [worker_v1.py#L337](https://github.com/vllm-project/vllm-ascend/blob/6c973361fc2eba5d3faa9b6b496b4b9fec4dc784/vllm_ascend/worker/worker_v1.py#L337) where you set with_stack to true. Now, in vLLM, you can set whether to obtain the Python call stack through an environment variable. The relevant PR is: [#21803](vllm-project/vllm#21803) and the documentation is: [profiling](https://docs.vllm.ai/en/latest/contributing/profiling.html?h=vllm_torch_profiler_with_stack#profile-with-pytorch-profiler) This PR sets the profiler initialization parameters by using the same environment variable as vLLM, eliminating the need for manual code modification. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? CI passed with new added/existing test. - vLLM version: v0.10.1.1 - vLLM main: vllm-project/vllm@0235103 --------- Signed-off-by: zhanghaiwen <zhanghaiwen@cmss.chinamobile.com> Co-authored-by: zhanghaiwen <zhanghaiwen@cmss.chinamobile.com>
1 parent 7c6f281 commit 5be55aa

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

tests/ut/worker/test_worker_v1.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,13 @@ def test_init_profiler_enabled(
452452
mock_logger,
453453
mock_envs_vllm,
454454
):
455-
"""Test _init_profiler method - profiler enabled case"""
455+
"""Test _init_profiler method - profiler enabled case with stack and memory profiling enabled"""
456456
from vllm_ascend.worker.worker_v1 import NPUWorker
457457

458458
# Set environment variables to enable profiler
459459
mock_envs_vllm.VLLM_TORCH_PROFILER_DIR = "/path/to/traces"
460+
mock_envs_vllm.VLLM_TORCH_PROFILER_WITH_STACK = True
461+
mock_envs_vllm.VLLM_TORCH_PROFILER_WITH_PROFILE_MEMORY = True
460462

461463
# Set enum mocks
462464
mock_export_type.Text = "Text"
@@ -516,8 +518,8 @@ def test_init_profiler_enabled(
516518
# Verify profiler parameters
517519
expected_activities = ["CPU", "NPU"]
518520
self.assertEqual(profile_kwargs["activities"], expected_activities)
519-
self.assertFalse(profile_kwargs["with_stack"])
520-
self.assertFalse(profile_kwargs["profile_memory"])
521+
self.assertTrue(profile_kwargs["with_stack"])
522+
self.assertTrue(profile_kwargs["profile_memory"])
521523
self.assertFalse(profile_kwargs["with_modules"])
522524
self.assertEqual(profile_kwargs["experimental_config"],
523525
mock_experimental_config_instance)

vllm_ascend/worker/worker_v1.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,9 @@ def _init_profiler(self):
336336
torch_npu.profiler.ProfilerActivity.CPU,
337337
torch_npu.profiler.ProfilerActivity.NPU,
338338
],
339-
with_stack=False,
340-
profile_memory=False,
339+
with_stack=envs_vllm.VLLM_TORCH_PROFILER_WITH_STACK,
340+
profile_memory=envs_vllm.\
341+
VLLM_TORCH_PROFILER_WITH_PROFILE_MEMORY,
341342
with_modules=False,
342343
experimental_config=experimental_config,
343344
on_trace_ready=torch_npu.profiler.tensorboard_trace_handler(
@@ -352,4 +353,4 @@ def get_supported_tasks(self) -> "tuple[SupportedTask, ...]":
352353
return self.model_runner.get_supported_tasks()
353354

354355
def take_draft_token_ids(self) -> Optional[DraftTokenIds]:
355-
return self.model_runner.take_draft_token_ids()
356+
return self.model_runner.take_draft_token_ids()

0 commit comments

Comments
 (0)