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>
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>
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>
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>
In-place ranking races across blocks: block X writes shaped rewards[i]
before block Y loads it in tile scan. __syncthreads is block-local.
Fix: read from rewards_out (raw), write to gpu_batch.rewards (clone).
The DtoD clone from collect_experiences_gpu provides the output buffer.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Four improvements to the training pipeline:
1. Asymmetric spread gradient: challenger action (adjacent to taken) gets
pushed UP at half strength instead of DOWN. Creates a two-horse race
instead of single-action monopoly.
2. Per-branch spread scaling: spread_grad *= branch_scale. Direction branch
(high impact) gets more spread than urgency (low impact).
3. Distributional variance position sizing (Layer 4): Var[Q] = E[Z²] - E[Z]²
computed in compute_expected_q. Position scaled by 1/(1+sqrt(Var[Q_taken])).
High uncertainty → smaller position. Kelly criterion from C51 atoms.
4. Reward std guard: skip rank normalization when observed_reward_std ≈ 0
(epoch 0). Prevents zeroing all rewards before std is observed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds a spread gradient to the C51 advantage logits that pushes the
taken action's distribution toward higher atoms and non-taken toward
lower. Scale = inv_batch * delta_z (adaptive to per-sample atom
resolution, zero hardcoded constants).
This gradient is ORTHOGONAL to the Bellman equation — it depends on
atom position, not target match. Active on ALL samples, providing
perpetual pressure to differentiate Q-values even when the C51
cross-entropy gradient vanishes at convergence. Prevents the Q-gap
plateau where all actions have identical Q-values.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Philox seed used batch_size+sample_id (constant across steps) so the
same action was always sampled for the same sample → at the fixed point,
identical target every step → zero gradient. Now uses t_buf (Adam step
counter, device-mapped, increments every step). Each training step
samples a DIFFERENT action per sample → target is truly stochastic →
gradient variance prevents convergence.
Also moves philox_uniform to common_device_functions.cuh for reuse.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deterministic softmax mixture produced a fixed target that the model
matched exactly → zero gradient → Q-gap frozen at 0.167, val_Sharpe
frozen at -5.62 from epoch 22. Stochastic sampling picks ONE action
per sample from the softmax weights. Expected target over many steps
is identical (unbiased) but per-step target varies → model can never
match a moving target → perpetual gradient → no convergence trap.
Also moves philox_uniform to common_device_functions.cuh so all
kernels can use it.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Floor = max(|mean_Q| * 0.01, 1e-6). At Q-mean=0.005: floor=5e-5.
At Q-mean=1.0: floor=0.01. Fully adaptive, zero hardcoded constants.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
tau=Q_gap/3 gave 20:1 weight ratio (95%/4%/1%), making the target
essentially argmax. Once the online distribution matched this sharp
target, cross-entropy gradient vanished → Q-gap froze at 0.158,
val_Sharpe locked at 2.40 from epoch 22.
tau=Q_gap gives a CONSTANT e:1 ≈ 2.72:1 ratio (63%/23%/14% for 3
actions) regardless of Q-gap magnitude. The target always maintains
meaningful mixture → perpetual gradient pressure → Q-values keep
evolving. Scale-invariant: the softmax ratio depends only on relative
Q-differences, not their absolute magnitude.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All 4 branches (dir, mag, order, urgency) now use Boltzmann sampling
in eval mode instead of argmax. argmax(softmax(Q/tau)) = argmax(Q) —
temperature is meaningless with argmax. Every state picked the same
winning action → identical trades → Sharpe=0.00 from epoch 8 onward.
Boltzmann sampling with Philox seed gives deterministic but
action-diverse evaluation. When Q-values differentiate, Boltzmann
naturally sharpens toward the best action.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Softmax weights used implicit tau=1, producing near-uniform weights
when Q-gap=0.06: exp(0.06)≈1.06 → weights [0.35, 0.33, 0.32].
The mixture averaged all distributions → zero gradient to differentiate
actions → Q-gap frozen → val_Sharpe locked at 0.00 after epoch 19.
Now uses tau = max(Q_gap/3, 0.001). With Q-gap=0.06 and tau=0.02:
exp(0.06/0.02) = exp(3) ≈ 20:1 weight ratio between best and worst.
The 0.001 floor means even tiny Q-differences produce sharp weights,
preventing the uniform-averaging fixed point.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
read_total_loss() calls cuStreamSynchronize which is illegal during
CUDA Graph stream capture. Was inside submit_aux_ops (captured in
graph_mega/graph_aux). Moved to Step 4 (conditional ops outside graph).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
branching_action_select exposure head used hard argmax while order/
urgency used Boltzmann. experience_action_select eval mode used pure
argmax for direction. Both replaced with Boltzmann softmax:
tau = max(Q_max - Q_min, 0.01)
When Q-values differentiate: converges to argmax. When flat: spreads
evenly. Eval mode takes argmax of softmax probs (deterministic).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two fixes:
1. Width: half = max(10*q_gap, 3*q_std, 0.1) instead of fixed 3*q_std+1.0.
With q_gap=0.06 and 51 atoms, gives ~5 atoms of action resolution
(was 1.5 atoms with the 1.0 floor). No more catastrophic -40 dips
from atom underresolution.
2. Baseline: uses q_std_ema (proportional to natural Q oscillation)
instead of fixed 0.01. Normal Q-oscillation (±q_std) no longer
triggers aggressive alpha — only abnormal shifts do.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>