feat(sp22): H6 Phase 3 α Phase C1 — collector W ptr setter

Wires the trainer's `w_aux_to_q_dir [4]` device pointer into the
GpuExperienceCollector so rollout-time action selection sees the
active atom-shift for the direction branch.

Changes:
- gpu_experience_collector.rs: new field aux_w_to_q_dir_dev_ptr (u64,
  default 0) + setter set_aux_w_to_q_dir_ptr(). Both rollout launchers
  (compute_expected_q + quantile_q_select) now pass W ptr + exp_states_f32
  + STATE_DIM_PADDED instead of NULL placeholders. NULL-safe via the
  kernels' existing aux_shift_active gating.
- gpu_dqn_trainer.rs: w_aux_to_q_dir field promoted to pub(crate) for
  cross-module access via raw_ptr().
- trainers/dqn/trainer/training_loop.rs: new wire-up block after SP15
  warm-count setter, mirroring the established setter pattern. NULL-safe
  on test scaffolds where fused_ctx or collector is absent.

End-state — rollout activation:
- compute_expected_q + quantile_q_select now return shifted E[Q] /
  quantile-blends per direction action during rollout.
- With trainer's W trained each step (Step 8+11 Adam), the rollout
  policy's direction-action distribution actively reflects the learned
  aux→policy coupling. state_121's per-env value drives a per-(env, action)
  bias of magnitude W[a] (≤0.5 initial prior, learned thereafter).

Verification: cargo check -p ml --lib clean (0 errors, 21 pre-existing
warnings).

Trainer + collector now smoke-ready end-to-end for the trainer/rollout
side. Eval-side activation pending Phase D.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-05-13 08:14:01 +02:00
parent 5d163e0e1d
commit 5106e3b117
4 changed files with 96 additions and 18 deletions

View File

@@ -17177,3 +17177,40 @@ Both scratch buffers default to 0 → when `aux_shift_active` is false in c51_lo
W now trains via the c51 loss gradient. Starting from structural prior `[-0.5, 0.0, +0.5, 0.0]`, Adam refines W per-action based on observed `state_121 × (loss reduction from atom-shift)`. The aux head trains independently via its supervised next-bar CE; together they form a learned cross-coupling from aux direction predictions to dir-branch Q distribution shifts.
Next session can dispatch a smoke at this checkpoint to measure whether the adaptive W (vs. fixed structural prior) lifts WR off 50%. If WR moves on the trainer side without rollout-side activation, Phase C1 is the next priority. If not, the hypothesis needs reconsideration.
#### Phase C1 — collector W ptr setter (2026-05-13)
**Phase C1 — rollout-time atom-shift activation**:
The collector's `compute_expected_q` + `quantile_q_select` launchers now read the trainer's `w_aux_to_q_dir [4]` device pointer (instead of NULL) when the trainer is wired in.
**Changes**:
- `gpu_experience_collector.rs`:
- New field `aux_w_to_q_dir_dev_ptr: u64` (default 0).
- New setter `set_aux_w_to_q_dir_ptr(dev_ptr: u64)` mirroring `set_isv_signals_ptr` + `set_sp15_alpha_warm_count_ptr` patterns.
- Both rollout-time launchers (`compute_expected_q` line ~5666, `quantile_q_select` line ~6041) now pass `self.aux_w_to_q_dir_dev_ptr` for W and `self.exp_states_f32.raw_ptr()` for batch_states, with `STATE_DIM_PADDED` (= 128) as the stride.
- `gpu_dqn_trainer.rs`:
- `w_aux_to_q_dir` field promoted from private to `pub(crate)` so `training_loop.rs` can read its raw_ptr().
- `trainers/dqn/trainer/training_loop.rs`:
- New wire-up block right after the SP15 warm-count setter calls `collector.set_aux_w_to_q_dir_ptr(fused.trainer().w_aux_to_q_dir.raw_ptr())`. NULL-safe: skipped when fused_ctx or collector absent (test scaffolds).
**End-state — rollout activation complete**:
Action selection during rollout now sees atom-shifted Q values:
- `compute_expected_q` returns shifted E[Q] per direction action → policy / epsilon-greedy / Thompson sampling picks accordingly.
- `quantile_q_select` returns shifted quantile-blended Q per direction action → IQR-based action selection mixes the shift into its blend.
With the trainer's W updated each step by Step 8+11 Adam, the rollout policy's direction-action distribution now actively reflects the learned aux→policy coupling. State_121's per-env value (recentered aux p_up) drives a per-(env, action) bias of magnitude W[a] (≤ 0.5 on initial prior, learned thereafter).
**Verification**:
- `cargo check -p ml --lib`: 0 errors, 21 pre-existing warnings.
**Remaining work**:
- **Phase D** (7 tasks): A2 eval-side aux infrastructure. Eval-time action selection doesn't see atom-shift yet (the eval backtester has its own forward + action-selection chain separate from the trainer/collector).
- **Phase E** (7 tasks): verification gates including capture-graph integrity, compute-sanitizer.
- **Phase F** (5 tasks): audit doc + atomic commit + push + smoke + verdict.
**Trainer + collector are now smoke-ready end-to-end for the trainer/rollout side**. Eval-side activation (Phase D) is needed for the validation backtests to also benefit from atom-shift.