Files
foxhunt/docs/superpowers
jgrusewski 0b3e401500 feat(ml-alpha): Phase 2A-A — MultiHeadPolicy foundation (inert)
K=3 policy mixture + regime-gated routing head, with gate reading
REGIME_DIM=6 features DIRECTLY (bypassing the VSN softmax bottleneck
per the regime-attenuation empirical finding). Components are
unconditional but not yet wired into the trainer — Phase 2A-B
adds backward + aux KL prior, 2A-C wires Q-distill grad routing
to the mixture.

* 4 new ISV slots 761-764 (K, gating entropy floor, head entropy
  floor, aux prior β) + RL_SLOTS_END 761→765.
* multi_head_policy_forward.cu: per-batch K-head logits + mixture
  combination. Grid=(B), Block=(N_ACTIONS=11). Persists pi_logits_k
  + pi_probs_k for backward.
* multi_head_policy_gate_forward.cu: per-batch K-thread softmax
  over W·regime + b. Reads regime_h directly (parallel channel —
  bypass VSN). Stores pre-softmax logits to gmem BEFORE the
  in-place exp (caught during impl — plan pseudocode would have
  corrupted gate_logits).
* MultiHeadPolicy struct with Option A asymmetry-break init:
  Head 0 → ShortLarge bias (+0.5), Head 1 → LongSmall+LongLarge
  bias (+0.5 each), Head 2 → Hold bias (+0.5). Indices verified
  against rl/common.rs:56-70 N_ACTIONS=11 enum. htod via local
  upload() helper using MappedF32Buffer + raw_memcpy_dtod_async
  (mirrors rl/ppo.rs, rl/dueling_q.rs).
* 5 GPU-oracle invariant tests, all PASS:
  - gate_probs_sum_to_one
  - pi_probs_mixture_sums_to_one
  - k1_reduces_to_single_head (bit-equal vs reference Linear)
  - gate_responds_to_regime_change (TVD > 0.5, modal head flips)
  - forward_is_deterministic_across_contexts (bit-equal across
    two fresh CUDA contexts)
* Determinism preserved: ./scripts/determinism-check.sh --quick
  exits 0 (pipeline unchanged, components inert).
* No memcpy_htod/memcpy_dtoh on regular slices, no atomicAdd, no
  scoped-init-seed bypass.

Empirical motivation (3-seed mid-smoke at HEAD 779c03b9d, b=128):
  mean -$6.41M ± $1.39M σ; 62× spread in popart_envelope quartile
  (Q1 -$1.99M / Q4 -$32k); policy TVD asymmetry 0.17 on popart
  axis vs 0.02 on vol axis. Regime-direct gating targets the
  attenuation chokepoint; mixture provides regime-conditional
  capacity that single-head softmax cannot express.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-03 01:41:57 +02:00
..