Archived
arch/common: group-limited sigmoid routing and a SwiGLU clipped after the SiLU, for Ling-3.0
GlmRouter takes `groups` and `topk_groups` and issues router_sigmoid_group_topk above one group. MoeFP8 passes them on (a grouped router runs the separate selection, not the single-group fused one), takes a clamp of its own for the shared arm, and with `swiglu_step` clips both arms after the SiLU; GateQuantFP8 issues swiglu_step for that, without the fused clamp-and-quantise. Every default is the existing behaviour, so no other graph changes.
This commit is contained in:
1 parent
523349dd8f
commit
1c2f55027c
3 files changed
+51
-21
No files matched your search
@@ -182,8 +182,19 @@ struct MoeFP8 {
|
||||
/* Block-fp8 experts whose scale plane is f32 (format 9, dtype fp8a8f32). */
|
||||
int expert_f32_scale = 0;
|
||||
double route_scale = 1.0;
|
||||
/* With `sigmoid_router`: group-limited selection over `n_group` groups, `topk_group` kept
|
||||
* (router_sigmoid_group_topk; Ling-3.0). 1 is GLM's single group. The fused selection and
|
||||
* sort is single-group, so a grouped router runs the separate pair. */
|
||||
int64_t n_group = 1, topk_group = 1;
|
||||
/* Clamp of the SwiGLU product (swiglu_clamped); 0 is none. */
|
||||
double swiglu_limit = 0.0;
|
||||
/* The shared arm's clamp where it differs from the routed one (Ling-3.0 clamps its shared
|
||||
* expert at 5 or 7 and its routed ones at 4, in different layers); negative: the routed
|
||||
* arm's. */
|
||||
double shared_swiglu_limit = -1.0;
|
||||
/* Clip after the SiLU (`swiglu_step`) rather than before it (`swiglu_clamped`), for both
|
||||
* arms. */
|
||||
int swiglu_step = 0;
|
||||
/* With `swiglu_limit`: the clamped product and its quantiser as one launch
|
||||
* (GateQuantFP8::fuse_clamped), for the routed and the shared arm. */
|
||||
int swiglu_quant = 0;
|
||||
@@ -618,6 +629,8 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
int ar_in, bool ar_out_) {
|
||||
g = geom; c = src.cfg; w = wire; layer = l;
|
||||
ar_out = ar_out_;
|
||||
if (c.n_group > 1) c.router_fuse = 0;
|
||||
const double sh_limit = c.shared_swiglu_limit < 0 ? c.swiglu_limit : c.shared_swiglu_limit;
|
||||
/* 0 means not expert-parallel: this rank owns every expert. */
|
||||
if (c.n_expert_all <= 0) c.n_expert_all = c.n_expert;
|
||||
if (c.n_expert <= 0 || c.top_k <= 0 || c.top_k > c.n_expert_all || c.n_ff_exp <= 0)
|
||||
@@ -764,6 +777,8 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
rc.rows = c.rows;
|
||||
rc.norm = c.norm_topk;
|
||||
rc.route_scale = c.route_scale;
|
||||
rc.groups = c.n_group;
|
||||
rc.topk_groups = c.topk_group;
|
||||
const GlmRouter::Wire wire{ w.h.x, w.logits, w.ids, w.ew };
|
||||
const GlmRouter::Src rs{ src.router, src.router_bias };
|
||||
RAD_ARCH_TRY(glm_router.declare(b, nm, g, l, nm.f("blk.%d.glm_router", l), rc, wire, rs));
|
||||
@@ -997,7 +1012,7 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
Geom gx = g;
|
||||
gx.w_bf16 = true;
|
||||
RAD_ARCH_TRY(gq_exp.declare(b, gx, w.egu, w.eff, c.n_ff_exp, "silu", c.rows * c.top_k,
|
||||
true, false, c.swiglu_limit));
|
||||
true, false, c.swiglu_limit, c.swiglu_step != 0));
|
||||
op_dn = rw(b, rad_decl_op(b, "moe_gemm",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, c.rows), RAD_INT("N", g.n_embd),
|
||||
RAD_INT("K", c.n_ff_exp), RAD_INT("n_expert", ne),
|
||||
@@ -1131,7 +1146,7 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
* the rotated op at no extra launch. */
|
||||
gq_exp.fuse_clamped = c.swiglu_quant != 0;
|
||||
RAD_ARCH_TRY(gq_exp.declare(b, g, w.egu, w.eff, c.n_ff_exp, "silu", c.rows * c.top_k,
|
||||
false, rot, c.swiglu_limit));
|
||||
false, rot, c.swiglu_limit, c.swiglu_step != 0));
|
||||
{
|
||||
const std::vector<rad_weight> tab = tables(w_dn, w_dns);
|
||||
rad_op h = ncls == 4
|
||||
@@ -1234,7 +1249,7 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
Geom gx = g;
|
||||
gx.w_bf16 = true;
|
||||
RAD_ARCH_TRY(gq_prot.declare(b, gx, b_pgu, pff, wp, "silu", c.rows * c.top_k, true,
|
||||
false, c.swiglu_limit));
|
||||
false, c.swiglu_limit, c.swiglu_step != 0));
|
||||
op_pdn = rw(b, rad_decl_op(b, "moe_gemm",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, c.rows), RAD_INT("N", g.n_embd),
|
||||
RAD_INT("K", wp), RAD_INT("n_expert", np),
|
||||
@@ -1374,7 +1389,7 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
RAD_ARCH_TRY(rad_buf_concurrent(b, w.sff.q8));
|
||||
RAD_ARCH_TRY(rad_buf_concurrent(b, w.sff.s8));
|
||||
}
|
||||
if (!w.sff.q || c.swiglu_limit>0 || (sh_down.reads_x && !(w.sff.q8_fed && sh_down.probed_i8)))
|
||||
if (!w.sff.q || sh_limit>0 || (sh_down.reads_x && !(w.sff.q8_fed && sh_down.probed_i8)))
|
||||
RAD_ARCH_TRY(rad_buf_concurrent(b, w.sff.x));
|
||||
RAD_ARCH_TRY(rad_buf_concurrent(b, w.sout));
|
||||
RAD_ARCH_TRY(rad_buf_concurrent(b, w.sgate));
|
||||
@@ -1391,7 +1406,7 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
gq_sh.fuse_clamped = c.swiglu_quant != 0;
|
||||
RAD_ARCH_TRY(gq_sh.declare(b, g, w.sgu, w.sff, c.n_ff_shared, "silu", c.rows,
|
||||
sh_down.reads_x && !(w.sff.q8_fed && sh_down.probed_i8), false,
|
||||
c.swiglu_limit));
|
||||
sh_limit, c.swiglu_step != 0));
|
||||
RAD_ARCH_TRY(sh_down.declare(b, nm, g, down_base,
|
||||
g.n_embd, c.n_ff_shared, RAD_SHARD_COL, grp_layer(l),
|
||||
{ shared_down },
|
||||
|
||||
Reference in new issue
Block a user