Files
foxhunt/crates/ml/examples
jgrusewski ed6f5588e1 feat(phase-e-4-a): wire Mamba2 forward in smoke --temporal path
Phase E.4.A Task 8: wire ml_alpha::Mamba2Block as the temporal
encoder before the C51 head when --temporal is set.

Architecture (--temporal):
  state_pinned ──push─▶ window_tensor[1, K=16, in_dim=10]
                              │
                              ▼ Mamba2Block::forward_train
                       h_enriched[1, hidden_dim=32]
                              │
                              ▼ launch_alpha_c51_forward (input dim=32)
                       probs[1, 9, 51] ──▶ Thompson selector

Implementation:
- Mamba2Block constructed at startup with config (in_dim=10,
  hidden_dim=32, state_dim=16, seq_len=K=16). Loaded from ml-alpha's
  precompiled cubin.
- Per-step: window push (shift+insert), then forward_train returns
  (logit, cache). We discard logit (ml-alpha's binary classifier head)
  and use cache.h_enriched as the C51 input.
- Per-step h_enriched cached into h_enriched_buf_dev[(t)..t+hidden_dim].
- Batched training (end-of-episode): the C51 forward + grad use
  h_enriched_buf_dev[0..ep_len*hidden] for the current state and
  [hidden..(ep_len+1)*hidden] for next-state (1-step offset). Runs
  one extra Mamba2 forward on the terminal window to populate slot
  ep_len.
- C51 input dim (W shape) becomes mamba2_hidden_dim when --temporal,
  STATE_DIM otherwise.

100-episode smoke verdict (vs C51-flat baseline):
  R_mean ep 50:  C51-flat -8.2  →  --temporal +0.4   (+8.6)
  R_mean ep 100: C51-flat +0.5  →  --temporal +10.0  (+9.5)
  rvr:           +1.045 → +1.046 (unchanged)
  Q_SPREAD:      23.9 → 12.6 (sharper distributions)
  ACTION_ENTROPY: 1.42 → 1.49 (now PASSES 0.5×ln(9) threshold)

Note: Mamba2 weights are FROZEN at random Xavier init in this
commit — T10 (backward + AdamW step) lands next. The R_mean lift
above is from C51 learning over RANDOM temporal projections of the
window — random SSM acts as a feature-engineering reservoir.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-15 21:14:31 +02:00
..