brotensor/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
5 / 5
100.0%
Branches:
-
-%
Functions:
1 / 1
100.0%

include/brotensor/ops/flash_attention.h
Line Branch Exec Source
1 #pragma once
2
3 // brotensor ops/flash_attention.h — Flash-attention family: tiled/windowed/varlen/qkvo/decode + KV cache.
4
5 #include "../tensor.h"
6 #include <cstdint>
7
8 namespace brotensor {
9
10
11 // Flash-attention-style fused attention (FP16, inference-only). Q, K, V are
12 // already projected. Tiled online softmax over Lk (no Lk-long materialisation);
13 // FP32 accumulation.
14 // Q: (Lq,D); K, V: (Lk,D) — FP16.
15 // d_mask: optional length-Lk FP32 mask (1 valid / 0 invalid); may be null.
16 // num_heads divides D.
17 // causal: if true, key k attends to query q only when k <= q (requires
18 // Lq == Lk); combines multiplicatively with d_mask.
19 // O: (Lq,D) FP16, resized as needed.
20 void flash_attention_forward(const Tensor& Q,
21 const Tensor& K,
22 const Tensor& V,
23 const float* d_mask,
24 int num_heads,
25 bool causal,
26 Tensor& O);
27
28
29 // GQA generalisation of flash_attention_forward: grouped-query attention
30 // over pre-projected Q/K/V, causal OR bidirectional. Q carries num_q_heads,
31 // K/V carry num_kv_heads (num_kv_heads must divide num_q_heads; equal == plain
32 // MHA). causal == false is full bidirectional attention over all Lk keys — the
33 // encoder prefill a bidirectional-ified decoder needs (LLM2Vec), or cross
34 // attention of any Lq over Lk context keys. causal == true reproduces
35 // flash_attention_forward's causal mask with GQA (requires Lq == Lk).
36 // Tiled online softmax, FP16/BF16/FP32 (FP32 at any head_dim), FP32
37 // accumulation; shares the windowed kernel's GQA + key-mask machinery.
38 // Q: (Lq, num_q_heads*head_dim); K, V: (Lk, num_kv_heads*head_dim).
39 // d_mask: optional length-Lk FP32 key mask (1 valid / 0 invalid); may be null.
40 // num_kv_heads divides num_q_heads; head_dim = Q.cols/num_q_heads must equal
41 // K.cols/num_kv_heads. causal requires Lq == Lk.
42 // O: (Lq, num_q_heads*head_dim), same dtype as Q, resized as needed.
43 void flash_attention_gqa_forward(const Tensor& Q,
44 const Tensor& K,
45 const Tensor& V,
46 const float* d_mask,
47 int num_q_heads,
48 int num_kv_heads,
49 bool causal,
50 Tensor& O);
51
52
53 // Sliding-window self-attention (FP32/FP16/BF16, inference-only) — the local
54 // attention of streaming neural codecs (e.g. Qwen3-TTS / Mimi), autoregressive decode,
55 // and bidirectional encoder models (e.g. ModernBERT). Q, K, V already projected,
56 // (L, num_heads*head_dim).
57 // The Lq queries occupy the last Lq positions of a length-Lk sequence
58 // (q_offset = Lk - Lq): query row r is at absolute position aq = r + q_offset.
59 // - causal == true: attends keys [max(0, aq-window+1), aq]. window <= 0 means
60 // unbounded causal — identical to flash_attention_forward with causal=true.
61 // - causal == false: attends keys [max(0, aq - window/2), min(Lk - 1, aq + window/2)]
62 // when window > 0, or all keys [0, Lk) when window <= 0 (full bidirectional).
63 // - Lq == Lk: self-attention (prefill / codec sliding window / encoder).
64 // - Lq < Lk: incremental decode of an Lq-token block over a K/V cache;
65 // Lq == 1 with window <= 0 attends every cached key (full cache attention),
66 // replacing a varlen call with no cu_seqlens upload. Requires Lk >= Lq.
67 // d_mask: optional length-Lk FP32 key mask (1 valid / 0 invalid), combined
68 // multiplicatively with the window; may be null.
69 // num_heads divides D. O: (Lq, num_heads*head_dim), resized as needed.
70 void flash_attention_windowed_forward(const Tensor& Q,
71 const Tensor& K,
72 const Tensor& V,
73 const float* d_mask,
74 int num_heads,
75 int window,
76 Tensor& O,
77 bool causal = true);
78
79
80 // Packed variable-length multi-head attention, forward only (Qwen3-VL window
81 // attention). All sequences in a batch live contiguously in one packed tensor;
82 // per-sequence boundaries come from `cu_seqlens_*` INT32 prefix-sum buffers of
83 // length `batch_size + 1`. Sequence b covers Q rows
84 // [cu_seqlens_q[b], cu_seqlens_q[b+1]) and attends to K/V rows
85 // [cu_seqlens_k[b], cu_seqlens_k[b+1]); no cross-sequence attention. Mirrors
86 // flash_attn_varlen_func semantics.
87 // Q: (total_tokens_q, num_heads * head_dim) — FP16/BF16/FP32 (GPU) / FP32 (CPU).
88 // K, V: (total_tokens_k, num_heads * head_dim) — same packing, num_heads
89 // matches Q (no GQA — that's a future cleanup).
90 // cu_seqlens_q, cu_seqlens_k: DEVICE pointers (CUDA/Metal device, raw host
91 // pointers on CPU), length batch_size + 1, INT32 prefix sums. Same
92 // convention as `const float* d_mask` elsewhere — caller owns the
93 // buffer; the op does not allocate or copy.
94 // max_seqlen_q, max_seqlen_k: bound the longest sequence's length — used by
95 // the GPU kernel for block sizing; the CPU impl ignores them.
96 // causal: if true, key k in sequence b attends to query q only when
97 // (k - cu_seqlens_k[b]) <= (q - cu_seqlens_q[b]); only meaningful when
98 // the per-sequence Q and K lengths match.
99 // O: (total_tokens_q, num_heads * head_dim) — overwritten, resized + dtype-set.
100 void flash_attention_varlen_forward(const Tensor& Q,
101 const Tensor& K,
102 const Tensor& V,
103 const int32_t* cu_seqlens_q,
104 const int32_t* cu_seqlens_k,
105 int batch_size,
106 int max_seqlen_q,
107 int max_seqlen_k,
108 int num_heads,
109 int head_dim,
110 bool causal,
111 Tensor& O);
112
113
114 // Packed variable-length bidirectional self-attention straight off a fused QKV
115 // projection — the encoder-batching entry point (many independent sequences of
116 // any lengths packed back to back, no padding, one launch per layer).
117 // QKV: (L, 3*num_heads*head_dim) — per row [q heads | k heads | v heads], the
118 // layout a fused Wqkv linear produces. FP16/BF16 on the GPU (head_dim 64
119 // takes the tensor-core kernel, other widths a generic one), FP32 on
120 // both CPU and GPU.
121 // seq_bounds: (L, 2) INT32 on the same device — row r's sequence occupies
122 // rows [seq_bounds[r,0], seq_bounds[r,1]) and must contain r. Rows only
123 // ever attend inside their own sequence.
124 // window > 0: row r attends keys j of its sequence with |r - j| <= window/2
125 // (ModernBERT / flash_attention_windowed_forward's bidirectional window);
126 // window <= 0: every key of its sequence.
127 // O: (L, num_heads*head_dim), same dtype as QKV, resized as needed.
128 // Row → sequence membership is data, not launch shape: the grid depends only
129 // on L, so a CUDA graph captured for one L replays for any packing of it.
130 void flash_attention_packed_qkv_forward(const Tensor& QKV,
131 const Tensor& seq_bounds,
132 int num_heads,
133 int window,
134 Tensor& O);
135
136
137 // Backward of flash_attention_packed_qkv_forward — the same packing, bounds
138 // and window, so a packed encoder can be trained (or differentiated to its
139 // inputs) through the exact attention it runs. Recompute-based: consumes no
140 // forward caches; re-derives each row's softmax statistics, then accumulates
141 // dQ per query row and dK / dV per key row (no atomics, deterministic).
142 // QKV: the forward's input (L, 3*num_heads*head_dim), post-RoPE.
143 // dO: (L, num_heads*head_dim) upstream gradient of the forward's O, same
144 // dtype as QKV.
145 // seq_bounds, num_heads, window: exactly as passed to the forward.
146 // dQKV: (L, 3*num_heads*head_dim) OVERWRITTEN (resized + dtype-set to
147 // QKV's) — per row [dQ heads | dK heads | dV heads].
148 // FP16/BF16/FP32 on the GPU (FP32 math), FP32 on the CPU. Cost is
149 // O(L * span * head_dim) with span the keys a row attends (window + 1, or its
150 // sequence length).
151 void flash_attention_packed_qkv_backward(const Tensor& QKV,
152 const Tensor& dO,
153 const Tensor& seq_bounds,
154 int num_heads,
155 int window,
156 Tensor& dQKV);
157
158
159 // Backward of flash_attention_varlen_forward — packed variable-length attention
160 // over pre-projected Q/K/V (no projection weights, no biases — projections are
161 // handled by the caller's linear layer; bias gradients belong to that layer).
162 // Recompute-based: consumes no forward caches, re-runs the per-sequence
163 // softmax then reverses it. Matches flash_attention_backward's per-sequence
164 // math; only the cu_seqlens scatter/gather and per-sequence causal differ.
165 // Q: (total_tokens_q, num_heads*head_dim) — FP16/BF16/FP32 (GPU) / FP32 (CPU).
166 // K, V: (total_tokens_k, num_heads*head_dim) — same dtype, same packing.
167 // O: (total_tokens_q, ...) forward output — currently unused (kept for API
168 // symmetry with flash_attention_backward).
169 // dO: (total_tokens_q, ...) upstream gradient, same dtype as Q/K/V.
170 // cu_seqlens_q, cu_seqlens_k: DEVICE pointers on GPU, host pointers on CPU,
171 // length batch_size + 1, INT32 prefix sums. Same convention as the
172 // forward.
173 // max_seqlen_q, max_seqlen_k: bound the longest per-sequence length — used
174 // by the GPU kernel for block/scratch sizing; the CPU impl ignores them.
175 // causal: per-sequence; only meaningful when per-sequence Lq == Lk.
176 // dQ: (total_tokens_q, ...); dK, dV: (total_tokens_k, ...) — OVERWRITTEN
177 // (resized + dtype-set), matching flash_attention_backward's contract.
178 // Out-of-range positions (causal-excluded, or in a fully empty K sequence)
179 // contribute nothing to any gradient. No cross-sequence attention.
180 void flash_attention_varlen_backward(const Tensor& Q,
181 const Tensor& K,
182 const Tensor& V,
183 const Tensor& O,
184 const Tensor& dO,
185 const int32_t* cu_seqlens_q,
186 const int32_t* cu_seqlens_k,
187 int batch_size,
188 int max_seqlen_q,
189 int max_seqlen_k,
190 int num_heads,
191 int head_dim,
192 bool causal,
193 Tensor& dQ,
194 Tensor& dK,
195 Tensor& dV);
196
197
198 // Flash-attention with QKV and output projections fused at the boundary.
199 // Projects X->Q, Ctx->K,V (or X->Q,K,V when Ctx is null), runs the tiled core,
200 // then projects with Wo. FP16 throughout.
201 // X: (Lq,D) FP16, query source.
202 // Ctx: (Lk,D_ctx) FP16 or null. Null => self-attention (Ctx<-X). D_ctx may
203 // differ from D (e.g. SD1.5 cross-attention).
204 // Wq, Wo: (D,D); Wk, Wv: (D,D_ctx) — FP16.
205 // bq, bk, bv, bo: optional (D,1) FP16 biases; null to skip.
206 // d_mask: optional length-Lk FP32 mask. num_heads divides D.
207 // causal: see flash_attention_forward (typically with Ctx == null).
208 // O: (Lq,D) FP16, resized as needed.
209 void flash_attention_qkvo_forward(const Tensor& X,
210 const Tensor* Ctx,
211 const Tensor& Wq, const Tensor* bq,
212 const Tensor& Wk, const Tensor* bk,
213 const Tensor& Wv, const Tensor* bv,
214 const Tensor& Wo, const Tensor* bo,
215 const float* d_mask,
216 int num_heads,
217 bool causal,
218 Tensor& O);
219
220
221 // Backward of flash_attention_qkvo_forward. Recompute-style: consumes no
222 // forward caches — re-runs the attention math from the inputs, then reverses
223 // it. FP16 storage, FP32 accumulation. All shape / dtype / Ctx-null /
224 // rectangular-Wk-Wv / causal / optional-bias rules match the forward; pass the
225 // same values.
226 // dO: (Lq,D) FP16 upstream.
227 // dX: (Lq,D) FP16 overwritten. For self-attention (Ctx null) dX absorbs
228 // the K/V-projection gradients too: dX = dQ.Wq + dK.Wk + dV.Wv.
229 // dCtx: (Lk,D_ctx) FP16 overwritten; must be null iff Ctx is null. For
230 // cross-attention dCtx = dK.Wk + dV.Wv.
231 // dWq, dWo: (D,D); dWk, dWv: (D,D_ctx) — FP16, accumulated (caller zeros).
232 // dbq, dbk, dbv, dbo: (D,1) FP16, accumulated iff the matching forward bias
233 // was non-null; pass null otherwise (the null/non-null symmetry must
234 // be exact — a mismatch is rejected).
235 // Causal- and mask-excluded positions contribute nothing to any gradient.
236 void flash_attention_qkvo_backward(
237 const Tensor& X, const Tensor* Ctx,
238 const Tensor& Wq, const Tensor* bq,
239 const Tensor& Wk, const Tensor* bk,
240 const Tensor& Wv, const Tensor* bv,
241 const Tensor& Wo, const Tensor* bo,
242 const float* d_mask,
243 int num_heads,
244 bool causal,
245 const Tensor& dO,
246 Tensor& dX, Tensor* dCtx,
247 Tensor& dWq, Tensor* dbq,
248 Tensor& dWk, Tensor* dbk,
249 Tensor& dWv, Tensor* dbv,
250 Tensor& dWo, Tensor* dbo);
251
252
253 // Backward of flash_attention_forward — bare attention core, no projection
254 // weights (what LoRA-style adapters need; projections are wrapped externally).
255 // Recompute-based; FP16 storage, FP32 accumulation.
256 // Q: (Lq,D); K, V: (Lk,D) — pre-projected forward inputs, FP16.
257 // O: (Lq,D) forward output — currently unused (kept for API symmetry).
258 // dO: (Lq,D) FP16 upstream.
259 // d_mask: optional length-Lk FP32 mask (null for unmasked); positions with
260 // mask[k] <= 0.5 are dropped.
261 // num_heads divides D. causal: match the forward (requires Lq == Lk).
262 // dQ: (Lq,D); dK, dV: (Lk,D) — FP16, overwritten (resized + dtype-set).
263 // Causal- and mask-excluded positions contribute nothing to dQ/dK/dV.
264 void flash_attention_backward(const Tensor& Q,
265 const Tensor& K,
266 const Tensor& V,
267 const Tensor& O,
268 const Tensor& dO,
269 const float* d_mask,
270 int num_heads,
271 bool causal,
272 Tensor& dQ,
273 Tensor& dK,
274 Tensor& dV);
275
276
277 // Project a context tensor through Wk/Wv into the exact (Lk,D) FP16 K/V buffers
278 // flash_attention_forward consumes. Used to precompute cross-attention K/V once
279 // per generate() (text context is fixed across denoising steps). Numerically
280 // identical to the K/V projection stage of flash_attention_qkvo_forward.
281 // ctx: (Lk,D_ctx) FP16. Wk, Wv: (D,D_ctx) FP16. bk, bv: (D,1) FP16 or null.
282 // K_out, V_out: (Lk,D) FP16, resized as needed.
283 void flash_attention_project_kv(const Tensor& ctx,
284 const Tensor& Wk, const Tensor* bk,
285 const Tensor& Wv, const Tensor* bv,
286 Tensor& K_out,
287 Tensor& V_out);
288
289
290 // Like flash_attention_qkvo_forward but K and V are already projected by the
291 // caller (typically via flash_attention_project_kv). Projects X->Q with Wq/bq,
292 // runs the tiled core against the supplied K/V, applies Wo/bo. FP16 throughout.
293 // X: (Lq,D); K, V: (Lk,D) — FP16. Wq, Wo: (D,D) FP16; bq, bo: (D,1) FP16 or null.
294 // d_mask: optional length-Lk FP32 mask. num_heads divides D.
295 // causal: see flash_attention_forward. O: (Lq,D) FP16, resized as needed.
296 void flash_attention_q_with_kv_cached_forward(const Tensor& X,
297 const Tensor& K,
298 const Tensor& V,
299 const Tensor& Wq, const Tensor* bq,
300 const Tensor& Wo, const Tensor* bo,
301 const float* d_mask,
302 int num_heads,
303 bool causal,
304 Tensor& O);
305
306
307 // KV-cache append (FP16): copy K_new, V_new into rows [cur_len, cur_len+L_new)
308 // of K_cache, V_cache.
309 // K_new, V_new: (L_new,D) FP16. K_cache, V_cache: (L_max,D) FP16 — must be
310 // pre-sized (not resized); cur_len + L_new <= L_max.
311 void kv_cache_append(const Tensor& K_new, const Tensor& V_new,
312 int cur_len, Tensor& K_cache, Tensor& V_cache);
313
314
315 // Causal flash-attention against a partially-filled KV cache (FP16, fwd-only).
316 // Runs the tiled core against rows [0, valid_len) of the caches. Query position
317 // p_q = (valid_len - L_q) + i attends to cache positions [0, p_q].
318 // Q: (L_q, num_q_heads*head_dim) FP16 — L_q == 1 for token-by-token decode,
319 // L_q > 1 supported.
320 // K_cache, V_cache: (L_max, num_kv_heads*head_dim) FP16 — only rows
321 // [0, valid_len) are read.
322 // valid_len >= L_q. num_kv_heads must divide num_q_heads (GQA); each KV head
323 // serves num_q_heads/num_kv_heads consecutive query heads. num_kv_heads ==
324 // num_q_heads is plain MHA. head_dim = Q.cols/num_q_heads must equal
325 // K_cache.cols/num_kv_heads.
326 // O: (L_q, num_q_heads*head_dim) FP16, resized as needed.
327 // GQA is native on all three backends: the decode kernel maps query head h to KV
328 // head h/(num_q_heads/num_kv_heads), reading the n_kv-wide cache directly — no
329 // KV-head widening needed. num_kv_heads == num_q_heads is plain MHA.
330 //
331 // Gemma-2 extensions (both default to today's exact behaviour):
332 // attn_softcap > 0: tanh logit soft-capping. After the 1/sqrt(head_dim) scale
333 // and BEFORE the causal/window mask and the online-softmax max/exp, each
334 // raw score s is replaced by attn_softcap * tanh(s / attn_softcap).
335 // attn_softcap == 0 (default) disables it — bit-identical to before.
336 // window > 0: sliding-window causal masking. Query at absolute position p
337 // (p = valid_len - L_q + q) attends key j only when j <= p AND
338 // j > p - window, i.e. keys in [max(0, p-window+1), p]. window <= 0
339 // (default) is unbounded causal — bit-identical to before. Composes
340 // multiplicatively with the causal mask.
341 void flash_attention_decode(const Tensor& Q,
342 const Tensor& K_cache, const Tensor& V_cache,
343 int valid_len, int num_q_heads, int num_kv_heads,
344 Tensor& O,
345 float attn_softcap = 0.0f, int window = 0);
346
347
348 // Single-token decode attention over a FIXED-CAPACITY masked KV cache — the
349 // CUDA-graph-capturable twin of flash_attention_decode. The kernel always
350 // sees the full (L_max, ·) cache buffers, so its launch shape never changes
351 // as generation advances; validity lives in `d_mask`, a device-resident
352 // length-L_max FP32 key mask (1 valid / 0 invalid) the caller updates
353 // between graph replays. Masked keys are dropped before the dot product and
354 // softmax (their weights underflow to exact zeros), so with
355 // mask = [1]*valid_len + [0]*(L_max-valid_len) the result is bit-identical
356 // to flash_attention_decode(Q, K, V, valid_len, ...) at L_q == 1. Fully
357 // masked key tiles are skipped without touching K/V.
358 // Q: (1, num_q_heads*head_dim) — single query row only.
359 // K_cache, V_cache: (L_max, num_kv_heads*head_dim); same GQA rules as
360 // flash_attention_decode.
361 // d_mask: device pointer, length L_max, FP32; must not be null and must
362 // mark at least one key valid.
363 // O: (1, num_q_heads*head_dim), resized as needed.
364 // Gemma-2 extensions match flash_attention_decode (see above):
365 // attn_softcap > 0: tanh logit soft-capping applied to each raw score before
366 // the mask and softmax. attn_softcap == 0 (default) disables it.
367 // window > 0: sliding-window masking. The query's absolute position p is the
368 // highest valid key index (the last 1 in d_mask); a key j is kept only
369 // when it is valid AND j > p - window, i.e. j in [max(0,p-window+1), p].
370 // window <= 0 (default) keeps the full valid set — bit-identical to
371 // before. Combines multiplicatively with the validity mask.
372 void flash_attention_decode_masked(const Tensor& Q,
373 const Tensor& K_cache,
374 const Tensor& V_cache,
375 const float* d_mask,
376 int num_q_heads, int num_kv_heads,
377 Tensor& O,
378 float attn_softcap = 0.0f, int window = 0);
379
380
381 // Single-token decode attention over the first *d_len keys of a
382 // fixed-capacity KV cache, the length read on the device at run time. Like
383 // the masked op, the launch shape never changes as generation advances, so a
384 // CUDA graph captured once replays for every step (the caller writes the new
385 // length between replays); unlike it, the work divides the VALID keys, so a
386 // cache sized for a long generation costs nothing for its unused rows.
387 // Results agree with flash_attention_decode(.., *d_len, ..) to rounding (the
388 // split points differ, so not bit for bit).
389 // Q may carry R > 1 rows: consecutive positions whose K/V are already the
390 // last R of the *d_len valid rows, row r attending causally to the first
391 // *d_len - R + 1 + r keys (flash_attention_decode's L_q > 1 rule) — a block
392 // of draft tokens verified in one pass, each cache row read once for all R.
393 // On CUDA that needs the grouped kernel's shapes (head_dim 64/128/256,
394 // group 1/2/4/8); *d_len >= R.
395 // Q: (R, num_q_heads*head_dim); K_cache, V_cache: (L_max, num_kv_heads*head_dim)
396 // FP16/BF16 on CUDA (head_dim a multiple of 32, at most 256), FP32 on CPU.
397 // d_len: device INT32 (a raw host pointer on CPU), 0 <= *d_len <= L_max;
398 // a length of 0 writes zeros.
399 // O: (1, num_q_heads*head_dim), resized as needed.
400 void flash_attention_decode_len(const Tensor& Q, const Tensor& K_cache, const Tensor& V_cache,
401 const int32_t* d_len, int num_q_heads, int num_kv_heads, Tensor& O);
402
403
404 // Back-compat overload: num_kv_heads defaults to num_heads (plain MHA).
405 2 inline void flash_attention_decode(const Tensor& Q,
406 const Tensor& K_cache, const Tensor& V_cache,
407 int valid_len, int num_heads, Tensor& O,
408 float attn_softcap = 0.0f, int window = 0) {
409 4 flash_attention_decode(Q, K_cache, V_cache, valid_len,
410 2 num_heads, /*num_kv_heads=*/num_heads, O,
411 2 attn_softcap, window);
412 2 }
413
414
415 // ─── W8A16 flash-attention variants ────────────────────────────────────────
416 //
417 // Same composition as flash_attention_project_kv /
418 // flash_attention_q_with_kv_cached_forward / flash_attention_qkvo_forward, but
419 // every projection takes an INT8 weight + per-output-row FP32 scale instead of
420 // an FP16 weight. The attention core stays FP16 (activations are never
421 // quantised). Each W*_int8 is (D, in_dim) with a matching scale (D,1); biases
422 // stay FP16 (D,1), optional. Masks, causal flag, and num_heads match the FP16
423 // versions.
424 void flash_attention_project_kv_int8w_fp16(const Tensor& ctx,
425 const Tensor& Wk_int8,
426 const Tensor& sk,
427 const Tensor* bk,
428 const Tensor& Wv_int8,
429 const Tensor& sv,
430 const Tensor* bv,
431 Tensor& K_out,
432 Tensor& V_out);
433
434
435 void flash_attention_q_with_kv_cached_int8w_fp16(const Tensor& X,
436 const Tensor& K,
437 const Tensor& V,
438 const Tensor& Wq_int8,
439 const Tensor& sq,
440 const Tensor* bq,
441 const Tensor& Wo_int8,
442 const Tensor& so,
443 const Tensor* bo,
444 const float* d_mask,
445 int num_heads,
446 bool causal,
447 Tensor& O);
448
449
450 void flash_attention_qkvo_int8w_fp16(const Tensor& X,
451 const Tensor* Ctx,
452 const Tensor& Wq_int8, const Tensor& sq, const Tensor* bq,
453 const Tensor& Wk_int8, const Tensor& sk, const Tensor* bk,
454 const Tensor& Wv_int8, const Tensor& sv, const Tensor* bv,
455 const Tensor& Wo_int8, const Tensor& so, const Tensor* bo,
456 const float* d_mask,
457 int num_heads,
458 bool causal,
459 Tensor& O);
460
461 } // namespace brotensor
462