Bringing Up a Hybrid Model on WebGPU With Stage Dumps

How a Gated-DeltaNet plus attention model went from a spec to a running WebGPU engine that picked the same next token as PyTorch: save every intermediate for one layer from the oracle, compare per stage, and watch for three traps, including a test runner that reported success while running zero tests.

Summary

A hybrid model mixes recurrent linear-attention layers with full attention. We wrote its WebGPU decode engine from a spec and a numpy reference, reusing the dense engine's matvec, norm and attention kernels and writing four new ones (conv, delta rule, gated norm, partial rotary prep). The oracle did not just save final logits; it saved every intermediate of one linear layer and one full layer. The first run compiled and picked the same next token as PyTorch, with 19 of the top 20 tokens shared.

The method

  1. Run the reference model, then record, for the last prompt token, the tensors at each stage of layer 0 (projections, conv output, recurrent state before and after, readout, gated norm, layer output).
  2. Run the engine on the same ids and read the matching GPU buffers.
  3. Compare per stage with cosine and relative L2, in order. The first stage that disagrees is where the bug is.

All four recurrent stages matched at cosine 1.0000. The decay gates matched to three decimals.

Three traps

Recurrent state is not idempotent. A dense model's probe can re-run the last token because the KV entry is overwritten. A recurrent state is updated in place, so each probe must re-prefill from position 0. A harness that re-ran only the last token would have reported garbage.

The comparison was wrong, not the engine. The test said FAIL at the last layer with relative L2 0.91. The reference's last hidden state is taken after the final norm; ours was before it. The cosine was fine. Check what the oracle's tensor actually is.

A runner that ran nothing. When the Python environment path in our regression script went stale, the test group that needed numpy ran zero tests and the script still printed zero failures and a passing total (67 passes where 84 were expected). A run that executes nothing is not a pass. The script now fails if any group runs nothing.

Key takeaways

  1. Save intermediates of one layer from the reference; per-stage comparison finds the first divergence immediately.
  2. Know whether your state update is idempotent before designing probes.
  3. When a check fails at the end, verify the reference tensor's definition before debugging the engine.
  4. Make test runners fail on empty groups.

Follow @robotnurseio on X for the short version.


Everything in these notes I also do for hire: local AI set up on hardware you own, configured on-site, then handed over with enough documentation that you do not need me afterward. If that sounds more useful than another weekend of reading forum threads, the details are at /work. No obligation from an email, and the posts stay free either way.

See pricing and book an audit →