Archived
The plugin carried the draft head's buffers, weights and ops in its declare and its draft pass
in its step, with the three ops that join the head to its layer declared inside the layer
function; each GLM block carried its core in a header of its own (rad_block_mla_latent.h,
rad_block_kda_state.h, rad_block_dsa_cache.h), the split threshold sat in rad_tp_split.h beside
the router's column split, and 64 / world, 8192 / world, 2048 / world were spelled across the
plugin and the blocks. tests/arch_test.cpp held the recording builder, the run-phase fakes, the
step lint, the batch kits and the fingerprints beside every architecture's cases, 9.5k lines in
one translation unit, GLM-5.3's among them.
Now one block a file in arch/common: rad_block_glm_{mhc,kda,mla,indexer,router,mtp}.h, the
cores joined to their blocks, and GlmMtp the draft head in three parts (inputs, join, head),
declared and stepped around the plugin's layer 45. rad_glm_tp.h (GlmTp) holds the widths a
rank's shard divides, the one threshold kSplitRows and the replicated all_reduce declared once;
SplitF32Proj moves over unchanged. The plugin reads as the stream's buffers, then each block's,
the KV groups, the layers, the head and the draft head.
tests/arch_fakes.h holds the fakes and the helpers every architecture test needs, included by
one translation unit a binary (neither binary links rad_core, as before); GLM-5.3's cases are
tests/glm5next_test.cpp, which includes only its plugin, with two cases new: every op the plugin
issues carries the operand count its schema declares (the kernel libraries' schemas under
$RADIANCE_HOME/kernels, counted as core/runtime/issue.cpp counts), and every declared weight
reads an entry the served container holds, at the dtype its stored encoding calls for (the
container's names and encodings as rad-info -v lists them).
Every declared name, declaration order and issue order is as it was: the pinned graph and step
hashes at one and eight ranks are the values arch_test pinned before the move (world 1
0xed3fc26c486ea1b5 / 0x98ba2952bb37b075, world 8 0x8204e073efdeee0c / 0x1279aecfe4e32d9a), and
arch_test's pins of the other architectures are unchanged.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
83 lines
3.8 KiB
C++
83 lines
3.8 KiB
C++
/* GLM noaux_tc router. Correction bias changes selection only; mixture weights
|
|
* come from the uncorrected sigmoid probabilities. All routing arithmetic is F32. */
|
|
#ifndef RAD_BLOCK_GLM_ROUTER_H
|
|
#define RAD_BLOCK_GLM_ROUTER_H
|
|
#include "rad_glm_tp.h"
|
|
#include <cmath>
|
|
|
|
namespace rad {
|
|
namespace arch {
|
|
struct GlmRouter {
|
|
struct Config {
|
|
int64_t experts = 288, top_k = 8, rows = 32;
|
|
int norm = 1;
|
|
double route_scale = 2.5;
|
|
};
|
|
struct Src {
|
|
const char *weight = nullptr, *correction = nullptr;
|
|
};
|
|
struct Wire {
|
|
rad_buf input = 0, logits = 0, ids = 0, weights = 0;
|
|
};
|
|
Geom g{};
|
|
Config c{};
|
|
Wire w{};
|
|
rad_weight projection = 0, correction = 0;
|
|
rad_op op_project = 0, op_select = 0;
|
|
SplitF32Proj split{};
|
|
|
|
int declare(RadBuilder* b, Names& nm, const Geom& geom, int layer, const char* name,
|
|
const Config& cfg, const Wire& wire, const Src& src) {
|
|
g = geom;
|
|
c = cfg;
|
|
w = wire;
|
|
if (!b || !name || !src.weight || !src.correction || g.n_embd < 1 || c.experts < 1 ||
|
|
c.experts > 512 || c.top_k < 1 || c.top_k > c.experts || c.rows < 1 ||
|
|
c.rows > g.max_tok || !std::isfinite(c.route_scale) || c.route_scale <= 0 || !w.input ||
|
|
!w.logits || !w.ids || !w.weights || w.logits == w.weights)
|
|
return RAD_E_INVAL;
|
|
const char *pn = nm.f("%s.weight", name), *cn = nm.f("%s.correction", name);
|
|
RAD_ARCH_TRY(map_copy(b, pn, src.weight));
|
|
RAD_ARCH_TRY(map_copy(b, cn, src.correction));
|
|
projection = decl_w(b, pn, RAD_F32, { c.experts, g.n_embd }, RAD_ACCESS_PER_TOKEN,
|
|
RAD_SHARD_NONE, grp_layer(layer));
|
|
correction = decl_w(b, cn, RAD_F32, { c.experts }, RAD_ACCESS_PER_TOKEN, RAD_SHARD_NONE,
|
|
grp_layer(layer));
|
|
if (!projection || !correction) return RAD_E_INVAL;
|
|
op_project = rw(b,
|
|
RAD_OP(b, "gemm_nt_f32",
|
|
RAD_PARAMS(RAD_RANGE("M", 1, c.rows), RAD_INT("N", c.experts),
|
|
RAD_INT("K", g.n_embd), RAD_STR("dtype", "bf16")),
|
|
RAD_WEIGHTS(projection)),
|
|
{ w.input }, { w.logits });
|
|
RAD_ARCH_TRY(split.declare(b, nm, g, name, c.rows, c.experts, g.n_embd, projection, w.input,
|
|
w.logits));
|
|
op_select =
|
|
rw(b,
|
|
RAD_OP(b, "router_sigmoid_topk",
|
|
RAD_PARAMS(RAD_RANGE("M", 1, c.rows), RAD_INT("n_expert", c.experts),
|
|
RAD_INT("top_k", c.top_k), RAD_INT("norm", c.norm),
|
|
RAD_F64("route_scale", c.route_scale), RAD_STR("dtype", "f32")),
|
|
RAD_WEIGHTS(correction)),
|
|
{ w.logits }, { w.ids, w.weights });
|
|
return op_project && op_select ? RAD_OK : RAD_E_INVAL;
|
|
}
|
|
void project(RadCtx* ctx, int64_t first, int64_t rows, int64_t output_first = 0) const {
|
|
if (split.takes(rows))
|
|
split.step(ctx, rows, brow_slice(w.input, first, rows, g.n_embd), projection,
|
|
brow_slice(w.logits, output_first, rows, c.experts));
|
|
else
|
|
RAD_ISSUE_N(ctx, op_project, rows, brow_slice(w.input, first, rows, g.n_embd),
|
|
RAD_W(projection), brow_slice(w.logits, output_first, rows, c.experts));
|
|
}
|
|
void step(RadCtx* ctx, int64_t first, int64_t rows, int64_t output_first = 0) const {
|
|
project(ctx, first, rows, output_first);
|
|
RAD_ISSUE_N(ctx, op_select, rows, brow_slice(w.logits, output_first, rows, c.experts),
|
|
RAD_W(correction), brow_slice(w.ids, output_first, rows, c.top_k),
|
|
brow_slice(w.weights, output_first, rows, c.top_k));
|
|
}
|
|
};
|
|
}
|
|
} // namespace rad::arch
|
|
#endif
|