Merge pull request #714 from elder-plinius/fix/384-autotune-peaks

docs: record allocator peaks on the first largest-shape forward
This commit is contained in:
Joseph Magly authored and GitHub committed 2026-11-28 14:17:37 -05:00
commit 68bd282a61
1 file changed
+17 -4
+17 -4
View File
@@ -274,17 +274,23 @@ def measure(inputs, cache, total):
torch.cuda.empty_cache()
torch.cuda.reset_peak_memory_stats()
before = torch.cuda.memory_allocated()
reserved_before = torch.cuda.memory_reserved()
with torch.inference_mode():
result = model(inputs, past_key_values=cache, use_cache=True)
torch.cuda.synchronize()
peak = torch.cuda.max_memory_allocated() - before
print(tuple(inputs.shape), total, "bound", bound, "peak", peak)
allocated_peak = torch.cuda.max_memory_allocated()
reserved_peak = torch.cuda.max_memory_reserved()
peak = allocated_peak - before
print(tuple(inputs.shape), total, "bound", bound,
"allocated_before", before, "allocated_peak", allocated_peak,
"reserved_before", reserved_before, "reserved_peak", reserved_peak,
"additional_allocated_peak", peak)
assert torch.isfinite(result.logits).all()
assert 0 < peak <= bound, (peak, bound)
return result.past_key_values
for batch in (1, 2):
for tokens in (1, 63, 64, 65, 129):
for batch in (2, 1):
for tokens in (129, 65, 64, 63, 1):
inputs = torch.ones(batch, tokens, device="cuda", dtype=torch.long)
for repetition in range(2):
cache = measure(inputs, None, tokens)
@@ -294,6 +300,13 @@ for batch in (1, 2):
PY
```
Run the largest planned batch and token shape first in a fresh process, before
any warmup forwards. Retain the absolute allocated and reserved peaks, their
baselines, and the repetition order. The first forward can include compilation
and autotuning, while a fresh process can still reuse on-disk compiler caches.
Record cache state with the measurement. These allocator measurements help
assess the estimated 256 MiB margin for the measured workload.
A passing small-model RTX 4090 test would cover only those shapes, callables,
dtype and device. Full Qwen 27B BF16 qualification on an A100 80 GB remains
required for the reported workload, including its actual prompt/cache limits,