Archived
libr4d, arch: the 31B and DFlash2 with fewer launches a step, same bytes
Attention reads q and the gqa-8 drafter's KV in place (attn_paged_qrow); the 31B's attention prologue stores k and v itself (qkv_norm_rope_kv_store); DFlash2's norm/rope/cache-store chains and add-then-norm pairs run as one launch each. Carries the launch-cliff padding until that PR merges. Squashed from: - libr4d: attn_paged_qrow on the split-KV decode kernel -- h256/gqa2, and h128/gqa8 by two groups a kv head - arch: the 31B's sliding layers and its drafter read through attn_paged_qrow where a card serves it - libr4d: step past the full-card launch cliff in qkv_norm_rope and the row norms - libr4d: qkv_norm_rope describes its operands, so rad-kbench and rad-tune can time it - libr4d, arch/gemma4_bf16: qkv_norm_rope_kv_store -- the 31B's prologue stores k and v itself - libr4d, arch/common: qkv_norm_rope takes v_norm; DFlash2's query pass folds its q/k chain - libr4d, arch/common: qkv_norm_rope takes n_head 0; DFlash2's context pass folds its key chain - libr4d, arch/common: add_rmsnorm; DFlash2 issues each residual add with the norm after it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
04e5480387
commit
015cba8837
20 files changed
+1332
-164
No files matched your search
@@ -65,6 +65,20 @@ struct R4DArgs {
|
||||
// null.
|
||||
const int* cu_q; // (num_seqs+1,) int32 device, or null for a uniform q_len
|
||||
int total_q; // rows of q/out; ignored unless cu_q is set
|
||||
|
||||
// ---- Views the split-KV decode kernel reads (r4d_attn_decode_h256_gqa6.hip); every other
|
||||
// kernel leaves them at zero and reads q dense with one cache head per query group.
|
||||
//
|
||||
// `q_ld` is the element distance between q rows, 0 for dense (q_heads * head_dim): the q part
|
||||
// of a fused [q|k|v] projection read where it lies (attn_paged_qrow). A multiple of 4.
|
||||
//
|
||||
// `kv_rep` maps query groups onto cache heads: group g (q heads g*GQA .. g*GQA+GQA-1) reads
|
||||
// cache head g / kv_rep, and the descales are per cache head. kv_heads then counts the groups
|
||||
// (q_heads / GQA) and the cache holds kv_heads / kv_rep heads. 0 or 1 is one head a group. It
|
||||
// runs a gqa of GQA * kv_rep on the kernel compiled for GQA, whose workgroup holds at most 64
|
||||
// rows of q_len * GQA: the 31B's DFlash drafter, gqa 8 at a block of 16, on the gqa-4 kernel.
|
||||
long q_ld;
|
||||
int kv_rep;
|
||||
};
|
||||
|
||||
// Rows of q and out. The split-KV scratch is laid out by dense query row, so the host sizing hook
|
||||
@@ -89,6 +103,9 @@ int r4d_attn_decode_h256_gqa6_bf16kv (const R4DArgs* a, hipStream_t stream);
|
||||
int r4d_attn_decode_h128_gqa4_fp8kv (const R4DArgs* a, hipStream_t stream);
|
||||
int r4d_attn_decode_h128_gqa4_bf16kv (const R4DArgs* a, hipStream_t stream);
|
||||
long r4d_attn_decode_h128_gqa4_scratch_bytes(const R4DArgs* a);
|
||||
// ...with R4DArgs::kv_rep and q_ld read: a gqa of 4 * kv_rep over a cache of kv_heads / kv_rep.
|
||||
int r4d_attn_decode_h128_gqa4_rep_fp8kv (const R4DArgs* a, hipStream_t stream);
|
||||
int r4d_attn_decode_h128_gqa4_rep_bf16kv (const R4DArgs* a, hipStream_t stream);
|
||||
// Bytes of split-KV partial buffer one decode launch of this shape needs. Independent of the cache
|
||||
// dtype: the partials are f16 either way.
|
||||
long r4d_attn_decode_h256_gqa6_scratch_bytes(const R4DArgs* a);
|
||||
@@ -106,6 +123,9 @@ int r4d_attn_prefill_h128_gqa2w_bf16kv(const R4DArgs* a, hipStream_t stream);
|
||||
int r4d_attn_decode_h128_gqa2w_fp8kv (const R4DArgs* a, hipStream_t stream);
|
||||
int r4d_attn_decode_h128_gqa2w_bf16kv (const R4DArgs* a, hipStream_t stream);
|
||||
long r4d_attn_decode_h128_gqa2w_scratch_bytes(const R4DArgs* a);
|
||||
// ...with q at R4DArgs::q_ld (attn_paged_qrow).
|
||||
int r4d_attn_decode_h256_gqa2_qld_fp8kv (const R4DArgs* a, hipStream_t stream);
|
||||
int r4d_attn_decode_h256_gqa2_qld_bf16kv (const R4DArgs* a, hipStream_t stream);
|
||||
// The geometry the attention kernels above are compiled for, so a caller can check a model
|
||||
// before the first launch.
|
||||
void r4d_attn_dims(int* head_dim, int* gqa, int* block_size, int* max_decode_rows);
|
||||
|
||||
Reference in new issue
Block a user