From 7d29c5ee4869451c765712c7ba98abc242186b5e Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Sun, 26 Apr 2026 21:12:07 +0200 Subject: [PATCH] diag(dqn): kernel printf for first 10 bars of val window 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Captures action_val + decoded dir/mag, max_position, prev_position, position post-trade, actual_dir, actual_mag, trail_triggered, conviction, health, value, max_equity inside backtest_env_step_batch. Localises which step in unified_env_step_core zeros target_position (or position) for non-Hold picks. After tracing the math, every analytical candidate (margin cap, Kelly cap with health-coupled warmup floor, trail stop) returns a positive target at cold start with my fix. val_dir_dist still locks at 0% Long while val_picked_dir_dist shows 17% Long — only direct kernel-side observation can show what's actually clamping. Removed once the gate is identified. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../ml/src/cuda_pipeline/backtest_env_kernel.cu | 15 +++++++++++++++ docs/dqn-wire-up-audit.md | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/ml/src/cuda_pipeline/backtest_env_kernel.cu b/crates/ml/src/cuda_pipeline/backtest_env_kernel.cu index 0e1ed5296..aabaf0115 100644 --- a/crates/ml/src/cuda_pipeline/backtest_env_kernel.cu +++ b/crates/ml/src/cuda_pipeline/backtest_env_kernel.cu @@ -486,6 +486,21 @@ extern "C" __global__ void backtest_env_step_batch( &actual_mag, &trail_triggered ); + + /* DIAG (val-collapse): print first 10 bars of window 0. Captures the + * inputs to unified_env_step_core + its outputs so we can localise + * which step zeros target_position for non-Hold picks. Removed once + * the gate is identified. */ + if (w == 0 && current_step < 10) { + int dir_dbg = action_val / (b1_size * b2_size * b3_size); + int mag_dbg = (action_val / (b2_size * b3_size)) % b1_size; + printf("[VALDIAG step=%d] act=%d dir=%d mag=%d close=%.2f maxpos=%.4f " + "prevpos=%.4f pos_post=%.4f actual_dir=%d actual_mag=%d trail=%d " + "conv=%.3f health=%.3f value=%.2f maxeq=%.2f\n", + current_step, action_val, dir_dbg, mag_dbg, close, max_position, + prev_position, position, actual_dir, actual_mag, trail_triggered, + conviction_core, health_k_batch, value, max_equity); + } (void)prev_position; (void)prev_position_sign; (void)trail_triggered; /* ── Post-trade floor check: catch intra-step breaches ────────── */ diff --git a/docs/dqn-wire-up-audit.md b/docs/dqn-wire-up-audit.md index c16b495c2..cc0263331 100644 --- a/docs/dqn-wire-up-audit.md +++ b/docs/dqn-wire-up-audit.md @@ -259,7 +259,7 @@ P5T5 Phase E (2026-04-26): per-fold reset for `MetricBandsRegistry` regression-d | `attention_backward_kernel.cu` | `gpu_attention.rs`, `gpu_tlob.rs` (reused for grad_norm+Adam kernels) | Wired | Attention backward pass | — | | `tlob_kernel.cu` (`tlob_sdp_forward`, `tlob_sdp_backward`, `tlob_write_states`, `tlob_read_grad_from_states`) | `gpu_tlob.rs` | Wired | D.8 Plan 2 Task 6C — TLOB SDP forward/backward, state scatter/read kernels | — | | `training_guard_kernel.cu` (`training_guard_check_and_accumulate`) | `gpu_training_guard.rs` | Wired | NaN / guard check kernel | — | -| `backtest_env_kernel.cu` (`backtest_env_step`) | `gpu_backtest_evaluator.rs` (`ENV_CUBIN`) | Wired | Backtest environment step | — | +| `backtest_env_kernel.cu` (`backtest_env_step`) | `gpu_backtest_evaluator.rs` (`ENV_CUBIN`) | Wired | Backtest environment step. Diagnostic printf at `backtest_env_step_batch` for first 10 bars of window 0 — tracking val-collapse Long/Short→Flat gate; removed once root cause identified. | — | | `backtest_metrics_kernel.cu` | `gpu_backtest_evaluator.rs` (`METRICS_CUBIN`) | Wired | Backtest metrics reduction | — | | `backtest_plan_kernel.cu` (`backtest_plan_diag_reduce`, `backtest_plan_state_isv`) | `gpu_backtest_evaluator.rs` (`BACKTEST_PLAN_CUBIN`) | Wired | Plan-ISV diagnostic reduction in val. D.6 (Plan 2 Task 6A): `backtest_plan_state_isv` now writes `pisv[6] = remaining_fraction`; stride updated to `SL_PORTFOLIO_PLAN_DIM=7`. | — | | `backtest_forward_ppo_kernel.cu` (`backtest_forward_ppo_kernel`) | `gpu_backtest_evaluator.rs::evaluate_ppo` (`PPO_FORWARD_CUBIN`) | OUT-of-DQN-scope | PPO-path backtest only; correct-as-is | — |