Repository navigation
Conversation
…ntelligence#171) A kernel can cache its output keyed on the input tensors (identity, data_ptr or version counter). It passes every correctness trial, since each trial uses new inputs, and the timing loop then times the cached calls as near zero. After correctness passes, count the GPU operations torch.profiler records when ModelNew is called again on inputs it has already seen, and on inputs it has not. A cached call launches nothing, so (0 repeated, >0 fresh) fails correctness with correctness_issue_name "cached_output". A kernel that needs no GPU work, or a call the profiler misses, reads 0 on both and passes. On by default; turn off with check_for_cached_output=False.
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.
In some environments torch.profiler stops receiving device-side kernel records once an extension has been loaded with torch.utils.cpp_extension, while host-side launch calls are still traced. Count the host-side calls that enqueue GPU work (kernel and graph launches, memcpy, memset) instead. A replayed CUDA graph does its work in one launch call, so a repeated call that launches a graph is not flagged; a control test covers it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #171, as discussed on #173. This adds the launch-count check from #171. It catches a kernel that returns a cached output, under any timing method, including
do_bench, which cannot draw fresh inputs per call.What it does
After correctness passes,
eval_kernel_against_refcallsModelNewonce on an input set it has not seen, then three more times on the same set. For each call it counts the CUDA calls that enqueue GPU work (kernel and graph launches, memcpy, memset), astorch.profilertraces them on the host.data_ptrcache, only the key reads for a value-fingerprint cache. If the repeated calls enqueue fewer operations than the first, the check setscorrectness=Falseandcorrectness_issue_name="cached_output".cudaGraphLaunch, so a repeated call that launches a graph is not flagged. A control test covers this.The check is on by default;
check_for_cached_output=Falseturns it off. Both counts go intometadata(launches_on_first_call,launches_on_repeated_call). It costs five extra forward calls and one extra input set.Host-side calls are counted rather than device-side kernel records. On my setup (torch 2.11+cu128, B200), once any extension has been loaded with
load_inline(even C++-only), the profiler keeps tracing host calls but device-side kernel records stop arriving or arrive only sometimes. Device-side counting therefore read 0 for clean kernels when several evals ran in one process.Results (B200)
cached_output(1 / 0)data_ptr()+_version()cached_output(1 / 0)cached_outputtorch.matmul(new control)False positives:
best_agent_solutions, each against the KernelBench revision METR evaluated on. Of 56 files, 38 pass correctness (19 CUDA, 19 Triton). All 38 pass the check, with identical first and repeated counts (1 to 710 calls). The other 18 never reach the check: 13 fail correctness, 4 are level 5 with no reference, and 1 fails to load.Tests
test_eval_adversarial.py:test_cached_output,test_cached_output_fingerprint,test_cached_output_cuda_graph_controlandtest_cached_output_control, with four small test kernels.test_non_default_streamdeselected.test_non_default_streamis timing-dependent on this B200 with or without this change. On unpatched main it failed 3 of 3 runs. With this change it has both passed and failed.Relation to #173
#173 draws fresh inputs per timed call in the loops the eval controls; this check covers the rest,
do_benchin particular.On
launchcount-on173, both together pass all 21 tests in one process. One coordination point: #173's timing tests need the memoizer to reach the timing loop, so they passcheck_for_cached_output=False. A new test then runs the same three memoizers underdo_benchand expectscached_output.The two branches add to the same parameter list and the same spot in
eval.py. Resolving the conflict means keeping both sides.Not tested: AMD/HIP.