Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tests/v1/worker/test_gpu_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def test_memory_profile_replays_model_after_kernel_warmup(
):
worker = object.__new__(Worker)
calls = []
worker.device = "cuda:0"
worker.model_runner = SimpleNamespace(
profile_run=lambda: calls.append("profile"),
)
Expand All @@ -127,10 +128,21 @@ def test_memory_profile_replays_model_after_kernel_warmup(
"_warmup_kernels_once",
lambda: calls.append("kernel_warmup"),
)
monkeypatch.setattr(
gpu_worker_module.torch.accelerator,
"reset_peak_memory_stats",
lambda device: calls.append(("reset_peak", device)),
)

worker._profile_model_with_kernel_warmup()

assert calls == ["profile", "compressor", "kernel_warmup", "profile"]
assert calls == [
"profile",
"compressor",
"kernel_warmup",
("reset_peak", "cuda:0"),
"profile",
]


@pytest.mark.parametrize("video_backend", [None, "opencv"])
Expand Down
6 changes: 6 additions & 0 deletions vllm/v1/worker/gpu_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ def _profile_model_with_kernel_warmup(self) -> None:
)
self._warmup_kernels_once()

# The first pass may include one-time compiler or loader temporaries.
# Keep every persistent allocation initialized above, but exclude that
# startup-only high-water mark from the activation measurement. The
# second pass below establishes the repeatable serving peak.
torch.accelerator.reset_peak_memory_stats(self.device)

# Kernel warmup can create persistent modules and communication pools.
# A second pass is required so the measured peak contains both those
# allocations and the model's transient activation workspace.
Expand Down
Loading