Commit Graph

3743 Commits

Author SHA1 Message Date
jgrusewski
f388a4a9ce feat: rewrite Attention to batched cuBLAS GEMMs
Replace per-sample CUDA kernels (multihead_feature_attention forward,
attention_backward_kernel + tiled weight_grad_reduce) with 12 cached
cublasLtMatmul descriptors for Q/K/V/O projections.

Forward: 4 cuBLAS GEMMs + bias_add + attn_sdp_fwd cubin + attn_layer_norm_fwd cubin
Backward: 8 cuBLAS GEMMs (4 dW + 4 dX) + attn_sdp_bwd + attn_layer_norm_bwd cubins
         + 4 bias_grad_reduce kernels

Eliminates: d_params_per_sample tiling buffer (was 26MB at B=16384),
per-sample backward kernel, weight_grad_reduce kernel, forward_kernel,
backward_kernel, saved_qkv buffer.

Adds: 15 intermediate D*B buffers for projection/gradient flow, SDP scores,
LayerNorm save state. Constructor takes Arc<SharedCublasHandle> instead of
Arc<CudaStream>. CUBLAS_COMPUTE_32F_FAST_TF32. Zero atomicAdd.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 00:02:34 +02:00
jgrusewski
45d8f4661c plan: rewrite Task 9 for child graph architecture
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 23:58:32 +02:00
jgrusewski
d1693930ab spec: child graph architecture — composable sub-graphs instead of flat capture
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 23:54:07 +02:00
jgrusewski
d77faca885 feat: add Attention cuBLAS element-wise cubin kernels
Add 6 new CUDA kernel functions to attention_backward_kernel.cu for the
batched cuBLAS attention path: attn_sdp_fwd, attn_sdp_bwd (sigmoid-gated
feature attention), attn_layer_norm_fwd, attn_layer_norm_bwd (per-sample
LayerNorm with residual), attn_bias_add, and attn_bias_grad_reduce.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 23:46:25 +02:00
jgrusewski
0e13fd1b82 feat: add IQN cuBLAS element-wise cubin kernels
Append 7 new CUDA kernels to iqn_dual_head_kernel.cu for the batched
cuBLAS IQN rewrite: iqn_hadamard_sigmoid, iqn_relu_fwd, iqn_relu_bwd,
iqn_quantile_huber_loss, iqn_hadamard_sigmoid_bwd, iqn_bias_add,
iqn_bias_grad_reduce.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 23:45:51 +02:00
jgrusewski
d799bfafbe feat: rewrite IQL trainer to batched cuBLAS GEMMs
Replace per-sample CUDA kernels (16,384 launches per GEMM) with batched
cublasLtMatmul — ONE call per GEMM layer. Forward pass uses 3 GEMMs +
SiLU + bias_add + expectile_loss. Backward pass uses 5 GEMMs + SiLU
backward + bias_grad_reduce. Eliminates grads_per_sample buffer (was
27MB), tiled backward loop, and weight_grad_reduce kernel.

Constructor now accepts Arc<SharedCublasHandle> instead of bare stream,
sharing the cuBLAS handle with the trunk forward/backward pipeline.
Eight IqlGemmDesc descriptors are cached at init with heuristic algo
selection for CUDA Graph compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 23:38:00 +02:00
jgrusewski
196c390946 feat: add IQL cuBLAS element-wise cubin kernels (silu, expectile_loss, bias)
Appends 5 new kernels to iql_value_kernel.cu for the cuBLAS batched GEMM
rewrite: iql_silu_fwd, iql_silu_bwd, iql_expectile_loss, iql_bias_add,
iql_bias_grad_reduce. Zero atomicAdd, fully deterministic, extern "C" for
cubin export.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 23:21:22 +02:00
jgrusewski
b215976a73 fix: disable temporal ops until cuBLAS aux rewrite — corrupts graph_aux
Temporal ops (mamba2, regime_dropout, isv_temporal_route, risk_budget)
between graph_forward and graph_aux replay corrupt graph_aux on Hopper.
ISV signal update + hold enforcement + aux_frequency still active.
Temporal pipeline will be properly addressed in the cuBLAS aux rewrite.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 22:50:23 +02:00
jgrusewski
6252e93bac fix: disable event tracking around temporal ops — prevents graph_aux corruption
Temporal ops between graph_forward and graph_aux replay use shared
buffers (h_s2). cudarc event recording on these buffers corrupts
the graph_aux replay state on Hopper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 22:44:09 +02:00
jgrusewski
387ce136d7 fix: temporal ops outside graph_forward — ungraphed per-step
Adding mamba2/predictive_coding/regime_dropout/isv_temporal_route/
risk_budget to submit_forward_ops_main broke graph_forward replay
on Hopper (same graph structure issue). Moved to run_full_step
between graph_forward replay and aux ops — ungraphed but still
runs every step, enriching h_s2 before IQL/IQN/attention.

