Files
foxhunt/docs
jgrusewski ab378327ec fix(data): vol_normalizer double-normalization removed (post-Bug-1)
The kernel block at experience_kernels.cu:698-704 divided
market_features[0..3] by vol_normalizer at runtime — designed for the
pre-Bug-1 pipeline where features arrived as RAW log returns (~±0.001).

After Bug 1 fix (commit 5a5dd0fed) moved z-normalization to the WRITER
(precompute_features.rs::NormStats::normalize_batch before fxcache write,
plus data_loading.rs DBN-fallback path applying the same op), features
arrive already-z-normalized. The runtime division then created a
1000-13000× DOUBLE NORMALIZATION inflating column 0 of next_states to
raw-price magnitude.

DIAG_AUX_LABEL diagnostic ground truth (production train-multi-seed-bn42w):
  - features_raw_cuda col 0 mean_abs = 0.443  (clean z-norm at SOURCE)
  - aux_nb_label_buf mean_abs        = 5398   (= 0.443 × inv_vol ~ 13245)
  - ratio matches 1 / vol_normalizer for ES 1-min realised vol ~7.5e-5

This bug caused label_scale=5481 in 50-epoch validation (cancelled
train-multi-seed-bn42w) while smoke ran with smaller window producing
smaller inv_vol → label_scale ~25-432. Both wrong, just different
inflation factors.

What changed:
  - experience_kernels.cu:698-704 block deleted; replaced with header
    comment explaining why. Kernel parameter `vol_normalizer` retained
    in signature with `(void)vol_normalizer;` to silence the
    unused-warning — removing the param would cascade through
    gpu_experience_collector.rs config struct + launcher + per-epoch
    Welford in training_loop.rs (60 lines). Bounded scope: leave the
    pipe wired, gut the consumer.
  - DIAG_AUX_LABEL diagnostic removed per its Fix 28 removal gate
    (gpu_dqn_trainer.rs ~12981 diagnostic block ~165 lines + the
    DIAG_AUX_LABEL_SOURCE_PTRS OnceLock static ~22 lines +
    training_loop.rs populate site ~22 lines).
  - Audit doc Fix 29 entry with audit results + open follow-ups.

Bug-1 contract audit (this commit's exhaustive re-check, 18 sites
classified):
  - 1 ⚠→: experience_kernels.cu:698-704 (this fix)
  - 13 : env-step kernel body, mirror universe, feature mask/noise,
    target reads at col 2 raw_close (Fix-27 already correct), DT
    rewards kernel, curriculum/hindsight/portfolio_sim kernel target
    reads, kernel header docs, PS_PREV_CLOSE state-layout slot
  - 4 ⚠ Stale (deferred — separate triage commits):
    * scripted_policy_kernel.cu:59-65 — seed-phase momentum reads
      state[MARKET_START] as raw_close, but post-Bug-1 it is z-normed
      log-return. Affects seed-phase scripted policy quality only.
    * backtest_plan_kernel.cu:77-100 — val plan_isv reads
      features[bar*feat_dim+0] as raw_close. Corrupts val plan_isv
      slots [PNL_VS_TARGET]/[PNL_VS_STOP].
    * metrics.rs:576 — val_data → window_prices reads target[0] as
      close (clones Fix-27 Bug B at host-side; affects val Sharpe).
    * hyperopt/adapters/dqn.rs:2492 — same target[0] pattern in HPO
      val_close_prices.
  - 1  Ambiguous: dqn_utility_kernels.cu:1089-1093 synthetic feature
    overlay; needs downstream-consumer contract verification.

Verification:
  - SQLX_OFFLINE=true cargo check -p ml --offline (47.87s) clean.
  - SQLX_OFFLINE=true cargo build -p ml --release --offline
    --features cuda (1m 30s) clean; cubin recompiled via nvcc.
  - Next L40S production run should show label_scale ~0.8 (matching
    kernel docstring expectation).

Refs: DIAG_AUX_LABEL diagnostic from Fix 28 in dqn-gpu-hot-path-audit.md
(commit 2683d4637) which captured the ground truth that pinned this
bug. Cancelled validation runs train-multi-seed-p5qzw (label_scale=808)
and train-multi-seed-bn42w (label_scale=5481) both blocked on this —
Fix 27 cleared the host-side variant (Welford reading target[0] as
raw_close); this Fix 29 closes the kernel-side variant. Bug 1 chain
(label_scale=5443 from 4-month-old #193) closes here.
feedback_trust_code_not_docs (the kernel comment said `#13 Vol
normalization` for months — accurate-when-written, stale-after-Bug-1).
feedback_no_partial_refactor does not apply because the kernel
parameter is retained as a no-op, deliberately leaving the
launcher/config-struct contract intact while the consumer is gutted.

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