Skip to content
Closed
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
12 changes: 10 additions & 2 deletions tensorrt_llm/_torch/pyexecutor/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,14 @@ def configure_kv_cache_capacity(self,

fraction = self._kv_cache_config.free_gpu_memory_fraction

# Warmup (torch.compile specialization, autotuning, CUDA-graph capture,
# memory-pool pre-population) already ran in PyExecutor.__init__ and is
# replayed against the final KV cache once this estimate is applied. Its
# high-water mark can exceed the text-only profiling dummy's, so latch it
# before reset_peak_memory_stats() drops it; otherwise the pool is sized
# against the smaller peak and warmup OOMs on the second pass.
warmup_peak_memory = torch.cuda.max_memory_allocated()

torch.cuda.empty_cache()
torch.cuda.reset_peak_memory_stats()
end, total_gpu_memory = torch.cuda.mem_get_info()
Expand Down Expand Up @@ -1197,8 +1205,8 @@ def configure_kv_cache_capacity(self,
if response.has_error():
raise RuntimeError(response.error_msg)

torch_peak_memory = torch.cuda.memory_stats(
)["allocated_bytes.all.peak"]
torch_peak_memory = max(torch.cuda.max_memory_allocated(),
warmup_peak_memory)

# Release before measuring current usage so the retained
# embeddings count toward the peak but not the steady state.
Expand Down
Loading