Repository navigation
Conversation
…emoization The timing loop passed the same input tensors to every timed trial, so a ModelNew that caches its output on input identity (e.g. `if x is self._last_x: return self._last_out`) passes every correctness trial but is timed from its cache, giving an arbitrarily large fake speedup. eval_kernel_against_ref now builds a pool of distinct input sets (own seed each, up to one per timed call, capped at 25% of free device memory by default) and every timing method rotates through it. Warmup still uses the original inputs, so pool entries are unseen before the first timed call. The reference timing in the excessive-speedup check uses the same pool. Rotation can be turned off with rotate_perf_inputs=False. Fixes ScalingIntelligence#171 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the quick fix! I ran it at The test kernel only remembers the last input, so any 2-set rotation beats it. A memoizer that keeps a few entries survives once the pool cycles: class ModelNew(nn.Module):
def __init__(self):
super().__init__()
self._cache = [] # [(x, out)], last 4 inputs
def forward(self, x):
for seen, out in self._cache:
if seen is x:
return out
out = torch.relu(x)
self._cache = (self._cache + [(x, out)])[-4:]
return outResults with
Two suggestions:
It would also help to add the per-set memoizer and a capped pool to The launch-count check from #171 catches this regardless of pool size: a cached call launches zero kernels. Happy to send the launch-count check as a follow-up PR. |
Review on ScalingIntelligence#173 showed the pool cycles once it holds fewer sets than timed calls, and the memory cap makes that common: a memoizer that keeps the last 4 inputs got 89x on level1/19 (6.4 GB input sets, pool of 2) and 3.4x on matmul with a T4-sized cap, under the excessive-speedup threshold. eval.make_fresh_inputs draws a new input set (own seed, seed + 1 + call) before each timed call, outside the timed region, in the loops the eval controls (cuda_event, do_bench_impl, host_time). The previous set is freed first, so only one set is live and there is no pool or memory cap. New values on every call also defeat memoizers keyed on a fingerprint of the input values, which copies of the same inputs would not. do_bench and nsight_python own their loops, so they keep reusing the inputs and print a warning. Tests: memoizers keyed on the last input, the last 4 inputs and a value fingerprint, each across cuda_event, do_bench_impl and host_time, plus CPU tests for make_fresh_inputs and the timing loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on ScalingIntelligence#173 showed the pool cycles once it holds fewer sets than timed calls, and the memory cap makes that common: a memoizer that keeps the last 4 inputs got 89x on level1/19 (6.4 GB input sets, pool of 2) and 3.4x on matmul with a T4-sized cap, under the excessive-speedup threshold. eval.make_fresh_inputs draws a new input set (own seed, seed + 1 + call) before each timed call, outside the timed region, in the loops the eval controls (cuda_event, do_bench_impl, host_time). The previous set is freed first, so only one set is live and there is no pool or memory cap. New values on every call also defeat memoizers keyed on a fingerprint of the input values, which copies of the same inputs would not. Inputs are drawn on the device (falling back to the CPU if get_inputs cannot run there), so drawing them per call stays cheap. do_bench and nsight_python own their loops, so they keep reusing the inputs and print a warning. Tests: memoizers keyed on the last input, the last 4 inputs and a value fingerprint, each across cuda_event, do_bench_impl and host_time, plus CPU tests for make_fresh_inputs and the timing loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on ScalingIntelligence#173 showed the pool cycles once it holds fewer sets than timed calls, and the memory cap makes that common: a memoizer that keeps the last 4 inputs got 89x on level1/19 (6.4 GB input sets, pool of 2) and 3.4x on matmul with a T4-sized cap, under the excessive-speedup threshold. eval.make_fresh_inputs draws a new input set (own seed, seed + 1 + call) before each timed call, outside the timed region, in the loops the eval controls (cuda_event, do_bench_impl, host_time). The previous set is freed first, so only one set is live and there is no pool or memory cap. New values on every call also defeat memoizers keyed on a fingerprint of the input values, which copies of the same inputs would not. Inputs are drawn on the device (falling back to the CPU if get_inputs cannot run there), so drawing them per call stays cheap. do_bench and nsight_python own their loops, so they keep reusing the inputs and print a warning. Tests: memoizers keyed on the last input, the last 4 inputs and a value fingerprint, each across cuda_event, do_bench_impl and host_time, plus CPU tests for make_fresh_inputs and the timing loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for testing this on a B200 and for the thorough breakdown. You're right that cycling a capped pool doesn't hold up once a memoizer keeps more entries than the pool has sets. I've pushed an update (e6103a0) that takes your first suggestion. The pool and the memory cap are gone. In the loops the eval controls ( One change from your suggestion: I draw new inputs rather than copying the same ones. Copies would still lose to a memoizer keyed on a fingerprint of a few input values. It passes correctness, since those trials use different values, then hits on every timed call, and the launch-count check wouldn't catch it because the fingerprint read launches a kernel. Inputs are drawn directly on the device (falling back to the CPU if
Tests in On a T4:
Peak extra memory with a 1 GiB input is 3.00 GiB for both 10 and 50 trials. I couldn't run level1/19 at full size, since a 6.4 GB input set doesn't fit on a T4 alongside its output. If you can rerun your B200 table on this version, that would be great. And yes, please send the launch-count check! It covers what fresh inputs can't, like |
A cache keyed on a fingerprint of the input values still launches the reads that compute its key on a hit, so it is never zero-launch. Count the first call on inputs the model has not seen and the repeated calls on the same inputs, and fail when the repeated calls launch fewer operations. Both calls see the same values, so a kernel without a cache launches the same operations. Raised in ScalingIntelligence#173.
|
Thanks, the per-call inputs fix it. I reran Your tests: The review table on this version (100 timed trials, threshold 10; columns are timing methods, values are speedup over the reference):
So the eval-controlled loops are covered, and Good catch on the fingerprint memoizer. A zero-launch rule misses it because the key read launches a D2H copy on every hit. I changed the check to compare the first call on unseen inputs with repeated calls on the same inputs and to fail when the repeated calls enqueue less GPU work. It catches all three of your memoizers under |
|
@simonguozirui when you have a moment, this one is ready for review. It fixes the timing-loop memoization from #171 (a memoizing kernel got a 13,000x+ fake speedup) and has been verified on a B200 by the issue's author, including the full-size level1/19 case. It pairs with #175, which covers |
Fixes #171.
Problem
eval_kernel_against_refbuiltinputsonce and every timing method calledkernel_fn(*args)with the same tensors on every timed trial. AModelNewthat memoizes on its inputs (if x is self._last_x: return self._last_out) is correct on every correctness trial, but after the first call every timed trial is a cache hit, so it reports an arbitrarily large speedup. Tolerances and input distributions can't catch this, because the output really is correct.Fix
eval.make_fresh_inputs(get_inputs, seed, device, ...)returnsfresh_args(call), which draws a new input set for each timed call with its own seed (seed + 1 + call). Inputs are new tensors with new values and stay reproducible. They're drawn directly on the device, falling back to the CPU ifget_inputscan't run there, so drawing per call stays cheap.cuda_event,do_bench_impl,host_time) take an optionalfresh_argsand draw before each timed call, outside the timed region. The previous set is freed first, so only one extra set is live whatever the input size. Warmup still uses the original inputs.do_benchandnsight_pythonown their loops, so drawing per call would land inside the timed region. They keep reusing the inputs and print a warning whenfresh_argsis passed.eval_kernel_against_refgetsfresh_perf_inputs=True(Falsegives the old behaviour). The reference timing in the excessive-speedup check uses the same per-call inputs, so the comparison is like for like.measure_ref_program_time(baseline generation) is unchanged, so published baselines stay comparable.New values on every call matter: copies of the same inputs would still lose to a memoizer keyed on a fingerprint of a few input values. It passes correctness, since those trials use different values, then hits on every timed call.
The first version of this PR rotated through a pre-built pool capped at 25% of free memory. As the review showed, the pool cycles once it's smaller than the number of timed calls (2 sets for level1/19's 6.4 GB inputs), so a memoizer keeping the last 4 inputs still won. The pool and the cap are gone now.
Tests
test_eval_adversarial.py:cuda_event,do_bench_implandhost_timefresh_perf_inputs=Falsetest_fresh_perf_inputs.py(CPU only): drawn inputs differ per call, are reproducible and differ from warmup, precision and non-tensor handling, CPU fallback, and a realhost_timeloop (CUDA stubbed) giving warmup the original inputs and every timed call new values.Results (Tesla T4,
cuda_eventunless noted, 100 trials, 19 passed in 1m51s)fresh_perf_inputs=FalsePeak extra memory while timing a 1 GiB input: 3.00 GiB for 10 trials and 3.00 GiB for 50 trials.
Not run: level1/19 at full size (doesn't fit a T4), other precisions and backends, AMD.
Follow-up
The launch-count check from #171 (zero CUDA launches on a call means it did no work) would also cover
do_bench,nsight_pythonand memoization paths fresh inputs can't reach. The issue author offered to send it.🤖 Generated with Claude Code