Archived
clef: the head in plugins of its own (arch/clef_bf16, arch/clef_fp8); the qwen35 plugins untouched
This commit is contained in:
1 parent
a96bfe821f
commit
b1da6a28bd
11 files changed
+163
-44
No files matched your search
@@ -0,0 +1,10 @@
|
||||
# Built in radiance's tree, or standalone against an installed radiance
|
||||
# (`cmake -S arch/clef_bf16 -B build -DCMAKE_PREFIX_PATH=<radiance prefix>`); see cmake/RadAddPlugin.cmake.
|
||||
if(NOT COMMAND rad_add_plugin)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(clef_bf16 LANGUAGES CXX)
|
||||
find_package(radiance REQUIRED)
|
||||
rad_plugin_defaults()
|
||||
endif()
|
||||
|
||||
rad_add_plugin(clef_bf16 architectures SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/clef_bf16.cpp)
|
||||
@@ -0,0 +1,62 @@
|
||||
/* clef_bf16 -- Cloudflare's clef and clef-flash decision models, bf16: the qwen35_bf16 trunk with
|
||||
* the joint schema head on the card (arch/common/rad_block_clef.h), served on /v1/systemone.
|
||||
*
|
||||
* This is arch/qwen35_bf16/qwen35_bf16.cpp built again under its own architecture id, as
|
||||
* qwen35_w8a8 is qwen35_fp8 built again: the trunk's declare and step are that file's, untouched,
|
||||
* and this file adds the head after them. A container selects it with `rad-convert --arch clef`,
|
||||
* so a plain qwen35 container never pays for the head and the qwen35 plugins carry no decision
|
||||
* code. The head needs `decision.type=clef` and the head's geometry in the container header,
|
||||
* which rad-convert writes from joint_head_config.json and joint_head.safetensors (--add).
|
||||
*/
|
||||
#define RAD_ARCH_NO_EXPORTS 1
|
||||
#include "../qwen35_bf16/qwen35_bf16.cpp"
|
||||
#undef RAD_ARCH_NO_EXPORTS
|
||||
|
||||
#include <arch/rad_block_clef.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace clef_bf16 {
|
||||
|
||||
using namespace rad::arch;
|
||||
|
||||
/* One head per rank beside the trunk's own per-rank state (qwen35_bf16::g_model). */
|
||||
static ClefHead g_head[MAX_RANKS];
|
||||
|
||||
static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx) {
|
||||
if (!b || !meta || !ctx) return RAD_E_INVAL;
|
||||
if (ctx->rank < 0 || ctx->rank >= MAX_RANKS) return RAD_E_INVAL;
|
||||
if (!ClefHead::present(meta)) {
|
||||
std::fprintf(stderr, "radiance: clef_bf16 serves a container converted with "
|
||||
"--set decision.type=clef and the head added (--add "
|
||||
"joint_head.safetensors); this one declares no decision model\n");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
RAD_ARCH_TRY(qwen35_bf16::declare(b, meta, ctx));
|
||||
/* The trunk's declare does not take part in sizing declares (no probe), so its state and the
|
||||
* head's are the real ones. The head goes after the vision tower: its buffers join the same
|
||||
* arena, and it reads the final norm's rows, the lm_head and the trunk's cache block size. */
|
||||
qwen35_bf16::Model& m = qwen35_bf16::g_model[ctx->rank];
|
||||
ClefHead& h = g_head[ctx->rank];
|
||||
h = ClefHead{};
|
||||
return h.declare(b, meta, ctx, m.nm, m.g, m.b_h, m.b_logits, m.w_lm_head, m.kv_full,
|
||||
(int)m.g.n_layer + 256);
|
||||
}
|
||||
|
||||
static void step(RadCtx* c, const RadBatch* batch) {
|
||||
qwen35_bf16::step(c, batch);
|
||||
/* An encoder pass runs the tower alone and leaves no rows for the head. */
|
||||
if (batch->enc) return;
|
||||
qwen35_bf16::Model& m = qwen35_bf16::g_model[rad_rank(c)];
|
||||
ClefHead& h = g_head[rad_rank(c)];
|
||||
/* The final norm's rows are still in `h` after the trunk's step; the logits row of each
|
||||
* sampled sequence has been written, and the head adds its values beside it. */
|
||||
h.step_tokens(c, batch, m.b_h);
|
||||
if (batch->n_out > 0) h.step_heads(c, batch, m.b_logits, m.w_lm_head);
|
||||
}
|
||||
|
||||
} /* namespace clef_bf16 */
|
||||
|
||||
RAD_ARCH_PLUGIN(clef_bf16, "clef", "", "0.1.0",
|
||||
"Cloudflare's clef / clef-flash (9B, 27B): the Qwen3.5 trunk of qwen35_bf16, bf16, "
|
||||
"with the joint schema head on the card for /v1/systemone")
|
||||
@@ -0,0 +1,10 @@
|
||||
# Built in radiance's tree, or standalone against an installed radiance
|
||||
# (`cmake -S arch/clef_fp8 -B build -DCMAKE_PREFIX_PATH=<radiance prefix>`); see cmake/RadAddPlugin.cmake.
|
||||
if(NOT COMMAND rad_add_plugin)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(clef_fp8 LANGUAGES CXX)
|
||||
find_package(radiance REQUIRED)
|
||||
rad_plugin_defaults()
|
||||
endif()
|
||||
|
||||
rad_add_plugin(clef_fp8 architectures SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/clef_fp8.cpp)
|
||||
@@ -0,0 +1,59 @@
|
||||
/* clef_fp8 -- Cloudflare's clef and clef-flash decision models, block fp8: the qwen35_fp8 trunk
|
||||
* with the joint schema head on the card (arch/common/rad_block_clef.h), served on
|
||||
* /v1/systemone.
|
||||
*
|
||||
* This is arch/qwen35_fp8/qwen35_fp8.cpp built again under its own namespace and architecture
|
||||
* id, as qwen35_w8a8 and qwen35moe_fp8 are: the trunk's declare, step and probe are that file's,
|
||||
* untouched, and this file adds the head after them. A container selects it with `rad-convert
|
||||
* --arch clef` and the fp8 recipe; the lm_head stays bf16, which the head reads.
|
||||
*/
|
||||
#define QWEN35_NS qwen35_clef_fp8
|
||||
#define QWEN35_ARCH_ID "clef"
|
||||
#define RAD_ARCH_NO_EXPORTS 1
|
||||
#include "../qwen35_fp8/qwen35_fp8.cpp"
|
||||
#undef RAD_ARCH_NO_EXPORTS
|
||||
|
||||
#include <arch/rad_block_clef.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace clef_fp8 {
|
||||
|
||||
using namespace rad::arch;
|
||||
|
||||
static ClefHead g_head[MAX_RANKS];
|
||||
|
||||
static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx) {
|
||||
if (!b || !meta || !ctx) return RAD_E_INVAL;
|
||||
if (ctx->rank < 0 || ctx->rank >= MAX_RANKS) return RAD_E_INVAL;
|
||||
if (!ClefHead::present(meta)) {
|
||||
std::fprintf(stderr, "radiance: clef_fp8 serves a container converted with "
|
||||
"--set decision.type=clef and the head added (--add "
|
||||
"joint_head.safetensors); this one declares no decision model\n");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
RAD_ARCH_TRY(qwen35_clef_fp8::declare(b, meta, ctx));
|
||||
qwen35_clef_fp8::Model& m = qwen35_clef_fp8::g_model[ctx->rank];
|
||||
ClefHead& h = g_head[ctx->rank];
|
||||
h = ClefHead{};
|
||||
return h.declare(b, meta, ctx, m.nm, m.g, m.a_h.x, m.b_logits, m.w_lm_head, m.kv_full,
|
||||
(int)m.g.n_layer + 256);
|
||||
}
|
||||
|
||||
static void step(RadCtx* c, const RadBatch* batch) {
|
||||
qwen35_clef_fp8::step(c, batch);
|
||||
/* An encoder pass leaves no rows for the head, and a drafter's pass is not a trunk step. */
|
||||
if (batch->enc || batch->draft_pass != 0) return;
|
||||
qwen35_clef_fp8::Model& m = qwen35_clef_fp8::g_model[rad_rank(c)];
|
||||
ClefHead& h = g_head[rad_rank(c)];
|
||||
/* The final norm's rows are in `a_h.x` after either of the trunk's step paths. */
|
||||
h.step_tokens(c, batch, m.a_h.x);
|
||||
if (batch->n_out > 0) h.step_heads(c, batch, m.b_logits, m.w_lm_head);
|
||||
}
|
||||
|
||||
} /* namespace clef_fp8 */
|
||||
|
||||
RAD_ARCH_PROBE(qwen35_clef_fp8)
|
||||
RAD_ARCH_PLUGIN(clef_fp8, "clef", "fp8_e4m3", "0.1.0",
|
||||
"Cloudflare's clef / clef-flash (9B, 27B): the Qwen3.5 trunk of qwen35_fp8, "
|
||||
"block-scaled fp8, with the joint schema head on the card for /v1/systemone")
|
||||
@@ -38,7 +38,6 @@
|
||||
*/
|
||||
#include <arch/rad_arch.h>
|
||||
#include <arch/rad_block_attn_gated.h>
|
||||
#include <arch/rad_block_clef.h>
|
||||
#include <arch/rad_block_gdn.h>
|
||||
#include <arch/rad_block_mlp.h>
|
||||
#include <arch/rad_block_vit.h>
|
||||
@@ -86,11 +85,6 @@ struct Model {
|
||||
VisionTower vit{};
|
||||
MediaRows mrows{};
|
||||
|
||||
/* ---- clef's joint schema head (arch/common/rad_block_clef.h), declared only when the
|
||||
* container says `decision.type=clef`; `clef.on` is false otherwise and every step below is
|
||||
* the one it was. */
|
||||
ClefHead clef{};
|
||||
|
||||
std::vector<Layer> layers;
|
||||
};
|
||||
|
||||
@@ -430,12 +424,6 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
rad_note(b, "the %lld MTP/NextN layer(s) under `mtp.` are not declared: this plugin "
|
||||
"serves the trunk only", (long long)nextn);
|
||||
|
||||
/* clef's head reads the final norm's rows and the lm_head, and keeps its own cache group,
|
||||
* bound well past the trunk's layers. */
|
||||
if (ClefHead::present(meta))
|
||||
RAD_ARCH_TRY(m.clef.declare(b, meta, ctx, nm, g, m.b_h, m.b_logits, m.w_lm_head,
|
||||
m.kv_full, (int)g.n_layer + 256));
|
||||
|
||||
/* The vision tower, last, so its activations share the arena with every buffer above. */
|
||||
if (m.media) RAD_ARCH_TRY(m.vit.declare(b, meta, ctx, nm, g.n_embd, (int)g.n_layer + 64));
|
||||
return RAD_OK;
|
||||
@@ -467,8 +455,6 @@ static void step(RadCtx* c, const RadBatch* batch) {
|
||||
|
||||
RAD_ISSUE(c, m.op_final_norm,
|
||||
brows(m.b_x, batch->n_tok), RAD_W(m.w_out_norm), brows(m.b_h, batch->n_tok));
|
||||
/* clef: every token's final hidden state into the head's cache (a no-op without the head). */
|
||||
m.clef.step_tokens(c, batch, m.b_h);
|
||||
|
||||
/* The lm_head runs only on the rows the sampler asked for; a mid-prompt prefill chunk has
|
||||
* n_out zero and skips it. */
|
||||
@@ -480,9 +466,6 @@ static void step(RadCtx* c, const RadBatch* batch) {
|
||||
RAD_ISSUE_N(c, m.op_logits, batch->n_out,
|
||||
brows(m.b_hout, batch->n_out), RAD_W(m.w_lm_head),
|
||||
brows(m.b_logits, batch->n_out));
|
||||
/* clef: the head over each sequence that carries a request's words, after the lm_head
|
||||
* has written the row it adds to. */
|
||||
m.clef.step_heads(c, batch, m.b_logits, m.w_lm_head);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,6 @@
|
||||
#endif
|
||||
#include <arch/rad_block_mtp_fp8.h>
|
||||
#include <arch/rad_block_dflash2.h>
|
||||
#include <arch/rad_block_clef.h>
|
||||
#include <arch/rad_block_vit.h>
|
||||
|
||||
#include <cstring>
|
||||
@@ -206,10 +205,6 @@ struct Model {
|
||||
VisionTower vit{};
|
||||
MediaRows mrows{};
|
||||
|
||||
/* ---- clef's joint schema head (arch/common/rad_block_clef.h), declared only when the
|
||||
* container says `decision.type=clef`; off, every step below is the one it was. */
|
||||
ClefHead clef{};
|
||||
|
||||
std::vector<Layer> layers;
|
||||
|
||||
/* The pipelined prefill (step_pipelined): on where declare allowed it; the bounds buffer it
|
||||
@@ -1274,12 +1269,6 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
rad_note(b, "the %lld MTP/NextN layer(s) under `mtp.` are not loaded: this deployment "
|
||||
"does not speculate", (long long)nextn);
|
||||
|
||||
/* clef's head (arch/common/rad_block_clef.h) reads the final norm's rows and the lm_head,
|
||||
* and keeps its own cache group, bound well past the trunk's and a drafter's layers. */
|
||||
if (ClefHead::present(meta))
|
||||
RAD_ARCH_TRY(m.clef.declare(b, meta, ctx, nm, g, m.a_h.x, m.b_logits, m.w_lm_head,
|
||||
m.kv_full, (int)g.n_layer + 256));
|
||||
|
||||
/* The vision tower, last: an encoder pass issues nothing else, so its activations share the
|
||||
* arena with every buffer above. Its weight groups start past every text layer, the MTP head
|
||||
* and a drafter's. */
|
||||
@@ -1504,8 +1493,6 @@ static void step_pipelined(RadCtx* c, const RadBatch* batch, Model& m, const int
|
||||
}
|
||||
pipe_wait1(c);
|
||||
if (L > 0) pipe_taps(c, m, L - 1, R, T - R);
|
||||
/* clef: both pieces' final norm is done by here; the head's cache takes every row. */
|
||||
m.clef.step_tokens(c, batch, m.a_h.x);
|
||||
|
||||
if (batch->n_out > 0) {
|
||||
RAD_ISSUE_N(c, m.op_gather, batch->n_out,
|
||||
@@ -1514,7 +1501,6 @@ static void step_pipelined(RadCtx* c, const RadBatch* batch, Model& m, const int
|
||||
RAD_ISSUE_N(c, m.op_logits, batch->n_out,
|
||||
brows(m.b_hout, batch->n_out), RAD_W(m.w_lm_head),
|
||||
brows(m.b_logits, batch->n_out));
|
||||
m.clef.step_heads(c, batch, m.b_logits, m.w_lm_head);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1610,8 +1596,6 @@ static void step(RadCtx* c, const RadBatch* batch) {
|
||||
|
||||
RAD_ISSUE(c, m.op_final_norm,
|
||||
brows(m.b_x, batch->n_tok), RAD_W(m.w_out_norm), brows(m.a_h.x, batch->n_tok));
|
||||
/* clef: every token's final hidden state into the head's cache (a no-op without the head). */
|
||||
m.clef.step_tokens(c, batch, m.a_h.x);
|
||||
|
||||
if (batch->n_out > 0) {
|
||||
RAD_ISSUE_N(c, m.op_gather, batch->n_out,
|
||||
@@ -1621,7 +1605,6 @@ static void step(RadCtx* c, const RadBatch* batch) {
|
||||
RAD_ISSUE_N(c, m.op_logits, batch->n_out,
|
||||
brows(m.b_hout, batch->n_out), RAD_W(m.w_lm_head),
|
||||
brows(m.b_logits, batch->n_out));
|
||||
m.clef.step_heads(c, batch, m.b_logits, m.w_lm_head);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user