graph_forward keeps the working kernel set (cuBLAS + ISV + plan).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 22:31:22 +02:00
jgrusewski
6d58eaa24e fix: min_hold_bars 10→50 + adaptive hold scales with base
min_hold=10 allowed ~1200 trades/day — costs destroyed the edge.
min_hold=50 (~6.5 min) limits to ~230 trades/day max.

Adaptive extension now scales 0-2× base (was hardcoded 0-8 bars).
With base=50: range is 50-150 bars depending on ISV stability.
Losing positions (negative reward_ema) get base only (50 bars).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 22:20:10 +02:00
jgrusewski
8499b4ee1b feat: wire temporal pipeline + fix hold + add aux_frequency
1. Temporal pipeline in training forward (submit_forward_ops_main):
   - mamba2_step: temporal scan enriches h_s2 with history
   - compute_predictive_coding_loss: temporal smoothness
   - apply_regime_dropout: regime-conditioned dropout
   - launch_isv_temporal_route: per-feature temporal weights
   - risk_budget_forward: risk budget from h_s2
   These were only in the monitoring path (reduce_current_q_stats),
   never in the actual training forward. The model trained without
   any temporal context.

2. ISV signal update after each adam step:
   update_isv_signals() called after mamba2 backward, reads pinned
   loss/grad_norm/Q-mean and updates the 12-element ISV vector.
   Was never called during training — ISV signals stayed at zero.

3. Backtest min_hold fixed:
   eval_min_hold was hardcoded 0 — no hold enforcement in validation.
   Now uses config.min_hold_bars.

4. Backtest ISV signals:
   Passes frozen ISV signals from last training step to validation
   backtest for adaptive hold enforcement.

5. aux_frequency parameter (default 4):
   IQL, IQN, attention, CQL run every 4th step instead of every step.
   ~4x faster epochs. graph_forward still runs every step.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 22:15:57 +02:00
jgrusewski
f9aedb1b05 fix: use split graphs (graph_forward + graph_aux) — graph_mega replay hangs
graph_mega captures spectral+forward+aux in one graph. Replay hangs
on Hopper even with cudarc wrapper. Split graphs work: graph_forward
(from GpuDqnTrainer) + graph_aux (cudarc wrapper). Both graphed,
2 launches per step instead of 1.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 21:15:39 +02:00
jgrusewski
1aadf7c8d3 feat: graph_mega re-enabled via cudarc wrapper — full single-launch pipeline
Rewrote capture_graph_mega to use cudarc's begin_capture/end_capture
instead of raw cuda_sys. Same fix that resolved graph_aux hang.
All graph types (graph_mega, graph_aux, graph_spectral) now use
cudarc wrapper consistently. Falls back to split graphs if mega fails.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 20:56:39 +02:00
jgrusewski
2aa955f0dd feat: log full validation backtest metrics — Sharpe + Sortino + WinRate + MaxDD + Trades + Calmar
compute_validation_loss only returned Sharpe, discarding all other
backtest metrics. Now logs the complete picture on every epoch so we
can verify if the learning system actually works on out-of-sample data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 20:48:35 +02:00
jgrusewski
30e94446cd fix: compute bars_per_day from fxcache timestamps — correct annualization
bars_per_day was hardcoded 390 (1-minute candles) but we use MBP-10
imbalance bars (~7500/day). All Sharpe/Sortino/return annualization
was off by sqrt(7500/390) ≈ 4.4×.

Now computed from actual fxcache timestamps:
  bars_per_day = total_bars / (trading_days from timestamp span)

