Files
foxhunt/crates
jgrusewski db4d9a16ff feat(rl): Phase 2.1 — scalar Bellman target + dueling Q (V baseline)
Spec: docs/superpowers/specs/2026-05-28-state-conditional-q-synthesis.md
§3 Sub-phase 2.1.

Replaces the distributional Bellman bootstrap
(fused_select_and_project_bellman) with the Dueling-DQN scalar
baseline target

  y(s_t, a_t)       = r_t + γⁿ × V_target(s_{t+1})
  advantage_scalar  = y − V(s_t)

projected via two-bin linear interpolation onto the action's atom
support. The Q-head's atom logits are now interpreted as the
advantage distribution A_dist(s, a); the CE loss between
softmax(A_dist(s_t, a_t)) and the projected target trains A to
model deviation from the scalar V baseline.

Changes:
- NEW crates/ml-alpha/cuda/bellman_scalar_target_project.cu —
  device-side scalar Bellman target + per-action atom projection.
  Grid (B, 1, 1), Block (Q_N_ATOMS=21, 1, 1). No atomicAdd, no
  cross-thread accumulation: scalar advantage produces a delta on
  exactly two atoms so each thread writes its own atom value.
- crates/ml-alpha/build.rs registers the new kernel.
- crates/ml-alpha/src/rl/dqn.rs:
  * Loads bellman_scalar_target_project from its own cubin.
  * Adds DqnHead::bellman_scalar_target_project wrapper.
  * Adds host-side composed_q_value(v_scalar, a_logits,
    atom_supports) -> Vec<f32> implementing the Dueling
    composition Q = V + A - mean_a(A) for test oracles.
- crates/ml-alpha/src/trainer/integrated.rs:
  * Allocates sampled_v_curr_d + sampled_v_target_tp1_d for
    V evaluated on PER-sampled hidden states.
  * step_synthetic_body Bellman build: replaces forward_target +
    fused_select_and_project_bellman with V forwards on sampled
    buffers + the new scalar Bellman projection (single source of
    truth — same swap applied to dqn_replay_step for k>0 path).
  * Test accessors isv_host_slice_mut_for_test,
    isv_dev_ptr_for_test, dqn_head_ref so kernel-oracle unit
    tests can drive the new kernel without a full mega-graph.
- NEW crates/ml-alpha/tests/q_projection_unit.rs — pre-impl oracle:
  projects y=0 to center atom, y=V_MAX to last, y=V_MIN to first,
  arbitrary in-range cases recover EV within Δz/2, verifies V_t
  enters as a subtraction. Plus pure host-side check of
  composed_q_value.

All Phase 2.1 unit tests pass (5 CUDA --ignored + 2 host-side).

Smoke status: BLOCKED on pre-existing NaN abort at step 4 affecting
HEAD (c52282fb4 + f11bab542 + 7e38e46e6) — l_pi=NaN, l_aux=NaN at
step 4 reproduce IDENTICALLY with and without Phase 2.1 changes.
Per feedback_stop_on_anomaly, the pre-existing NaN must be diagnosed
before the Phase 2.1 smoke gate (l_v<2.0, l_q<3.0,
action_entropy>1.5 for 500 steps) can be validated. The Phase 2.1
changes themselves are structurally sound — unit tests confirm
correct projection and the smoke loss trajectories at steps 0-3 are
within ~1% of HEAD (l_q 2.9484 vs 2.9926, l_v 6.3293 vs 6.3291).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 01:01:08 +02:00
..