Skip to content

Commit 67f3143

Browse files
authored
Added unit tests for capture_torch_profiler_dir and detailed_trace_annotation
Added unit tests for capture_torch_profiler_dir and detailed_trace_annotation profiler configs. Signed-off-by: devalshahamd <deval.shah@amd.com>
1 parent a81d732 commit 67f3143

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

‎tests/v1/worker/test_gpu_profiler.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,53 @@ class TestIsUriPath:
236236
def test_is_uri_path(self, path, expected):
237237
"""Test that _is_uri_path correctly identifies URI vs local paths."""
238238
assert _is_uri_path(path) == expected
239+
240+
241+
class TestAnnotateProfile:
242+
"""Tests for Worker.annotate_profile() annotation string formatting."""
243+
244+
def _annotate(self, detailed: bool) -> str:
245+
worker = MagicMock()
246+
worker.vllm_config.profiler_config.detailed_trace_annotation = detailed
247+
worker.profiler = MagicMock()
248+
249+
ctx_req = MagicMock(req_id="ctx1", num_computed_tokens=0)
250+
cached = CachedRequestData(
251+
req_ids=["gen1"], resumed_req_ids=set(), new_token_ids=[],
252+
all_token_ids={}, new_block_ids=[],
253+
num_computed_tokens=[10], num_output_tokens=[1],
254+
)
255+
sched = MagicMock(scheduled_new_reqs=[ctx_req],
256+
scheduled_cached_reqs=cached,
257+
num_scheduled_tokens={"ctx1": 4, "gen1": 1})
258+
259+
Worker.annotate_profile(worker, sched)
260+
return worker.profiler.annotate_context_manager.call_args[0][0]
261+
262+
def test_simple_format_mixed(self):
263+
assert self._annotate(detailed=False) == (
264+
"execute_context_1(4)_generation_1(1)")
265+
266+
def test_detailed_format_mixed(self):
267+
# ctx1: sq=4, sk=4, sqsq=16, sqsk=16 | gen1: sq=1, sk=11, sqsq=1, sqsk=11 | bs=5
268+
assert self._annotate(detailed=True) == (
269+
"execute_5_context_1(sq4sk4sqsq16sqsk16)"
270+
"_generation_1(sq1sk11sqsq1sqsk11)")
271+
272+
273+
def test_profiler_entered_during_capture():
274+
"""Profiler is used as a context manager in _warmup_and_capture,
275+
confirming it is active during the actual graph capture run."""
276+
runner = MagicMock()
277+
runner.compilation_config.cudagraph_num_of_warmups = 0
278+
mock_profiler = MagicMock()
279+
280+
GPUModelRunner._warmup_and_capture(
281+
runner,
282+
desc=MagicMock(num_tokens=4, uniform=True),
283+
cudagraph_runtime_mode=CUDAGraphMode.FULL,
284+
profiler=mock_profiler,
285+
)
286+
287+
mock_profiler.__enter__.assert_called_once()
288+
mock_profiler.__exit__.assert_called_once()

0 commit comments

Comments
 (0)