Propagates to: val_Sharpe, train_Sharpe, financials, backtest evaluator.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 20:46:04 +02:00
jgrusewski
0c06aeca5a fix: replace raw cuda_sys graph capture with cudarc wrapper
Root cause: capture_graph_aux and capture_graph_spectral used raw
cuda_sys::cuStreamBeginCapture_v2 / cuStreamEndCapture, bypassing
cudarc's internal state tracking. Mixing raw FFI with cudarc's
managed context corrupts the captured graph, causing replay hangs.

capture_training_graphs (GpuDqnTrainer) always used cudarc's
stream.begin_capture() / stream.end_capture() and worked. Now all
graph captures use the same cudarc wrapper.

All graphs re-enabled: graph_forward, graph_forward_ddqn, graph_adam,
graph_spectral, graph_aux. Full graphed pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 19:37:32 +02:00
jgrusewski
8f2f72430e fix: also skip graph_aux CAPTURE — capture itself corrupts stream state
graph_aux was still being captured (then not replayed). The capture
process uses cuStreamBeginCapture which corrupts cudarc's internal
state, causing the NEXT graph_forward replay to hang on step 2.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 19:25:31 +02:00
jgrusewski
e03da19051 fix: run aux ops ungraphed — graph_aux replay hangs on Hopper
graph_forward replays fine (step 1 completes in 3.8s).
graph_aux replay hangs on step 2. All aux ops work ungraphed
(confirmed by diagnostic run). Keep graph_forward graphed for
speed, run aux ops directly on stream until root cause found.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 19:11:29 +02:00
jgrusewski
92b61c5d96 fix: disable_event_tracking in capture_graph_aux and capture_graph_spectral
Root cause: cudarc's device_ptr() records CudaEvents during graph
capture, silently corrupting the graph. capture_training_graphs
(GpuDqnTrainer) already disabled event tracking, but capture_graph_aux
and capture_graph_spectral (FusedTrainingCtx) did not.

With state_dim=88 this was harmless. With state_dim=96, different
buffer layouts trigger event recording paths in IQL/IQN/attention,
producing a corrupted graph that hangs on replay.

Diagnostic confirmed: all ops complete ungraphed, graph_aux capture
returned CUDA_ERROR_STREAM_CAPTURE_INVALIDATED.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 18:54:33 +02:00
jgrusewski
cb3c282188 diag: sync after every aux op to find exact hanging kernel
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 18:24:32 +02:00
jgrusewski
0fb4c6803f test: run ungraphed to isolate graph vs kernel bug
Skip all CUDA Graph capture — run cuBLAS + kernels directly on stream.
If this works, the hang is graph replay. If not, it's a kernel bug.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 17:14:16 +02:00
jgrusewski
9c6c516d21 Revert "test: revert experience_kernels.cu to working SHA — cubin isolation test (PUSHED)"
This reverts commit 3201123ae3.
2026-04-17 17:05:34 +02:00
jgrusewski
3201123ae3 test: revert experience_kernels.cu to working SHA — cubin isolation test (PUSHED)
If graph_forward works with the working SHA cubin but hangs with
current cubin, nvcc register allocation changes from new/modified
kernels in the same compilation unit affect graph-captured kernels.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 17:03:23 +02:00
jgrusewski
f0ec0a74d1 fix: use CU_STREAM_CAPTURE_MODE_GLOBAL for cuBLAS graph capture on Hopper
NVIDIA docs: cuBLAS with cublasLtMatmul requires GLOBAL capture mode,
not THREAD_LOCAL. THREAD_LOCAL allows cuBLAS internal cudaMallocAsync
to escape the capture scope on sm_90, corrupting the graph.

Also reverts all previous workaround attempts (workspace=0, ldb padding,
bn_concat stride) — the capture mode was the root cause.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 16:48:37 +02:00
jgrusewski
ab8145875c fix: cuBLAS workspace=0 forces graph-safe algorithms on Hopper
Workspace-using cublasLt algorithms on sm_90 employ TMA (Tensor Memory
Accelerator) internally. TMA state is not captured by CUDA Graphs,
causing replay hangs. Setting MAX_WORKSPACE_BYTES=0 in the algorithm
heuristic forces workspace-free algorithms guaranteed graph-compatible.

