/** * attention_block.ts – Causal Multi-Head Self-Attention Block. * * Intentionally simple for WebGPU — naive O(L²) tiled attention, * no Flash-Attention dependency. Suitable for hybrid (Jamba/Zamba) schedules * where a few attention layers interleave with SSM layers. * * Data flow: * Input (B, L, D_model) * └─ RMSNorm * └─ wQKV → Q (B,L,H,dh), K (B,L,H,dh), V (B,L,H,dh) * └─ causal attention scores = Q·Kᵀ / √dh (masked) * └─ softmax * └─ weighted V sum * └─ concat heads → wO → D_model * └─ + residual * [optional FFN sublayer] * * Implements SequenceLayer. */ import type { SequenceLayer, LayerForwardResult, LayerParam } from './sequence_layer.js'; export interface AttentionBlockConfig { dModel: number; nHeads: number; dHead?: number; hasFfn?: boolean; ffnMult?: number; } export interface AttentionCache { scores: GPUBuffer; } export declare class AttentionBlock implements SequenceLayer { readonly layerType: "attention"; device: GPUDevice; config: Required; dHead: number; gpuWeights: Record; pipelines: Record; constructor(device: GPUDevice, config: AttentionBlockConfig); private _initWeights; private _buildPipelines; forward(xBuf: GPUBuffer, batch: number, seqLen: number): LayerForwardResult; parameters(): LayerParam[]; getTrainableParams(): LayerParam[]; setWSLAMode(_enabled: boolean): void; destroy(): void; } //# sourceMappingURL=attention_block.d.ts.map