Archived
radiance 1.7.0
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves every shipped container - Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime - /v1/messages works with Claude Code as it ships (gearwave00001) - a long agent conversation keeps its cached history when the client rewrites its last turn (manueloverride) - a stream's first event goes out with the first token, so llama-benchy measures prefill right - opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42) - four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b) - NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA adapters (baKon) - many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool arguments and the CPU's vision and audio encoders - plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
1 parent
b068190326
commit
1e968f6e1d
739 files changed
+128447
-84632
No files matched your search
@@ -1,42 +1,31 @@
|
||||
/* rad_block_attn_fp8.h -- the PLAIN GQA attention block with block-scaled FP8 projections.
|
||||
/* rad_block_attn_fp8.h -- plain GQA attention with block-scaled FP8 projections.
|
||||
*
|
||||
* rmsnorm -> quant_act_fp8 -> fused q|k|v gemm_nt_q -> rope -> kv_store -> attn_paged
|
||||
* -> quant_act_fp8 -> o gemm_nt_q -> [all_reduce] -> residual add
|
||||
*
|
||||
* IT IS rad_block_attn_gated_fp8.h WITHOUT THE TWO THINGS THAT MAKE THAT ONE GATED, and those two
|
||||
* are what a family answers differently rather than what a model tunes:
|
||||
* rad_block_attn_gated_fp8.h without its two family-specific features:
|
||||
*
|
||||
* - NO PER-HEAD Q/K NORM. Qwen3.5 norms each head against its own gain before rotating; LLaMA
|
||||
* and MiniCPM5 rotate the projection as it comes out of the GEMM. A block that normed anyway
|
||||
* against an absent gain would be a different model, and one that normed against a gain of
|
||||
* ones would be a wasted launch a layer.
|
||||
* - NO OUTPUT GATE. There is no second half of the query projection and no sigmoid: the
|
||||
* attention output goes straight into the out-projection.
|
||||
* - No per-head q/k norm. Qwen3.5 norms each head before rotating; LLaMA and MiniCPM5 rotate
|
||||
* the GEMM output directly.
|
||||
* - No output gate. The attention output goes straight into the out-projection.
|
||||
*
|
||||
* WHAT THAT BUYS is the fused q|k|v, which the gated block cannot have: its query projection is
|
||||
* [q|gate] interleaved per head and k and v are separate tensors, so there are three GEMMs a layer.
|
||||
* Here the three weights concatenate along dim 0 into one [q_dim + 2*kv_dim, n_embd] and `rope`
|
||||
* takes exactly that row -- q heads then k heads, v left alone, which is the operand shape the op
|
||||
* was written for (docs/OPS.md). One GEMM, one rope, one quantise in front of all of it.
|
||||
* That allows a fused q|k|v, which the gated block cannot have (its query projection is [q|gate]
|
||||
* interleaved per head). The three weights concatenate along dim 0 into one
|
||||
* [q_dim + 2*kv_dim, n_embd], and `rope` takes that row as is: q heads, then k heads, v untouched
|
||||
* (docs/OPS.md). One GEMM, one rope and one quantise.
|
||||
*
|
||||
* THE ROW PARTS ARE NOT DECORATION. A tensor-parallel rank owns a slice of EACH of the three
|
||||
* projections, not a contiguous slice of the stack; without `row_parts` rank 0 gets the whole query
|
||||
* and rank 1 the whole key and value, and both ranks then compute a perfectly well-formed wrong
|
||||
* thing. LinearFP8 also checks that each part is a whole number of 128-row scale blocks, which is
|
||||
* what makes a block-scaled fusion expressible at all.
|
||||
* `row_parts` is required: a tensor-parallel rank owns a slice of each of the three projections,
|
||||
* not a contiguous slice of the stack. LinearFP8 checks that each part is a whole number of
|
||||
* 128-row scale blocks.
|
||||
*
|
||||
* Everything else -- the fused norm/quantise/residual/all-reduce op at the front, the KV group's
|
||||
* own dtype, the fold flags -- is rad_fp8.h's and rad_block_attn_gated_fp8.h's and is documented
|
||||
* there.
|
||||
* The fused front op, the KV dtype and the fold flags are documented in rad_fp8.h and
|
||||
* rad_block_attn_gated_fp8.h.
|
||||
*/
|
||||
#ifndef RAD_BLOCK_ATTN_FP8_H
|
||||
#define RAD_BLOCK_ATTN_FP8_H
|
||||
|
||||
#include "rad_fp8.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace rad {
|
||||
namespace arch {
|
||||
|
||||
@@ -49,8 +38,8 @@ struct AttnFP8 {
|
||||
ActFP8 attn{}; /* [max_tok, q_dim] attention output */
|
||||
};
|
||||
|
||||
/* The checkpoint's tensor names. Whether they hold block fp8 already or a dense tensor the
|
||||
* recipe quantises is the container's business; the declaration is the same either way. */
|
||||
/* Checkpoint tensor names; the declaration is the same whether they hold block fp8 or a dense
|
||||
* tensor the recipe quantises. */
|
||||
struct Src {
|
||||
const char* norm = nullptr;
|
||||
const char* q = nullptr;
|
||||
@@ -64,9 +53,8 @@ struct AttnFP8 {
|
||||
int layer = 0;
|
||||
rad_kvgroup kv = 0;
|
||||
int64_t n_rot = 0;
|
||||
/* The rotation pairs HALVES (NeoX), which is what HF's rotate_half does and what every LLaMA
|
||||
* derivative ships. GPT-J's adjacent pairs would be arithmetically silent too -- no per-op
|
||||
* check tells the two apart -- so this is stated rather than inferred. */
|
||||
/* The rotation pairs halves (NeoX, HF's rotate_half), as LLaMA derivatives ship. Stated
|
||||
* explicitly: GPT-J's adjacent pairs would pass every per-op check too. */
|
||||
const char* mode = "neox";
|
||||
|
||||
rad_weight w_norm = 0;
|
||||
@@ -99,10 +87,9 @@ inline int AttnFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l, r
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
|
||||
/* NO KV-HEAD REPLICATION HERE. The fused [q|k|v] row-shards by head with the plain even shard,
|
||||
* so above the KV head count a rank would get a slice of one KV head and declare fine while
|
||||
* reading the wrong rows. rad_block_attn_gated.h refuses for the same reason; the block that
|
||||
* plumbs geom_from's `kv_off` is rad_block_attn_gated_fp8.h. */
|
||||
/* No KV-head replication: the fused [q|k|v] uses the plain even row shard, so above the KV head
|
||||
* count a rank would read the wrong rows. rad_block_attn_gated_fp8.h is the block that uses
|
||||
* geom_from's `kv_off`. */
|
||||
if (g.world > g.n_head_kv_all) {
|
||||
fprintf(stderr, "radiance: %s declares no KV row span and cannot serve world_size = %d "
|
||||
"with n_head_kv = %lld.\n", __func__, g.world,
|
||||
@@ -114,43 +101,29 @@ inline int AttnFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l, r
|
||||
w_norm = decl_w(b, nm.f("blk.%d.attn_norm.weight", l), RAD_F32, {g.n_embd},
|
||||
RAD_ACCESS_PER_TOKEN, RAD_SHARD_NONE, grp_layer(l));
|
||||
|
||||
/* One norm, one quantise, one consumer -- and one op, see rad_fp8.h's NormQuantFP8. */
|
||||
/* Norm and quantise in one op (rad_fp8.h: NormQuantFP8). */
|
||||
RAD_ARCH_TRY(nq_h.declare(b, g, w_norm, fold ? w.h.x : w.x, w.h, g.n_embd,
|
||||
fold ? w.x : 0, 0, ar_in));
|
||||
RAD_ARCH_TRY(qkv.declare(b, nm, g, nm.f("blk.%d.attn_qkv", l), q_dim + 2 * kv_dim, g.n_embd,
|
||||
RAD_SHARD_ROW, grp_layer(l), { src.q, src.k, src.v }, w.h, w.qkv,
|
||||
0, { q_dim, kv_dim, kv_dim }));
|
||||
|
||||
op_rope = rw(b, decl_rotary(b, g, "rope",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok), RAD_INT("head_dim", g.head_dim),
|
||||
RAD_INT("n_head", g.n_head), RAD_INT("n_head_kv", g.n_head_kv),
|
||||
RAD_F64("theta", g.theta), RAD_F64("scale", g.rope_scale),
|
||||
RAD_STR("mode", mode), RAD_INT("rotary_dim", n_rot)),
|
||||
RAD_NOWEIGHTS),
|
||||
op_rope = rw(b, decl_rope(b, g, g.max_tok, g.head_dim, g.n_head, g.n_head_kv, n_rot, mode),
|
||||
{w.qkv}, {w.qkv});
|
||||
|
||||
/* THE QUERY IS LIFTED OUT OF THE FUSED ROW, and this op is here because libr4d's paged
|
||||
* attention indexes `q` as one dense [total_q, n_head, head_dim] block and has no pitch
|
||||
* argument for it (r4d_attn_args.h, fill_paged). A column slice of the fused projection has a
|
||||
* row pitch of q_dim + 2*kv_dim, so passing it is refused at issue -- correctly, and loudly.
|
||||
*
|
||||
* The gated block beside this one never needs it: its q comes out of a q|gate de-interleave
|
||||
* that writes a buffer of its own. A plain LLaMA attention has no de-interleave, so the choice
|
||||
* is one `cast` a layer (this) or splitting the projection into q and kv (two more launches a
|
||||
* layer, one GEMM and one rope). The copy is the cheaper of the two at decode, which is the
|
||||
* step that matters, and it is one line to delete if the kernels ever take a q pitch.
|
||||
*
|
||||
* `from` and `to` are the same dtype: `cast` with no conversion is this tree's row copy, and
|
||||
* the drafter tap uses it the same way. */
|
||||
/* Copies the query out of the fused row: libr4d's paged attention reads `q` as a dense
|
||||
* [total_q, n_head, head_dim] block with no pitch argument (r4d_attn_args.h, fill_paged), so a
|
||||
* column slice with pitch q_dim + 2*kv_dim is refused at issue. One copy per layer is cheaper
|
||||
* at decode than splitting the projection (one more GEMM and one more rope). Remove it if the
|
||||
* kernels gain a q pitch. `cast` with from == to is this tree's row copy. */
|
||||
op_qlift = rw(b, RAD_OP(b, "cast",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok), RAD_INT("n", q_dim),
|
||||
RAD_STR("from", g.dtype), RAD_STR("to", g.dtype)),
|
||||
RAD_NOWEIGHTS),
|
||||
{w.qkv}, {w.q});
|
||||
|
||||
/* Declared before kv_store because `block_size` is RAD_DERIVED and kv_store reads the resolved
|
||||
* kernel's value back; see rad_block_attn_gated.h on why the declared order differs from the
|
||||
* issue order. */
|
||||
/* Declared before kv_store, which reads back the resolved `block_size` (rad_block_attn_gated.h
|
||||
* explains declare vs issue order). */
|
||||
op_attn = rw(b, RAD_OP(b, "attn_paged",
|
||||
RAD_PARAMS(RAD_RANGE("q_len", 1, g.max_tok), RAD_INT("head_dim", g.head_dim),
|
||||
RAD_INT("gqa", g.gqa()), RAD_INT("causal", 1),
|
||||
@@ -169,8 +142,8 @@ inline int AttnFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l, r
|
||||
RAD_NOWEIGHTS),
|
||||
{w.qkv}, {});
|
||||
|
||||
/* The out-projection's input quantiser. The gated block folds this into its gate pass; there
|
||||
* is no gate here, so it is the plain `quant_act_fp8` over the attention output. */
|
||||
/* The out-projection's input quantiser; a plain `quant_act_fp8`, as there is no gate pass to
|
||||
* fold it into. */
|
||||
RAD_ARCH_TRY(q_attn.declare(b, g, w.attn, q_dim));
|
||||
RAD_ARCH_TRY(o.declare(b, nm, g, nm.f("blk.%d.attn_output", l), g.n_embd, q_dim,
|
||||
RAD_SHARD_COL, grp_layer(l), { src.o }, w.attn, w.h.x));
|
||||
@@ -204,11 +177,11 @@ inline void AttnFP8::step(RadCtx* c, const RadBatch* batch) const {
|
||||
|
||||
nq_h.step(c, T);
|
||||
qkv.step(c, w.h, w.qkv, T);
|
||||
/* IN PLACE OVER THE FUSED ROW, which is what makes one launch do both halves: `rope` rotates
|
||||
* `n_head` query heads then `n_head_kv` key heads and leaves the value heads alone. */
|
||||
RAD_ISSUE(c, op_rope, brows(w.qkv, T), praw(batch->positions, RAD_I32, T));
|
||||
/* In place over the fused row: rotates n_head query heads, then n_head_kv key heads, and
|
||||
* leaves the value heads alone. */
|
||||
RAD_ISSUE(c, op_rope, brows(w.qkv, T), rope_posmc(g, batch, T));
|
||||
|
||||
/* k and v are COLUMN SLICES of the same row, at q_dim and q_dim + kv_dim. */
|
||||
/* k and v are column slices of the fused row, at q_dim and q_dim + kv_dim. */
|
||||
RAD_ISSUE(c, op_kv_store,
|
||||
bcol(w.qkv, q_dim, kv_dim, T), bcol(w.qkv, q_dim + kv_dim, kv_dim, T),
|
||||
praw(slot, RAD_I32, T), kv_cache(kv, layer));
|
||||
|
||||
Reference in new issue
Block a user