Applied to all 4 GEMM descriptor creation paths:
- batched_forward.rs: cached + uncached + relu_bias
- batched_backward.rs: cached

Removed ws_size parameter from descriptor creation functions — no
longer needed. ~5-10% GEMM perf cost vs full workspace, negligible
vs total step time.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 16:20:56 +02:00
jgrusewski
3462743c59 fix: disable graph_mega — use split graphs (graph_forward + graph_aux)
graph_mega uses raw cuda_sys FFI for capture which hangs on Hopper
with state_dim=96. Split graphs use cudarc's begin/end_capture which
handles event tracking correctly. 3 launches vs 1 per step — ~2µs
overhead, negligible vs ~160ms step time.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 15:53:53 +02:00
jgrusewski
0c247535b9 fix: pad bn_concat stride to 128 — forces graph-compatible cuBLAS algo on Hopper
state_dim 88→96 changed s1_input_dim (62→70), causing cuBLAS
heuristic to pick a CUDA Graph-incompatible algorithm on sm_90.
Padding bn_concat's leading dimension to 128 (CUTLASS K-tile)
forces tile-aligned algorithms that work in graph replay.

Changes:
- batched_forward.rs: s1_ldb always pad128 when bottleneck active
- gpu_dqn_trainer.rs: bn_concat_buf allocated with padded stride
- dqn_utility_kernels.cu: bn_tanh_concat_kernel takes concat_stride param

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 15:42:56 +02:00
jgrusewski
4483bf0f93 fix: disable event tracking during graph_mega capture — fixes H100 hang
capture_graph_mega was missing disable_event_tracking() that
capture_training_graphs already had. With state_dim=96, cudarc's
device_ptr() calls inside cuBLAS record CudaEvents during graph
capture, which are disallowed and corrupt the graph on Hopper.

Also reverts c51_grad/c51_loss/dqn_utility kernel files to working
SHA — removes all symptom-chasing changes that were red herrings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 15:25:06 +02:00
jgrusewski
996be07a54 Revert "test: revert experience_kernels.cu to working SHA — cubin isolation test"
This reverts commit 18c0107ce5.
2026-04-17 15:22:49 +02:00
jgrusewski
18c0107ce5 test: revert experience_kernels.cu to working SHA — cubin isolation test
Temporarily reverts ALL experience_kernels.cu changes to match 11b1a1ca9
exactly. If graph_mega works, the cubin-level changes (new plan_noise_inject
kernel + modified experience_state_gather/env_step bodies) are affecting
register allocation for graph_mega kernels on Hopper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 15:13:15 +02:00
jgrusewski
924aaa775e fix: restore c51_grad 19th param + HER (32,1,1) — match working SHA graph_mega
graph_mega on Hopper requires EXACT node structure match with working
SHA 11b1a1ca9. Two remaining differences caused the hang:
- c51_grad: 18→19 params (restored unused q_mean_ema_ptr)
- HER relabel: (1,1,1)→(32,1,1) (restored warp-parallel launch)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 14:58:58 +02:00
jgrusewski
709fffe923 fix: revert c51_loss_reduce to (1,1,1) — same Hopper graph hang class
The warp-parallel (32,1,1) change to c51_loss_reduce caused the same
hang as isv_feature_gate: changing block_dim inside graph_mega alters
CUDA Graph node structure on Hopper's TMA scheduler. Must stay (1,1,1).

Also: batch_size 8192→16384, gpu_n_episodes 1024→4096, num_atoms 51→52
to align h100.toml with dqn-production.toml.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 14:46:15 +02:00
jgrusewski
8b51588d97 fix: revert isv_feature_gate to in-place — fixes graph_mega hang on H100
Root cause: the read→write split (save_h_s2 → gated_h_s2_buf) removed the
WAW dependency that cuBLAS's internal TMA async ops on Hopper (sm_90)
require for correct CUDA Graph replay ordering. In-place modification
restores the dependency chain: cuBLAS forward → isv_feature_gate → backward.

