Files
foxhunt/crates
jgrusewski 6f53d676fb docs(sp17): annotate c51_loss/c51_grad SP17 compliance (Commit E)
Audit-only commit per user design call DD9. The plan's Task 1.4
incorrectly claimed c51_loss_batched + c51_grad_kernel needed migration;
both kernels have been mean-zero centered since commit 56373f094.

Audit findings:

c51_loss_kernel.cu::c51_loss_batched (line 760-806):
- Forward dueling reduction at lines 765-779 already computes
  `a_mean = (1/n_d) Σ shmem_adv[a, j]` and applies
  `centered = shmem_adv[a_d, j] - a_mean` — IS the SP17 mean-zero
  projection. Annotated `/* SP17 mean-zero */`.
- Counterfactual magnitude path at lines 788-805: same pattern.
- Spectral decoupling at lines 812-827: same pattern.
- Bellman target argmax at lines 848-855: shmem_proj[j] IS a_mean_per_atom.
- Per-d=1 magnitude std normalization (line 770-778) is ORTHOGONAL to
  SP17 mean-zero — a separate variance-control concern for the magnitude
  branch's tighter Q distribution. Annotated
  `/* SP17: per-d=1 mag std normalization (orthogonal) */`.

c51_grad_kernel.cu::c51_grad_kernel (line 287-291):
- `dueling_grad = (a == a_d) ? (1.0f - inv_A) : (-inv_A)` at line 288 IS
  the SP17 mean-zero Jacobian: J[a, a_d] = δ(a, a_d) − 1/n_d. The chain
  rule for centered logit `A_taken − mean_a A` w.r.t. A[a'] produces
  exactly this Kronecker-delta-minus-uniform pattern.
- Per-d=1 magnitude std grad multiplier (line 290) — same orthogonal
  concern as c51_loss.

Zero code-path change. Both kernels behave bit-identically to pre-E.

Wire-up status (FINAL — every consumer SP17-compliant):
  compute_expected_q (Task 1.2)         MIGRATED
  quantile_q_select (Commit A)          MIGRATED
  mag_concat_qdir (Commit B)            MIGRATED
  Thompson direction-select (Commit C)  MIGRATED + V wired in
  barrier_gradient_direction (Commit D) MIGRATED
  ib_gradient_direction (Commit D)      MIGRATED
  c51_loss_batched (this commit)        ALREADY-COMPLIANT, ANNOTATED
  c51_grad_kernel (this commit)         ALREADY-COMPLIANT, ANNOTATED

After this commit, EVERY advantage-logit read in cuda_pipeline goes
through the SP17 mean-zero contract. No un-centered raw-advantage reads
remain in production kernels.

Verification (RTX 3050 Ti):
  cargo check --workspace                                              → clean
  cargo test sp17_dueling_oracle_tests --features cuda -- --ignored    → 6/6 PASS
  grep adv_a[ kernels (excluding centered/comments)                    → empty
  grep dir_logits_b[ kernels (excluding centered/comments)             → empty

Plan: docs/superpowers/plans/2026-05-08-sp17-dueling-q-network.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 22:03:17 +02:00
..