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>
This commit is contained in:
jgrusewski
2026-04-18 00:02:34 +02:00
parent 45d8f4661c
commit f388a4a9ce
2 changed files with 711 additions and 163 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -541,7 +541,7 @@ impl FusedTrainingCtx {
num_heads: 4,
batch_size,
};
let gpu_attention = match GpuAttention::new(stream.clone(), attn_config) {
let gpu_attention = match GpuAttention::new(Arc::clone(trainer.shared_cublas()), attn_config) {
Ok(attn) => {
info!(
hidden_dim = shared_h2,