Also upgrades c51_loss_reduce from sequential to warp-parallel reduction
(32 threads, __shfl_down_sync) — ~32× faster for B=8192.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 14:29:52 +02:00
jgrusewski
0d86c5e283 fix: revert ALL block_dim (32,1,1) back to (1,1,1) — eliminates ALL race conditions
The block_dim (1,1,1) → (32,1,1) change introduced race conditions
in every single-thread kernel that writes to shared scalars.
Fixed stochastic_depth_rng and c51_loss_reduce individually, but
there may be more. Safest fix: revert ALL to (1,1,1) matching the
working 11b1a1ca9. These kernels are tiny (single-thread work) —
the 32-thread "optimization" wasted 31 threads and added races.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 13:34:02 +02:00
jgrusewski
ca7dfa9f08 fix(critical): c51_loss_reduce missing threadIdx guard — 32-way write race
SECOND race condition from block_dim (1,1,1)→(32,1,1) change:
c51_loss_reduce had 32 threads all computing sum and writing to
total_loss[0] simultaneously. On sm_90 (H100) → corrupted loss →
NaN in C51 gradient → graph_mega replay hangs.

This kernel runs INSIDE graph_mega (submit_forward_ops_main),
called twice (MSE reduce + C51 reduce). Both corrupted.

Also fixed stochastic_depth_rng in previous commit (same issue,
runs in pre-replay).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 13:19:39 +02:00
jgrusewski
c7fa67159c fix(critical): stochastic_depth_rng missing threadIdx guard — 32-way race
Root cause of graph_mega hang: stochastic_depth_rng kernel had NO
threadIdx.x guard. When block_dim changed from (1,1,1) to (32,1,1),
all 32 threads wrote to scale_buf[0..2] and rng_state[0] simultaneously.
Race condition → corrupted stochastic depth scales → NaN in cuBLAS
forward → C51 Bellman projection diverges → infinite loop → hang.

Fix: if (threadIdx.x != 0) return; — single writer for 3 scale + 1 rng.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 12:57:18 +02:00
jgrusewski
2c8967ad96 feat: compute-sanitizer support in Argo training workflow
Usage: ./scripts/argo-train.sh dqn --baseline --epochs 2 --sanitizer memcheck
       ./scripts/argo-train.sh dqn --baseline --epochs 1 --sanitizer synccheck

Tools: memcheck (OOB, uninitialized), racecheck (data races),
synccheck (__syncthreads divergence/deadlocks).
10-100x slower — use with 1-2 epochs for debugging.
Detects exact kernel + line causing GPU hang.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 12:24:23 +02:00
jgrusewski
88307b8e3b test: remove plan_noise_inject from graph_mega — isolating hang cause
plan_noise_inject is the ONLY new kernel inside graph_mega vs the
working 11b1a1ca9. Everything else is identical (submit_forward_ops_main,
submit_aux_ops, capture_graph_mega). If this fixes the hang,
plan_noise_inject is incompatible with graph_mega on sm_90.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 11:58:08 +02:00
jgrusewski
f264ba00cb fix: ISV+plan kernels BACK inside graph_mega (matching working 11b1a1ca9)
Reverted to the structure that WORKED on H100: ISV kernels inside
submit_forward_ops_main (captured in graph_mega). Removed duplicate
pre-replay calls. The working version had ISV in graph_mega — removing
them was wrong. Added plan_noise_inject to the same block.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 11:53:29 +02:00
jgrusewski
2f4a669392 fix: revert recursive_confidence_backward to original warp+block reduction
The per-weight-element rewrite (2 blocks, B=8192 loop) caused
graph_mega replay to hang on H100 sm_90. The original warp+block
reduction (ceil(B/256) blocks, atomicAdd per block) worked on H100.
Reverted to working version. Remove duplicate fill_gamma_buf from
pre-replay (already inside graph_mega).

Root cause investigation pending — the per-weight-element pattern
works on sm_80 (RTX 3050) but hangs on sm_90 (H100).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 11:35:28 +02:00
jgrusewski
5ce0454ceb fix(critical): recursive_confidence_backward — per-weight-element, zero syncthreads
ROOT CAUSE of graph_mega hang: the warp+block reduction in
recursive_confidence_backward had 256 iterations of __syncthreads
inside a loop (2 syncs × SH2=256 = 512 barriers per thread).
This overwhelmed the CUDA graph node scheduler on H100.

