Add JAX reference implementations for CPU-slow challenges#278
Merged
Conversation
The TPU runner uses CPU torch as ground truth, but reference_impl is intractably slow on CPU for large matmuls, attention, transformer blocks, convolutions, O(n^2) ops, and challenges with Python-level sequential loops. The runner prefers a challenge-supplied reference_impl_jax when present. Add reference_impl_jax to 30 such challenges. Each mirrors reference_impl exactly under the runner contract: takes the in/inout params in signature order as jax arrays, returns the out/inout results, fp32 matmuls at highest precision. Python sequential loops are replaced with jax.lax.scan (linear_recurrence, ssm_selective_scan, adder_transformer decode) and jax.lax.fori_loop (all_pairs_shortest_paths), and nested .item() loops are vectorized (categorical_cross_entropy, speculative_decoding_verification). jax is imported lazily inside reference_impl_jax (not at module scope) so challenge.py still imports and runs the torch reference_impl on images where jax is not installed (e.g. the CUDA runner). Verified each against the torch reference on its functional tests at the challenge's own atol/rtol. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
3566a2a to
f3190f5
Compare
Migrate generate_performance_test on the jax-ref'd challenges from imperative torch construction to declarative specs (RandTensor/RandnTensor/RandIntTensor/ FullTensor/OutTensor); the runner materializes inputs on the accelerator (jax on TPU) instead of generating on CPU and copying over. 18 migrated; structured-input challenges left imperative. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ca8d713 to
9b536e7
Compare
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.
No description provided.