Files
foxhunt/crates
jgrusewski f9a8a5aa9a feat(dqn): intent-side magnitude distribution diagnostic (EVAL_INTENT_MAG_DIST)
Adds a parallel read path that reports the policy's intended mag_idx
BEFORE Kelly/margin caps and before the Hold/Flat dir_idx forces
mag=0. This exposes whether the magnitude Q-head is learning state-
dependent preferences, independent of the Kelly cold-start cap that
was masking it via actual_mag decoding (kelly_position_cap
warmup_floor=0.5 + safety=0.5+0.5*health pinning abs_pos <= 0.375).

Kernel changes (experience_kernels.cu):
- experience_action_select: new trailing optional arg `out_intent_mag`
  (int*, NULL=skip). Populated AFTER the existing mag_idx selection
  via a strict argmax over q_b1, ignoring the Hold/Flat mag=0 forcing,
  with the same higher-bin-wins tie-break used in the b2/b3 paths.
  Uses q_sign so the intent stays consistent with contrarian mode.
- New scatter_intent_chunk kernel: copies step-major chunked intent
  [chunk_len, n_windows] into window-major intent_history
  [n_windows, max_len], mirroring the actions_history layout.

Rust wiring (gpu_backtest_evaluator.rs):
- New fields intent_mag_buf, chunked_intent_mag_buf, scatter_intent_kernel.
  Buffers allocated alongside existing chunked buffers in
  ensure_action_select_ready. intent_mag_buf is zeroed by
  reset_evaluation_state so short rollouts don't read stale data.
- submit_dqn_step_loop_cublas appends the new arg to the action_select
  launch and launches scatter_intent_chunk immediately after, before
  the env_batch_kernel (which never touches intent_mag_buf).
- read_eval_intent_magnitude_distribution mirrors
  read_eval_action_distribution_per_magnitude but decodes raw mag_idx
  (a as usize) rather than the factored action encoding.

Training-path call site (gpu_experience_collector.rs): passes NULL
(0u64) for the new arg — training does not collect intent history.

Trainer wiring:
- new last_eval_intent_magnitude_dist field + accessor; populated in
  metrics.rs::evaluate_on_gpu next to last_eval_magnitude_dist.

Smoke test (magnitude_distribution.rs): adds [EVAL_INTENT_MAG_DIST]
println line; no new assertions.

Diagnostic-only, no new feature flag — production behaviour unchanged.
All 7 files build cleanly with no new warnings.

[testing: smoke compiles + runs, still fails on the existing H10
assertion (EVAL_DIST Quarter=1.000 driven by Kelly cold-start cap),
EVAL_INTENT_MAG_DIST shows Quarter=0.357 Half=0.045 Full=0.599 at
20-epoch smoke on local RTX 3050 Ti — confirming the magnitude head
prefers Full ~60% of the time while the Kelly-capped realised
distribution pins to Quarter.]

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 00:22:56 +02:00
..