Skip to content

Add challenge 107: Hadamard Transform (Medium)#286

Open
claude[bot] wants to merge 1 commit into
mainfrom
add-challenge-107-hadamard-transform
Open

Add challenge 107: Hadamard Transform (Medium)#286
claude[bot] wants to merge 1 commit into
mainfrom
add-challenge-107-hadamard-transform

Conversation

@claude

@claude claude Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds challenge 107: Hadamard Transform at medium difficulty.
  • Solvers compute the orthonormal Walsh-Hadamard transform of every row of a (B, N) matrix, where N is a power of two, using the fast butterfly schedule (O(N log N)).
  • Real-world inference relevance: Hadamard rotations are the core kernel in QuaRot / QuIP# style low-bit LLM quantization, where activations are rotated by a Hadamard matrix before INT4 / INT8 matmul to spread out outliers.
  • Teaches per-row work distribution, shared-memory layout, and __syncthreads() between the log2(N) butterfly stages — meaningfully harder than an elementwise op, simpler than a full FFT.

Files

  • challenges/medium/107_hadamard_transform/challenge.py — reference impl (pure PyTorch view/add/sub, works on CUDA and XLA), 10 functional tests covering N = 1, 2, 4, 16, 8, 32, 128, 1024, 64, 2048 with zeros, constants, mixed signs, and large rows.
  • challenges/medium/107_hadamard_transform/challenge.html — problem statement with recursive H_N definition and stage-by-stage worked example.
  • All 6 starters (.cu, .pytorch.py, .triton.py, .jax.py, .cute.py, .mojo).

Validation

  • pre-commit run --all-files — passes.
  • Verified reference impl locally: H @ H = I, constant rows produce a single non-zero coefficient at index 0, example [1, 2, 3, 4] → [5, -1, -2, 0].
  • Submitted a CUDA solution via scripts/run_challenge.py --action submit on a T4 — all tests pass.

Test plan

  • pre-commit run --all-files clean
  • Reference impl matches by-hand Hadamard transform on the example
  • CUDA reference solution passes full functional + performance suite on T4
  • Reviewer spot-checks HTML rendering and example layout

Adds a batched Walsh-Hadamard transform challenge: solvers compute the
orthonormal Hadamard transform of each row of a (B, N) matrix where N is
a power of two. The fast butterfly schedule (O(N log N), log2 N stages
with __syncthreads between them) is a real-world inference kernel used
in QuaRot/QuIP# style activation rotations for low-bit LLM quantization.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants