states_buf has stride pad128(state_dim) for CUTLASS alignment. The
concat_ofi kernel was reading with stride state_dim → OOB for sample 1+.
With state_dim=50, pad=128: sample 1 OFI at offset 128+42=170, but
kernel read at 50+42=92 (sample 0 padding area). Silent data corruption.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adam kernel changed from float lr to const float* lr_ptr. The CUDA graph
captures the pointer (not the value). CPU writes new LR to lr_pinned each
epoch, kernel reads current value on replay. Eliminates 30s × 200 = 100 min
graph recapture overhead from cosine LR warm restarts.
Selectivity and denoiser Adam launchers share aux_lr_pinned (fixed 1e-4)
to satisfy the updated const float* kernel signature without graph impact.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Denoiser: q_denoise_backward kernel computes MSE gradient vs target
network Q-values, backprops through 2 FC-SiLU-FC steps. Separate Adam
at LR=1e-4. Runs after main backward in training step.
xLSTM: qlstm_train_step kernel computes prediction loss (context[0]
vs prev_q_mean), backprops through output gate + retrieval. SGD update
in-place at LR=1e-4. Runs after qlstm_step in reduce_current_q_stats.
Both fully on GPU. Zero untrained components remaining.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Renamed: q_bf16→q_host, bf16_uniform→uniform, host_bf16→host,
bf16_raw→raw, bf16_pred→pred, raw_bf16_ptr→raw_f32_ptr (removed dup).
Removed stale comments: "no bf16 NaN risk", "no bf16 overflow",
"no bf16 precision loss", "BF16 bias+relu kernels".
Removed redundant .to_vec() clones from test helpers.
Also includes precommit fixes:
- CRITICAL: backward_full uses padded_byte_offset for ALL offsets
- HIGH: Graph + xLSTM params documented as fixed-init by design
- LOW: Diffusion denoiser K=3→K=2 (eliminates ping-pong copy)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
CRITICAL: backward_full manual offset calculations replaced with
padded_byte_offset for ALL 24 tensor offsets. Eliminates brittle
manual computation that was a regression risk.
HIGH: Graph message passing + xLSTM params documented as fixed-init
by design. Graph edges encode domain knowledge. xLSTM context is
a learned-at-init projection. Training deferred to future work.
LOW: Diffusion denoiser changed from 3 to 2 steps (eliminates
ping-pong DtoD copy). raw_bf16_ptr removed (dead code).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
liquid_tau_rk4_step kernel: adaptive Euler/RK4 based on xLSTM context norm.
per_branch_q_gap_ema and liquid_mod moved from pinned/CPU to CudaSlice device buffers.
Zero CPU compute in training dynamics. Zero pinned memory for liquid tau.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
8 cubic B-spline basis functions per gate neuron + residual connection.
Spline coefficients initialized to uniform 0.125 (flat 0.5 gate).
kan_gate_combine replaces glu_combine in forward.
kan_gate_backward replaces glu_backward in backward.
9,216 new parameters (4 x AH x 9).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dir→mag, dir→ord, mag→urg, ord→urg gated message passing on 12 Q-values.
Runs after Q-attention for structural coordination. Separate Adam (LR=1e-4).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Component 10: reset_branch_adam_momentum zeros m/v for indices 8-41 only.
Tried before full rewind as lightweight plateau-breaking fix. Full rewind
now delayed by 3 epochs (plateau_threshold + 3) to let the reset take effect.
Component 11: spread_amplifier = target_q_gap / current_q_gap, multiplied
into liquid_mod after the liquid ODE update in update_liquid_tau.
Amplifies spread when Q-gap is below target (10 * eval_q_std_ema, min 0.3).
Component 12: cosine LR schedule with T=20 warm restarts (SGDR). LR decays
base→10% of base then resets each T epochs. scale_adam_momentum(0.5) at
restart preserves gradient direction while reducing Adam momentum magnitude.
set_lr() invalidates graph_adam for re-capture with the new LR.
Fixes Adam momentum cancellation observed in train-vpb4w epoch 23-28.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extracts Q_10th/Q_50th/Q_90th from C51 CDF per action. Blends using
iqn_readiness: optimistic (Q_90th) when exploring, pessimistic (Q_10th)
when exploiting. OFU principle — uncertain actions naturally explored.
E[Q] still computed for monitoring and loss. Zero extra parameters.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Q-gap-only detection missed the train-vpb4w plateau (6 frozen epochs
without trigger). Now detects EITHER Q-gap velocity ≈ 0 OR val_Sharpe
identical to previous epoch (|delta| < 0.01). Adds info! logging showing
plateau_epochs counter, which detector fired, and checkpoint count.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two-phase kernel: q_mean_reduce computes global mean, q_mean_subtract
centers all Q-values. Runs after compute_expected_q, before Q-attention.
Fixes Q-mean drift 0→+0.47 observed in train-vpb4w.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Observed train-vpb4w freeze at epoch 23 (val_Sharpe=51.11):
- avg_grad=10.0 (nonzero!) but Q-stats FROZEN for 4+ epochs
- Root cause: Adam momentum converged to fixed point, not zero gradient
Component 10: Targeted Adam momentum reset for branch weights only
(indices 8-41). Lighter than full rewind, preserves trunk convergence.
Component 11: Q-gap target attractor for spread gradient. Amplifies
spread when Q-gap is below target, reduces when above. Prevents
spread from being too weak at high Q-gap levels.
Component 12: Cosine LR schedule with warm restarts (T=20 epochs).
LR decay prevents overshoot, restart jumps break fixed points.
Half-momentum at restart preserves gradient direction.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
entropy_coeff ramps when atom utilization EMA drops below 50%.
Linear ramp: 0 extra at 50%+, 1× base_entropy extra at 0%.
Prevents distributional collapse 100%→20% observed in train-vpb4w.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Task 10: q_mean_reduce + q_mean_subtract two-phase kernel. Zero params.
Fixes Q-mean drift 0→+0.47 from bootstrapping bias.
Task 11: Adaptive entropy_coeff based on utilization_ema. Zero params.
Fixes atom utilization collapse 100%→20%.
Execution order: 10, 11, then 1-9.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Observed in train-vpb4w (live H100 run):
- Q-mean drifts 0→+0.47 over 18 epochs (bootstrapping bias)
- Atom utilization drops 100%→20% (distributional collapse)
- val_Sharpe peaks 54.59 then decays to 31.52
Component 8: Mean-center Q-values before action selection pipeline.
Zero params, preserves ranking, prevents drift accumulation.
Component 9: Adaptive atom entropy regularization. Ramps entropy_coeff
when utilization drops below 50%. Uses existing c51_grad_kernel param.
Both are zero-param fixes moved to top of implementation order.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Softmax over SH2=256 features gives mask[i]=1/256=0.004 per feature,
collapsing the input signal 256×. Sigmoid gives mask[i]∈(0,1) independently
per feature. At W_vsn2=0 init: sigmoid(0)=0.5 → h_masked = 0.5*h_s2.
Shared memory reduced: SH2+R (no mask buffer needed, sigmoid is inline).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sigmoid(Q·K/√d) × V is a per-head feature gate, not standard multi-head
attention (seq_len=1 makes softmax trivial). Comments now accurately
describe the learned gating mechanism and its purpose.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
LOW 1: sel_t_buf CudaSlice + per-step memcpy_htod → sel_t_pinned
device-mapped. Zero copies, GPU reads directly from host memory.
LOW 2: is_q_gap_frozen uniform [q_gap; 4] → actual per-branch Q-gaps
from 48B DtoH readback in reduce_current_q_stats. Each branch now
independently detected as frozen/unfrozen. Liquid tau and trajectory
backtracking use real per-branch velocities.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mag_concat now uses vsn_masked (feature-selected) instead of raw h_s2
for its first SH2 columns. strided_scatter kernel writes tight [B,SH2]
vsn_masked into wide [B,SH2+3] mag_concat preserving Q_dir in last 3.
launch_mag_concat → launch_mag_concat_from with explicit source ptr.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
CRITICAL: backward_full used state_dim for goff_b_s1 offset but
compute_param_sizes uses s1_input_dim (smaller with bottleneck active).
All downstream gradient offsets were misaligned. Fixed: sd → s1d.
HIGH: q_attn_params used alloc_f32 (potentially non-zero) instead of
alloc_zeros. Cross-branch Q-attention residual connection needs near-zero
init for stability. Fixed: alloc_zeros.
MEDIUM (deferred): VSN masking bypassed for magnitude branch — mag_concat
reads raw h_s2 instead of vsn_masked. No impact while W_vsn2 is zero-init
(identity mask). Will fix when VSN backward is wired.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
selectivity_forward: sigmoid(dot(W_sel, h_s2) + b_sel) per sample.
selectivity_backward: BCE gradient on (sel, per_sample_loss/mean_loss).
Separate Adam at LR=1e-4. PER priority integration deferred.
Also fixes kernel names (selectivity_gate_fwd→selectivity_forward,
selectivity_gate_bwd→selectivity_backward) to match experience_kernels.cu.
Adds sel_norm_buf, sel_norm_partials, sel_clip_buf, sel_t_buf fields
needed by dqn_adam_update_kernel. Wired into run_full_step after main
Adam step with mean_loss=1.0 placeholder and non-fatal error handling.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c51_grad_kernel reads liquid_mod[d] per branch instead of spread_velocity[0].
4 per-branch Q-gap EMAs with adaptive alpha drive continuous-time ODE.
Fast branch learning → large tau → slow adaptation → don't overshoot.
Stuck branch → small tau → fast adaptation → push harder.
spread_velocity infrastructure removed (-30 lines).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
launch_q_attention runs 2-head attention on 12 Q-values [B, 12].
Wired into reduce_current_q_stats after compute_expected_q.
Also fixes kernel function name: q_cross_branch_attn → cross_branch_q_attention.
Experience collection deferred — uses raw Q-values for now.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d_h_bd → glu_backward → d_value + d_gate_pre. Two weight gradient
GEMMs per branch (value + gate). Upstream gradient sums both paths.
VSN backward DEFERRED (W_vsn init to identity, zero gradient for now).
Gradient flows to gate weights at indices 34-41.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Checkpoint ring buffer ranked by improvement rate, plateau detection
via liquid tau velocity, informed perturbation cycle (Adam reset,
shrink-perturb, temp boost, LR×2), depth-limited rewind. ~150 lines
in training_loop.rs, zero CUDA changes. Recovers from plateaus that
prevention mechanisms (spread gradient, liquid tau) fail to avoid.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
param_sizes[12] grows by 3*adv_h for direction conditioning.
mag_concat_buf [B, SH2+3] and d_mag_concat_buf allocated.
mag_concat_qdir and strided_accumulate kernels loaded.
launch_mag_concat and accumulate_d_h_s2_from_concat methods added.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mag_concat_qdir: computes direction E[Q] from softmax over C51 atoms,
normalizes by delta_z for matched gradient scale, concatenates with h_s2
to produce [B, SH2+3] input for magnitude branch FC.
strided_accumulate: extracts first SH2 columns from d_mag_concat [B, SH2+3]
into d_h_s2 [B, SH2] with beta accumulation for backward pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Raw E[Q] ~ 0.1 while h_s2 ~ 1.0 post-ReLU. Without normalization,
Q_dir columns learn 10x slower. Dividing by delta_z scales to ~1-10.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>