Files
foxhunt/crates
jgrusewski eeeb4e0a90 feat(generalization): #31 bottleneck — experience collector + backward kernels
Complete temporal causal bottleneck implementation across all GPU paths:

Experience collector (data collection):
- Loads bn_tanh_concat_kernel from utility cubin
- Bottleneck GEMM + tanh + concat runs per timestep before Q-forward
- Same 2D compression as training → consistent Q-values for action selection
- Buffers: exp_bn_hidden [N, bn_dim], exp_bn_concat [N, concat_dim]

Backward pass (gradient kernels):
- bn_tanh_backward_kernel: d_bn = d_concat * (1 - tanh^2)
  Reads saved tanh values from forward, applies derivative
- bn_bias_grad_kernel: db_bn = sum(d_bn, dim=0) via atomicAdd
- dW_bn via cuBLAS launch_dw_only: d_bn^T @ states[:, :market_dim]
- All gradients accumulate into grad_buf at tensors 20-21

The 2D bottleneck is now end-to-end:
  Forward: states → W_bn GEMM → tanh → concat → h_s1 → ... → Q-values
  Backward: d_logits → ... → d_h_s1 → d_concat → d_bn (tanh') → dW_bn, db_bn
  Experience: states → bottleneck → Q-forward → action selection → env step

Set bottleneck_dim=2 to enable. Default: 0 (disabled, backward compatible).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 09:54:47 +02:00
..