Fix: converted to per-weight-element pattern (same as other
deterministic backward kernels). One thread per weight (SH2+1=257),
loops over B samples. Zero __syncthreads, zero atomicAdd,
zero shared memory. Graph-mega safe.

Grid: ceil(257/256)=2 blocks (was ceil(8192/256)=32 blocks).
Massive resource reduction + deterministic + graph compatible.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 10:54:50 +02:00
jgrusewski
341346af09 fix: ISV+plan kernels run pre-mega-replay, not inside graph_mega
NVRTC-compiled ISV kernels conflict with cuBLAS GEMM internal stream
scheduling when captured in the same CUDA Graph as cuBLAS ops.
Moving ISV+plan to pre-replay phase: they run BEFORE graph_mega
replay on every training step. Their outputs (gamma_mod_buf,
branch_gate_buf, gated_h_s2_buf, predicted_error_buf, plan_params_buf)
are stable device buffers consumed by the captured graph.
Same result, no deadlock. ISV updates every step (not every 50).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 10:36:23 +02:00
jgrusewski
99f1687972 fix(critical): gated_h_s2_buf — stop in-place modification of save_h_s2
ROOT CAUSE of graph_mega hang: isv_feature_gate modified save_h_s2
in-place. cuBLAS backward (later in graph_mega) reads save_h_s2
expecting ORIGINAL (pre-gate) values for correct gradient computation.
The gated values corrupted gradients → GPU hang.

Fix: separate buffers. save_h_s2 preserved for backward (unmodified).
gated_h_s2_buf receives ISV-gated output for branch heads.
recursive_confidence_forward, trade_plan_forward, risk_budget_forward
now read from gated_h_s2_buf.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 10:17:41 +02:00
jgrusewski
8832268a54 fix: single-thread kernels → full warp (32 threads) for graph_mega
CUDA Graph mega capture hangs with block_dim=(1,1,1) kernels.
Changed all ISV/plan single-thread launches to block_dim=(32,1,1).
Kernels already guard with if(threadIdx.x != 0) return — only
thread 0 does work, rest idle. Full warp is graph scheduler
friendly. Local smoke test passes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 09:56:04 +02:00
jgrusewski
055bcbcf46 feat(plan): plan noise injection for temporal diversity (Phase 2-D simplified)
plan_noise_inject kernel: ±5% Philox-seeded multiplicative noise on
plan_params [B, 6] after forward pass. Creates temporal diversity —
model sees slightly different plans each step, learns robust behavior.
Called in both reduce_current_q_stats and submit_forward_ops_main.
Full 3-run spatial ensemble deferred to follow-up.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 09:46:18 +02:00
jgrusewski
98f1efb5f8 fix: restore ISV+plan kernels in graph_forward — smoke test passes
ISV kernels back inside submit_forward_ops_main (graph capture).
Local smoke test: PASS (training_sharpe=3.773). graph_forward
capture works with ISV single-thread kernels. If H100 graph_mega
hangs, the issue is mega-specific, not ISV compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 09:42:20 +02:00
jgrusewski
5836280a34 cleanup: remove AutoBatchSizer — batch_size from config is source of truth
AutoBatchSizer didn't account for experience collector VRAM, causing
OOM on H100 with state_dim=96. batch_size is configured per GPU
profile (h100.toml=8192, rtx3050.toml=64). No auto-sizing needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 09:35:16 +02:00
jgrusewski
d144171b92 feat(plan): track intra_trade_max_pnl in ps[21] for hindsight labels (N18)
Max unrealized P&L tracked each bar during trade. Enables hindsight
plan learning: compare plan's profit_target vs actual max P&L.
The plan head learns optimal targets from what was achievable.
Reset on trade entry, reversal, and episode hard/soft reset.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 09:35:08 +02:00
jgrusewski
614d4dbf84 cleanup: remove ofi_enabled/ofi_pre conditionals — OFI always on
OFI (20 microstructure features) is unconditionally enabled.
mbp10_data_dir always set. state_dim unconditionally 96.
Removed dead else branches (ofi_dim=0, state_dim=72).
Simplifies 7 files across the workspace.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 09:28:49 +02:00