Archived
arch/nemotronh: Nemotron-3.5-Bolt-74B-A9B
NVIDIA's Nemotron-H hybrid from its bf16 checkpoint: 40 Mamba-2, 40 latent-MoE and 8 NoPE attention blocks, the LiLiCorr drafter (7 drafts a step) and the C-RADIO tower with its projector, at one, two or four ranks. docs/ARCHITECTURES.md describes the model. nemotronh_test: the drafter's KV heads at two and four ranks, a speculative step at four, and the arena's sizing declares.
This commit is contained in:
1 parent
cc46e3b714
commit
0c4292e45b
7 files changed
+1906
-11
No files matched your search
@@ -0,0 +1,7 @@
|
||||
if(NOT COMMAND rad_add_plugin)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(nemotronh LANGUAGES CXX)
|
||||
find_package(radiance REQUIRED)
|
||||
rad_plugin_defaults()
|
||||
endif()
|
||||
rad_add_plugin(nemotronh architectures SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nemotronh.cpp)
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,348 @@
|
||||
/* radio.h -- Nemotron-H Omni's vision encoder: C-RADIO (v4-H) and the projector after it (mlp1).
|
||||
*
|
||||
* Per encoder pass (RadBatch::enc). The processor (core/mm, Family::Radio) gives every segment
|
||||
* `n_prefix` zero rows ahead of its patches, with coordinate (-1, k):
|
||||
*
|
||||
* x = rows @ W^T one GEMM for both projections: a row is a
|
||||
* tubelet's frames then a picture's patch, the part
|
||||
* not in use zero, and W = [video_embedder |
|
||||
* embedder] concatenated at convert; no bias
|
||||
* x += CPE(table, row, col), or prefix[k] grid_embed_cpe: the 128 x 128 table resampled
|
||||
* half-pixel bilinear onto a square of the grid's
|
||||
* longer side and cropped to it; a prefix row takes
|
||||
* the k-th class or register token
|
||||
* depth times (pre-norm, LayerScale 1):
|
||||
* x += proj(attn(qkv(LN1(x)))) full attention within a segment, no rotary
|
||||
* x += fc2(gelu(fc1(LN2(x)))) exact GELU
|
||||
* y = each segment's patch rows gather_rows: the prefix rows dropped
|
||||
* out = l2(relu(l1(rms(y viewed [P/4, 4 * width])))^2)
|
||||
*
|
||||
* which is transformers' RadioModel (make_preprocessor_external) then NemotronH_Omni's vision
|
||||
* projector with vision_final_layernorm off. The pixel shuffle (ps v2) is the view: the processor
|
||||
* keeps a 2 x 2 block's patches consecutive, (dy, dx), the order the shuffle concatenates them;
|
||||
* the tower is order-independent within a segment (attention is permutation-equivariant, every
|
||||
* other layer is per row, the position term is sampled at each row's own coordinate).
|
||||
*
|
||||
* A pass is one grid (RadEncoderDecl::one_grid), so its segments are equally long and each
|
||||
* segment's patch rows sit at a fixed offset, which `step` gathers with slices of one identity
|
||||
* index. Replicated, per-request weights and pass-sized activations, as in
|
||||
* arch/common/rad_block_vit.h's tower.
|
||||
*/
|
||||
#ifndef NEMOTRONH_RADIO_H
|
||||
#define NEMOTRONH_RADIO_H
|
||||
|
||||
#include <arch/rad_arch.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace nemotronh {
|
||||
|
||||
using namespace rad::arch;
|
||||
|
||||
struct Radio {
|
||||
int64_t depth = 0, width = 0, heads = 0, ff = 0, patch = 0, merge = 0, side = 0, npre = 0;
|
||||
int64_t tubelet = 0, head_dim = 0, patch_dim = 0, proj_hidden = 0, n_embd = 0, P = 0, R = 0;
|
||||
float eps = 1e-6f;
|
||||
bool on = false;
|
||||
|
||||
struct Layer {
|
||||
rad_weight n1w = 0, n1b = 0, n2w = 0, n2b = 0;
|
||||
rad_weight qkv_w = 0, qkv_b = 0, out_w = 0, out_b = 0;
|
||||
rad_weight up_w = 0, up_b = 0, down_w = 0, down_b = 0;
|
||||
rad_op ln1 = 0, qkv = 0, attn = 0, proj = 0, ln2 = 0, up = 0, down = 0;
|
||||
};
|
||||
std::vector<Layer> L;
|
||||
rad_weight w_patch = 0, w_pos = 0, w_pre = 0, mn_w = 0, m1_w = 0, m2_w = 0;
|
||||
rad_op op_patch = 0, op_pos = 0, op_seq = 0, op_gather = 0, op_mln = 0, op_m1 = 0;
|
||||
rad_op op_act = 0, op_m2 = 0;
|
||||
rad_buf b_x = 0, b_h = 0, b_qkv = 0, b_att = 0, b_ff = 0, b_seq = 0, b_g = 0, b_mn = 0;
|
||||
rad_buf b_mf = 0, b_ma = 0, b_out = 0;
|
||||
|
||||
/* A tower to declare: the container is a Nemotron-H Omni one, whose vision_config is RADIO's. */
|
||||
static bool present(const RadModelMeta* m) {
|
||||
return !std::strcmp(rad_meta_gets(m, "vision_config.model_type", ""), "radio") &&
|
||||
rad_meta_geti(m, "vision_config.num_hidden_layers", 0) > 0;
|
||||
}
|
||||
|
||||
int declare(RadBuilder* b, const RadModelMeta* m, const RadBuildCtx* ctx, Names& nm,
|
||||
int64_t model_embd, int first_group);
|
||||
void step(RadCtx* c, const RadBatch* batch) const;
|
||||
};
|
||||
|
||||
inline int Radio::declare(RadBuilder* b, const RadModelMeta* m, const RadBuildCtx* ctx, Names& nm,
|
||||
int64_t model_embd, int first_group) {
|
||||
on = false;
|
||||
if (!present(m) || ctx->max_enc_patches <= 0) return RAD_OK;
|
||||
|
||||
depth = rad_meta_geti(m, "vision_config.num_hidden_layers", 0);
|
||||
width = rad_meta_geti(m, "vision_config.hidden_size", 0);
|
||||
heads = rad_meta_geti(m, "vision_config.num_attention_heads", 0);
|
||||
ff = (int64_t)std::llround(rad_meta_getf(m, "vision_config.mlp_ratio", 0.0) * (double)width);
|
||||
patch = rad_meta_geti(m, "vision_config.patch_size", 0);
|
||||
eps = (float)rad_meta_getf(m, "vision_config.layer_norm_eps", 1e-6);
|
||||
side = rad_meta_geti(m, "vision_config.max_img_size", 0) / (patch > 0 ? patch : 1);
|
||||
npre = rad_meta_geti(m, "vision_config.num_cls_tokens", 0) +
|
||||
rad_meta_geti(m, "vision_config.num_registers", 0);
|
||||
tubelet = rad_meta_geti(m, "vision_config.video_temporal_patch_size",
|
||||
rad_meta_geti(m, "video_temporal_patch_size", 0));
|
||||
const double ratio = rad_meta_getf(m, "downsample_ratio", 0.0);
|
||||
merge = ratio > 0.0 ? (int64_t)std::llround(1.0 / ratio) : 0;
|
||||
proj_hidden = rad_meta_geti(m, "projector_hidden_size", 0);
|
||||
n_embd = model_embd;
|
||||
const int64_t chans = rad_meta_geti(m, "vision_config.num_channels", 3);
|
||||
if (depth <= 0 || width <= 0 || heads <= 0 || ff <= 0 || patch <= 0 || side <= 0 ||
|
||||
npre <= 0 || tubelet <= 0 || merge <= 0 || proj_hidden <= 0 || width % heads ||
|
||||
chans != 3) {
|
||||
fprintf(stderr, "radiance: nemotronh: the container's RADIO vision_config is incomplete or "
|
||||
"inconsistent (layers %lld, hidden %lld, heads %lld, ff %lld, patch %lld, "
|
||||
"table %lld, prefix %lld, tubelet %lld, merge %lld, projector %lld)\n",
|
||||
(long long)depth, (long long)width, (long long)heads, (long long)ff,
|
||||
(long long)patch, (long long)side, (long long)npre, (long long)tubelet,
|
||||
(long long)merge, (long long)proj_hidden);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
/* What this tower serves of RADIO's options: the plain GELU MLP, LayerScale 1 (no stored
|
||||
* scales), q/k/v with biases, and no final layer norm before the projector. */
|
||||
const char* act = rad_meta_gets(m, "vision_config.hidden_act", "gelu");
|
||||
const bool swiglu = rad_meta_geti(m, "vision_config.use_swiglu_ffn", 0) != 0 ||
|
||||
!std::strcmp(rad_meta_gets(m, "vision_config.use_swiglu_ffn", ""), "true");
|
||||
const bool final_ln = rad_meta_geti(m, "vision_final_layernorm", 0) != 0 ||
|
||||
!std::strcmp(rad_meta_gets(m, "vision_final_layernorm", ""), "true");
|
||||
if (std::strcmp(act, "gelu") || swiglu || final_ln ||
|
||||
rad_meta_getf(m, "vision_config.layerscale_value", 1.0) != 1.0) {
|
||||
fprintf(stderr, "radiance: nemotronh: this RADIO tower (activation '%s'%s%s, layer scale "
|
||||
"%g) is not the one served: GELU MLP, layer scale 1, no final layer norm\n",
|
||||
act, swiglu ? ", SwiGLU" : "", final_ln ? ", final layer norm" : "",
|
||||
rad_meta_getf(m, "vision_config.layerscale_value", 1.0));
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
head_dim = width / heads;
|
||||
const int64_t pp = chans * patch * patch;
|
||||
patch_dim = pp * (1 + tubelet);
|
||||
const int64_t mm = merge * merge, mw = mm * width;
|
||||
|
||||
/* A pass's rows, prefix rows included; the output rows are at most a quarter of them. */
|
||||
P = ctx->max_enc_patches;
|
||||
const int64_t max_seg = P;
|
||||
if (ctx->shape_probe) {
|
||||
const int64_t r = std::min<int64_t>(P, ctx->max_tok);
|
||||
P = std::max<int64_t>(mm, r / mm * mm);
|
||||
}
|
||||
R = P / mm;
|
||||
if (R <= 0) return RAD_E_SHAPE;
|
||||
const int ACC = RAD_ACCESS_PER_REQUEST;
|
||||
|
||||
auto bw = [&](const char* dn, const char* src, std::initializer_list<int64_t> shp,
|
||||
RadWeightGroup g) -> rad_weight {
|
||||
if (map_copy(b, dn, src) < 0) return 0;
|
||||
return decl_w(b, dn, RAD_BF16, shp, ACC, RAD_SHARD_NONE, g);
|
||||
};
|
||||
const char* pg = "vision_model.radio_model.model.patch_generator.";
|
||||
/* [video_embedder | embedder] along K: one GEMM for a row of either kind. */
|
||||
if (map_concat(b, nm.f("v.patch.weight"),
|
||||
{ nm.ckpt("%svideo_embedder.weight", pg), nm.ckpt("%sembedder.weight", pg) },
|
||||
1) < 0)
|
||||
return RAD_E_INVAL;
|
||||
/* Whether the tower is here at all: its stem's encoding, which convert answers from the
|
||||
* checkpoint and load from the container alike. A text-only cut (a few blocks for a host
|
||||
* reference) or a container converted without it serves text; the map left behind is inert. */
|
||||
{
|
||||
RadEncoding enc;
|
||||
if (rad_weight_encoding(b, nm.f("v.patch.weight"), &enc, nullptr, nullptr) != RAD_OK) {
|
||||
rad_note(b, "nemotronh: vision_config names a RADIO tower its weights are not here "
|
||||
"for; serving text");
|
||||
return RAD_OK;
|
||||
}
|
||||
}
|
||||
w_patch = decl_w(b, nm.f("v.patch.weight"), RAD_BF16, { width, patch_dim }, ACC,
|
||||
RAD_SHARD_NONE, grp_model());
|
||||
/* The checkpoint's [1, side * side, width] read as the [side * side, width] table. */
|
||||
w_pos = bw(nm.f("v.pos.weight"), nm.ckpt("%spos_embed", pg), { side * side, width }, grp_model());
|
||||
w_pre = bw(nm.f("v.prefix.weight"), nm.ckpt("%scls_token.token", pg), { npre, width },
|
||||
grp_model());
|
||||
L.assign((size_t)depth, Layer{});
|
||||
for (int64_t i = 0; i < depth; ++i) {
|
||||
Layer& l = L[(size_t)i];
|
||||
const RadWeightGroup g = grp_layer(first_group + (int)i);
|
||||
const int li = (int)i;
|
||||
const char* e = "vision_model.radio_model.model.blocks.%d.%s";
|
||||
l.n1w = bw(nm.f("v.blk.%d.norm1.weight", li), nm.ckpt(e, li, "norm1.weight"), { width }, g);
|
||||
l.n1b = bw(nm.f("v.blk.%d.norm1.bias", li), nm.ckpt(e, li, "norm1.bias"), { width }, g);
|
||||
l.qkv_w = bw(nm.f("v.blk.%d.qkv.weight", li), nm.ckpt(e, li, "attn.qkv.weight"), { 3 * width, width }, g);
|
||||
l.qkv_b = bw(nm.f("v.blk.%d.qkv.bias", li), nm.ckpt(e, li, "attn.qkv.bias"), { 3 * width }, g);
|
||||
l.out_w = bw(nm.f("v.blk.%d.proj.weight", li), nm.ckpt(e, li, "attn.proj.weight"), { width, width }, g);
|
||||
l.out_b = bw(nm.f("v.blk.%d.proj.bias", li), nm.ckpt(e, li, "attn.proj.bias"), { width }, g);
|
||||
l.n2w = bw(nm.f("v.blk.%d.norm2.weight", li), nm.ckpt(e, li, "norm2.weight"), { width }, g);
|
||||
l.n2b = bw(nm.f("v.blk.%d.norm2.bias", li), nm.ckpt(e, li, "norm2.bias"), { width }, g);
|
||||
l.up_w = bw(nm.f("v.blk.%d.fc1.weight", li), nm.ckpt(e, li, "mlp.fc1.weight"), { ff, width }, g);
|
||||
l.up_b = bw(nm.f("v.blk.%d.fc1.bias", li), nm.ckpt(e, li, "mlp.fc1.bias"), { ff }, g);
|
||||
l.down_w = bw(nm.f("v.blk.%d.fc2.weight", li), nm.ckpt(e, li, "mlp.fc2.weight"), { width, ff }, g);
|
||||
l.down_b = bw(nm.f("v.blk.%d.fc2.bias", li), nm.ckpt(e, li, "mlp.fc2.bias"), { width }, g);
|
||||
if (!l.n1w || !l.n1b || !l.n2w || !l.n2b || !l.qkv_w || !l.qkv_b || !l.out_w ||
|
||||
!l.out_b || !l.up_w || !l.up_b || !l.down_w || !l.down_b)
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
mn_w = bw(nm.f("v.proj.norm.weight"), nm.ckpt("mlp1.0.weight"), { mw }, grp_model());
|
||||
m1_w = bw(nm.f("v.proj.fc1.weight"), nm.ckpt("mlp1.1.weight"), { proj_hidden, mw }, grp_model());
|
||||
m2_w = bw(nm.f("v.proj.fc2.weight"), nm.ckpt("mlp1.3.weight"), { n_embd, proj_hidden }, grp_model());
|
||||
if (!w_patch || !w_pos || !w_pre || !mn_w || !m1_w || !m2_w) return RAD_E_INVAL;
|
||||
|
||||
/* ---- activations. `g` holds the gathered patch rows at `width` and is read by the norm as
|
||||
* R rows of mm * width (the pixel shuffle's view, no copy). */
|
||||
b_x = decl_b(b, nm.f("v.x"), RAD_BF16, { P, width });
|
||||
b_h = decl_b(b, nm.f("v.h"), RAD_BF16, { P, width });
|
||||
b_qkv = decl_b(b, nm.f("v.qkv"), RAD_BF16, { P, 3 * width });
|
||||
b_att = decl_b(b, nm.f("v.att"), RAD_BF16, { P, width });
|
||||
b_ff = decl_b(b, nm.f("v.ff"), RAD_BF16, { P, ff });
|
||||
b_seq = decl_b(b, nm.f("v.seq"), RAD_I32, { P });
|
||||
b_g = decl_b(b, nm.f("v.g"), RAD_BF16, { R, mw });
|
||||
b_mn = decl_b(b, nm.f("v.mn"), RAD_BF16, { R, mw });
|
||||
b_mf = decl_b(b, nm.f("v.mf"), RAD_BF16, { R, proj_hidden });
|
||||
b_ma = decl_b(b, nm.f("v.ma"), RAD_BF16, { R, proj_hidden });
|
||||
b_out = decl_b(b, nm.f("v.out"), RAD_BF16, { R, n_embd });
|
||||
if (!b_x || !b_h || !b_qkv || !b_att || !b_ff || !b_seq || !b_g || !b_mn || !b_mf || !b_ma ||
|
||||
!b_out)
|
||||
return RAD_E_INVAL;
|
||||
|
||||
auto gemm_b = [&](int64_t rows, int64_t N, int64_t K, const char* a, rad_weight w,
|
||||
rad_weight bias) -> rad_op {
|
||||
return RAD_OP(b, "gemm_nt_bias",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, rows), RAD_INT("N", N), RAD_INT("K", K),
|
||||
RAD_STR("dtype", "bf16"), RAD_STR("act", a)),
|
||||
RAD_WEIGHTS(w, bias));
|
||||
};
|
||||
auto gemm = [&](int64_t rows, int64_t N, int64_t K, rad_weight w) -> rad_op {
|
||||
return RAD_OP(b, "gemm_nt",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, rows), RAD_INT("N", N), RAD_INT("K", K),
|
||||
RAD_STR("dtype", "bf16")),
|
||||
RAD_WEIGHTS(w));
|
||||
};
|
||||
auto lnorm = [&](int64_t rows, rad_weight w, rad_weight bias) -> rad_op {
|
||||
return RAD_OP(b, "layernorm",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, rows), RAD_INT("n", width),
|
||||
RAD_F64("eps", eps), RAD_STR("dtype", "bf16")),
|
||||
RAD_WEIGHTS(w, bias));
|
||||
};
|
||||
|
||||
op_patch = rw(b, gemm(P, width, patch_dim, w_patch), {}, { b_x });
|
||||
op_pos = rw(b, RAD_OP(b, "grid_embed_cpe",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, P), RAD_INT("n", width),
|
||||
RAD_INT("side", side), RAD_INT("n_prefix", npre),
|
||||
RAD_STR("dtype", "bf16")),
|
||||
RAD_WEIGHTS(w_pos, w_pre)),
|
||||
{ b_x }, { b_x });
|
||||
op_seq = rw(b, RAD_OP(b, "iota",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, P), RAD_INT("start", 0), RAD_INT("step", 1)),
|
||||
RAD_NOWEIGHTS),
|
||||
{}, { b_seq });
|
||||
for (Layer& l : L) {
|
||||
l.ln1 = rw(b, lnorm(P, l.n1w, l.n1b), { b_x }, { b_h });
|
||||
l.qkv = rw(b, gemm_b(P, 3 * width, width, "none", l.qkv_w, l.qkv_b), { b_h }, { b_qkv });
|
||||
l.attn = rw(b, RAD_OP(b, "attn_dense",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, P), RAD_INT("head_dim", head_dim),
|
||||
RAD_INT("gqa", 1), RAD_INT("causal", 0),
|
||||
RAD_STR("dtype", "bf16"),
|
||||
RAD_F64("scale", 1.0 / std::sqrt((double)head_dim)),
|
||||
RAD_INT("max_seqlen", max_seg)),
|
||||
RAD_NOWEIGHTS),
|
||||
{ b_qkv }, { b_att });
|
||||
l.proj = rw(b, gemm_b(P, width, width, "none", l.out_w, l.out_b), { b_att, b_x }, { b_x });
|
||||
l.ln2 = rw(b, lnorm(P, l.n2w, l.n2b), { b_x }, { b_h });
|
||||
l.up = rw(b, gemm_b(P, ff, width, "gelu", l.up_w, l.up_b), { b_h }, { b_ff });
|
||||
l.down = rw(b, gemm_b(P, width, ff, "none", l.down_w, l.down_b), { b_ff, b_x }, { b_x });
|
||||
}
|
||||
op_gather = rw(b, RAD_OP(b, "gather_rows",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, P), RAD_INT("n", width),
|
||||
RAD_STR("dtype", "bf16")),
|
||||
RAD_NOWEIGHTS),
|
||||
{ b_x, b_seq }, { b_g });
|
||||
op_mln = rw(b, RAD_OP(b, "rmsnorm",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, R), RAD_INT("n", mw), RAD_F64("eps", 1e-5),
|
||||
RAD_STR("dtype", "bf16")),
|
||||
RAD_WEIGHTS(mn_w)),
|
||||
{ b_g }, { b_mn });
|
||||
op_m1 = rw(b, gemm(R, proj_hidden, mw, m1_w), { b_mn }, { b_mf });
|
||||
/* relu(x)^2: act_mul's "relu" with the one tensor in both operands. */
|
||||
op_act = rw(b, RAD_OP(b, "act_mul",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, R), RAD_INT("n", proj_hidden),
|
||||
RAD_STR("act", "relu"), RAD_STR("dtype", "bf16")),
|
||||
RAD_NOWEIGHTS),
|
||||
{ b_mf }, { b_ma });
|
||||
op_m2 = rw(b, gemm(R, n_embd, proj_hidden, m2_w), { b_ma }, { b_out });
|
||||
|
||||
if (!ctx->shape_probe) {
|
||||
RadEncoderDecl e{};
|
||||
e.name = "vision";
|
||||
e.modalities = RAD_MM_IMAGE | RAD_MM_VIDEO;
|
||||
e.patch_dim = patch_dim;
|
||||
e.merge = mm;
|
||||
e.max_patches = P;
|
||||
e.n_embd = n_embd;
|
||||
e.out = b_out;
|
||||
e.one_grid = 1;
|
||||
RAD_ARCH_TRY(rad_declare_encoder(b, &e));
|
||||
rad_note(b, "RADIO tower: %lld blocks of %lld (%lld heads x %lld), ff %lld, patch %lld "
|
||||
"(tubelet %lld), %lld x %lld position table, %lld prefix rows; projector %lld "
|
||||
"-> %lld -> %lld; %lld rows a pass",
|
||||
(long long)depth, (long long)width, (long long)heads, (long long)head_dim,
|
||||
(long long)ff, (long long)patch, (long long)tubelet, (long long)side,
|
||||
(long long)side, (long long)npre, (long long)mw, (long long)proj_hidden,
|
||||
(long long)n_embd, (long long)P);
|
||||
}
|
||||
on = true;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
inline void Radio::step(RadCtx* c, const RadBatch* batch) const {
|
||||
const int64_t Pn = batch->enc_n_patch, S = batch->enc_n_seg;
|
||||
const int64_t mm = merge * merge;
|
||||
const int64_t gh = S > 0 && batch->enc_seg_h ? batch->enc_seg_h[0] : 0;
|
||||
const int64_t gw = S > 0 && batch->enc_seg_w ? batch->enc_seg_w[0] : 0;
|
||||
const int64_t seg = npre + gh * gw, Rn = S * gh * gw / (mm > 0 ? mm : 1);
|
||||
if (!on || Pn <= 0 || Pn > P || S <= 0 || gh <= 0 || gw <= 0 || (gh * gw) % mm ||
|
||||
S * seg != Pn || Rn > R) {
|
||||
rad_step_fail(c, "nemotronh: an encoder pass this program's RADIO tower cannot serve: no "
|
||||
"tower, more rows than it was declared for, or segments that are not one "
|
||||
"grid of whole merged rows behind their prefix rows");
|
||||
return;
|
||||
}
|
||||
const RadOperand pix = praw2(batch->enc_pixels, RAD_BF16, Pn, patch_dim);
|
||||
const RadOperand crd = praw2(batch->enc_coord, RAD_I32, 4, Pn);
|
||||
const RadOperand cu = praw(batch->enc_cu, RAD_I32, S + 1);
|
||||
|
||||
RAD_ISSUE_N(c, op_patch, Pn, pix, RAD_W(w_patch), brows(b_x, Pn));
|
||||
RAD_ISSUE_N(c, op_pos, Pn, brows(b_x, Pn), RAD_W(w_pos), crd, RAD_W(w_pre));
|
||||
RAD_ISSUE_N(c, op_seq, Pn, brows(b_seq, Pn));
|
||||
for (const Layer& l : L) {
|
||||
RAD_ISSUE_N(c, l.ln1, Pn, brows(b_x, Pn), RAD_W(l.n1w), RAD_W(l.n1b), brows(b_h, Pn));
|
||||
RAD_ISSUE_N(c, l.qkv, Pn, brows(b_h, Pn), RAD_W(l.qkv_w), RAD_W(l.qkv_b), RAD_NONE,
|
||||
brows(b_qkv, Pn));
|
||||
RAD_ISSUE_N(c, l.attn, Pn,
|
||||
bcol(b_qkv, 0, width, Pn), bcol(b_qkv, width, width, Pn),
|
||||
bcol(b_qkv, 2 * width, width, Pn), cu, brows(b_att, Pn));
|
||||
RAD_ISSUE_N(c, l.proj, Pn, brows(b_att, Pn), RAD_W(l.out_w), RAD_W(l.out_b),
|
||||
brows(b_x, Pn), brows(b_x, Pn));
|
||||
RAD_ISSUE_N(c, l.ln2, Pn, brows(b_x, Pn), RAD_W(l.n2w), RAD_W(l.n2b), brows(b_h, Pn));
|
||||
RAD_ISSUE_N(c, l.up, Pn, brows(b_h, Pn), RAD_W(l.up_w), RAD_W(l.up_b), RAD_NONE,
|
||||
brows(b_ff, Pn));
|
||||
RAD_ISSUE_N(c, l.down, Pn, brows(b_ff, Pn), RAD_W(l.down_w), RAD_W(l.down_b),
|
||||
brows(b_x, Pn), brows(b_x, Pn));
|
||||
}
|
||||
/* Each segment's patch rows, behind its prefix rows, into `g` at width: segment s's are rows
|
||||
* [s * seg + npre, (s + 1) * seg) of x, which the identity index names by a slice. */
|
||||
const int64_t hw = gh * gw;
|
||||
for (int64_t s = 0; s < S; ++s)
|
||||
RAD_ISSUE_N(c, op_gather, hw, brows(b_x, Pn), brow_slice(b_seq, s * seg + npre, hw, 1),
|
||||
brow_slice(b_g, s * hw / mm, hw / mm, mm * width));
|
||||
RAD_ISSUE_N(c, op_mln, Rn, brows(b_g, Rn), RAD_W(mn_w), brows(b_mn, Rn));
|
||||
RAD_ISSUE_N(c, op_m1, Rn, brows(b_mn, Rn), RAD_W(m1_w), brows(b_mf, Rn));
|
||||
RAD_ISSUE_N(c, op_act, Rn, brows(b_mf, Rn), brows(b_mf, Rn), brows(b_ma, Rn));
|
||||
RAD_ISSUE_N(c, op_m2, Rn, brows(b_ma, Rn), RAD_W(m2_w), brows(b_out, Rn));
|
||||
}
|
||||
|
||||
} /* namespace nemotronh */
|
||||
|
||||
#endif /* NEMOTRONH_RADIO_H */
|
||||
@@ -19,6 +19,7 @@ plugin claims.
|
||||
| `arch/qwen4exp_fp8` | `qwen4exp` | *(empty)* | Qwen4-Exp (Qwen3.8-Flash-Next), a bf16 checkpoint quantised at convert, or Qwen's FP8 release as it ships |
|
||||
| `arch/glm5next` | `glm5next` | *(empty)* | GLM-5.3-Flash from AMD's Quark MXFP4 export: four mHC residual streams over 34 KDA and 11 sparse latent-attention (MLA) layers with a DSA indexer, 288 MXFP4 experts at top-8 under sigmoid routing, block-FP8 attention and dense layers at f32 scales, each weight served as stored; its MTP layer is a serial drafter. Pictures through its vision tower (`arch/common/rad_block_glm_vision.h`); bf16 KV |
|
||||
| `arch/bailing_hybrid` | `bailinghybrid` | *(empty)* | Ling-3.0-flash and its fine-tunes (Ling-3.0-flash-Sante) from the bf16 checkpoint: 35 KDA and 7 dense latent-attention (MLA) layers with a rotary part and a head-wise gate, 512 experts at top-8 under group-limited sigmoid routing with an ungated shared expert, the routed experts as the recipe stores them (`data/recipes/ling3-w4a8-rtn.recipe`); its MTP layer is a serial drafter; bf16 KV |
|
||||
| `arch/nemotronh` | `nemotronh` | *(empty)* | Nemotron-3.5-Bolt-74B-A9B (`nemotron_h_omni` around `nemotron_h_puzzle`), its language model from the bf16 checkpoint: 40 Mamba-2, 40 latent-MoE and 8 NoPE attention blocks in the order `layers_block_type` gives, 240 to 496 ungated relu^2 experts a layer in a 1024-wide latent with a relu^2 shared expert; linears and experts as the recipe stores them (`data/recipes/nemotron74-fp8.recipe`, `nemotron74-w4nl64-gptq.recipe`); pictures and video through its C-RADIO tower (`arch/nemotronh/radio.h`); bf16 KV |
|
||||
| `arch/lfm2_bf16` | `lfm2` | *(empty)* | LiquidAI's LFM2 and LFM2-VL, bf16, one rank |
|
||||
| `arch/spark25_bf16` | `spark25` | *(empty)* | Spark X2.6, bf16 checkpoint, mixed sliding/full attention, TP1 or TP with exact collectives ([geometry](#spark25-spark-x26)). Optional DSpark drafter when the container already holds `draft.*` tensors, TP1 only. |
|
||||
| `arch/embgemma2` | `embeddinggemma2` | *(empty)* | EmbeddingGemma 2: a bidirectional encoder with Gemma 4's vision tower and audio conformer, pooled to one vector |
|
||||
@@ -2067,6 +2068,74 @@ same model and this engine 0.8%. The transcripts match word for word.
|
||||
|
||||
---
|
||||
|
||||
# `nemotronh`: Nemotron-3.5-Bolt-74B-A9B
|
||||
|
||||
`arch/nemotronh` serves the language model of Nemotron-3.5-Bolt-74B-A9B (`model_type:
|
||||
nemotron_h_omni`, NemotronH_Omni_Reasoning_V3; the text model is `llm_config`, `nemotron_h_puzzle`)
|
||||
from the bf16 checkpoint. The reference is vLLM's `nemotron_h.py` and `mamba_mixer2.py`; NVIDIA's HF
|
||||
`modeling_nemotron_h.py` agrees except for the CPU scan (below). The plugin reuses `MoeFP8` for the
|
||||
routed arm and `AttnFP8` for attention; its Mamba-2 block and the latent feed-forward around
|
||||
`MoeFP8` are in the plugin file.
|
||||
|
||||
```
|
||||
88 blocks, hidden 4096, vocab 131072 (embedding and lm_head separate), RMS eps 1e-5; each block one
|
||||
mixer behind its own norm and a residual add, the type from `layers_block_type`
|
||||
40 Mamba-2: 128 heads of 64 in 8 groups, state 128
|
||||
in_proj 4096 -> z 8192 | x 8192 | B 1024 | C 1024 | dt 128, no bias
|
||||
x|B|C through a causal depthwise conv of width 4 with bias, then SiLU
|
||||
dt' = softplus(dt + dt_bias), unclamped; A = -exp(A_log); a D skip per head
|
||||
y = scan(x, B, C, dt'); RMSNormGated: norm over groups of 1024 of y * silu(z), times 8192 gains
|
||||
out_proj 8192 -> 4096
|
||||
40 latent MoE: router on the normed hidden state (sigmoid, a correction bias for the selection
|
||||
only, one group, top-9, normalized, x5)
|
||||
fc1_latent_proj 4096 -> 1024; routed experts in the latent, ungated: down(relu(up(x))^2);
|
||||
per layer (`block_configs`) 240 to 496 experts of 1536 to 2560; fc2_latent_proj 1024 -> 4096
|
||||
one shared expert on the hidden state, 4096 -> 5376 -> 4096, relu^2
|
||||
8 attention: 32 query heads, 2 KV heads of 128, no position encoding
|
||||
```
|
||||
|
||||
Traps:
|
||||
|
||||
- **The layer count is not stated.** `llm_config` has no `num_hidden_layers`; HF derives it from
|
||||
`block_configs`. The checkpoint reader counts `layers_block_type` when the key is absent, and
|
||||
flattens the array of objects `block_configs` into `block_configs.<l>.<field>`, from which the
|
||||
plugin reads each routed layer's experts, width and top-k.
|
||||
- **dt is not clamped.** `time_step_limit` is (0, inf), and vLLM passes exactly that to its scan.
|
||||
HF's CPU path `torch_forward` clamps dt' below at `time_step_min` (0.001), which in the first
|
||||
layers moves 13 % of the (token, head) steps, and it is also wrong past its first 128-token chunk
|
||||
(the state handoff between chunks): HF on the CPU is no reference beyond 128 tokens.
|
||||
- **The gated norm normalises the product, per group.** `norm(y * silu(z)) * w` with the RMS over
|
||||
1024 channels (8 groups of the 8192), not `norm(y) * w * silu(z)` (the delta net's
|
||||
`gdn_gated_rmsnorm`). Served as `act_mul` (silu), a gainless `rmsnorm` over rows of 1024 and
|
||||
`mul_weight`; a rank's heads are whole groups.
|
||||
- **The router reads the hidden state, the experts the latent.** `MoeFP8` runs at the latent width
|
||||
(`Config::router_k` sizes the router, `Wire::route` feeds it); fc2 is linear and has no bias, so
|
||||
each rank applies it to its partial latent sum and one all-reduce over the hidden width sums the
|
||||
routed and shared arms (`Config::no_reduce`).
|
||||
- **relu^2 is `act_mul`'s relu over one operand twice:** relu(x) * x, rounded once, which is
|
||||
torch's `relu(x) ** 2` in bf16 bit for bit.
|
||||
- **The bf16 checkpoint has no BOS in its template.** Its chat template sets none, as llama.cpp
|
||||
does for the MoE form.
|
||||
|
||||
**KV groups.**
|
||||
|
||||
| group | kind | per layer | layers |
|
||||
|---|---|---|---|
|
||||
| `kv_attn` | `RAD_KV_FULL`, bf16, 2 / tp heads of 128 (1 at four ranks, replicated over a pair), block 16 | keys and values | 8 attention |
|
||||
| `kv_ssm` | `RAD_KV_LINEAR`, f32, 64 x 128 a head | the recurrent state, 128 / tp heads a rank | 40 Mamba-2 |
|
||||
| `kv_ssm_conv` | `RAD_KV_CONV`, bf16, width 4 | the convolution history, (8192 + 2048) / tp channels a rank | 40 Mamba-2 |
|
||||
| `kv_draft` | `RAD_KV_WINDOW` (1024), bf16, 2 / tp heads of 128 (1 at four ranks, replicated over a pair), block 16 | the LiLiCorr drafter's keys and values | its 5 layers, past the trunk |
|
||||
|
||||
**Speculation.** With drafts the scan keeps `ssd_update`'s anchor form (the committed state and a
|
||||
scratch of per-token records: decay, `dt' x`, B), at most 31 drafts a step. NVIDIA's LiLiCorr block
|
||||
drafter proposes 7: 32 query heads over 2 KV heads of 128, which four ranks replicate as the trunk's
|
||||
attention does (`drafter_geom`'s `kv_repl_ok`: each rank reads its head's k and v rows at `kv_off`,
|
||||
and `attn_paged_sink` runs at gqa 8 instead of 16).
|
||||
|
||||
**Vision.** `arch/nemotronh/radio.h` serves the C-RADIO (v4-H) tower and its `mlp1` projector when
|
||||
the container holds them (`vision_config.model_type` `radio`): pictures, and video in tubelets of
|
||||
two frames, through `core/mm`'s `Radio` family.
|
||||
|
||||
# `minimaxmusic3`: MiniMax-Music3, songs
|
||||
|
||||
`arch/minimaxmusic3` declares an audio generator (`rad_declare_audio_generator`), which makes the
|
||||
|
||||
+10
-10
@@ -10,12 +10,12 @@
|
||||
# fast every test with none of slow, gpu, oot and perf, set at the end of this file: the
|
||||
# inner loop (`ctest --preset fast`, or `ctest -L fast`)
|
||||
#
|
||||
# arch_test and glm5next_test do not link rad_core: they supply their own recording fake of the
|
||||
# declare-phase C ABI (arch_fakes.h), so plugins are tested without depending on core/build/'s
|
||||
# builder. With the archive linked, a new ABI call missing from the fake would pull in
|
||||
# rad_builder.cpp.o and collide on every rad_decl_* symbol; without it the error is a single
|
||||
# undefined reference.
|
||||
set(RAD_TESTS_NO_CORE arch_test glm5next_test nemotron35_test spark25_arch_test)
|
||||
# arch_test, glm5next_test, nemotron35_test, spark25_arch_test and nemotronh_test do not link rad_core: they supply
|
||||
# their own recording fake of the declare-phase C ABI (arch_fakes.h), so plugins are tested without
|
||||
# depending on core/build/'s builder. With the archive linked, a new ABI call missing from the fake
|
||||
# would pull in rad_builder.cpp.o and collide on every rad_decl_* symbol; without it the error is a
|
||||
# single undefined reference.
|
||||
set(RAD_TESTS_NO_CORE arch_test glm5next_test nemotron35_test spark25_arch_test nemotronh_test)
|
||||
|
||||
# fixture_test tests tools/kfixture.cpp and tools/opshapes.cpp (the seeded draw, the reduction and
|
||||
# the on-disk recording) directly, kbench_test tools/kbench_core.cpp (rad-kbench's rules), and
|
||||
@@ -386,10 +386,10 @@ if(TARGET abi_layout_test)
|
||||
COMPILE_OPTIONS "-std=c11;-pedantic-errors;-Wall;-Wextra")
|
||||
endif()
|
||||
|
||||
# arch_test reads libref's vocabulary from $RADIANCE_HOME/kernels to check that each architecture
|
||||
# declares on it, and glm5next_test the loaded libraries' op schemas, so libref is built before
|
||||
# them.
|
||||
foreach(t arch_test glm5next_test)
|
||||
# arch_test and nemotronh_test read libref's vocabulary from $RADIANCE_HOME/kernels to check that
|
||||
# each architecture declares on it, and glm5next_test the loaded libraries' op schemas, so libref is
|
||||
# built before them.
|
||||
foreach(t arch_test glm5next_test nemotronh_test)
|
||||
if(TARGET libref AND TARGET ${t})
|
||||
add_dependencies(${t} libref)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
/* nemotronh_test.cpp -- Nemotron-3.5-Bolt's plugin (nemotronh) with its LiLiCorr drafter, declared
|
||||
* and stepped against the recording builder of arch_fakes.h.
|
||||
*
|
||||
* The metadata is a nine-block cut of the released config, as rad-info --meta prints a container
|
||||
* converted from it (the vision tower's keys left out): every block kind, one attention block, and
|
||||
* the drafter with 32 query heads over 2 KV heads of 128. */
|
||||
#define RAD_ARCH_NO_EXPORTS 1
|
||||
|
||||
#include "arch_fakes.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
/* ==================================================================== the plugin under test */
|
||||
#include "../arch/nemotronh/nemotronh.cpp"
|
||||
|
||||
namespace {
|
||||
|
||||
const char* const k_nemo[][2] = {
|
||||
{ "tie_word_embeddings", "0" },
|
||||
{ "attention_bias", "0" },
|
||||
{ "block_configs.1.moe_intermediate_size", "2048" },
|
||||
{ "block_configs.1.n_routed_experts", "240" },
|
||||
{ "block_configs.1.num_experts_per_tok", "9" },
|
||||
{ "block_configs.3.moe_intermediate_size", "1536" },
|
||||
{ "block_configs.3.n_routed_experts", "240" },
|
||||
{ "block_configs.3.num_experts_per_tok", "9" },
|
||||
{ "block_configs.5.moe_intermediate_size", "2048" },
|
||||
{ "block_configs.5.n_routed_experts", "240" },
|
||||
{ "block_configs.5.num_experts_per_tok", "9" },
|
||||
{ "block_configs.8.moe_intermediate_size", "2304" },
|
||||
{ "block_configs.8.n_routed_experts", "304" },
|
||||
{ "block_configs.8.num_experts_per_tok", "9" },
|
||||
{ "conv_kernel", "4" },
|
||||
{ "hidden_act", "relu2" },
|
||||
{ "layers_block_type", "mamba moe mamba moe mamba moe mamba attention moe" },
|
||||
{ "mamba_head_dim", "64" },
|
||||
{ "mamba_hidden_act", "silu" },
|
||||
{ "mamba_num_heads", "128" },
|
||||
{ "mamba_proj_bias", "0" },
|
||||
{ "mlp_bias", "0" },
|
||||
{ "mlp_hidden_act", "relu2" },
|
||||
{ "moe_latent_size", "1024" },
|
||||
{ "moe_shared_expert_intermediate_size", "5376" },
|
||||
{ "n_group", "1" },
|
||||
{ "n_groups", "8" },
|
||||
{ "n_shared_experts", "1" },
|
||||
{ "norm_topk_prob", "1" },
|
||||
{ "num_nextn_predict_layers", "0" },
|
||||
{ "residual_in_fp32", "0" },
|
||||
{ "routed_scaling_factor", "5" },
|
||||
{ "scoring_func", "sigmoid" },
|
||||
{ "ssm_state_size", "128" },
|
||||
{ "topk_group", "1" },
|
||||
{ "use_bias", "0" },
|
||||
{ "use_conv_bias", "1" },
|
||||
{ "draft.architectures", "LiLiCorrDraftModel" },
|
||||
{ "draft.attention_sink_bias", "1" },
|
||||
{ "draft.block_size", "8" },
|
||||
{ "draft.dflash_config.attention_sink_bias", "1" },
|
||||
{ "draft.dflash_config.causal", "0" },
|
||||
{ "draft.dflash_config.conv_group_size", "16" },
|
||||
{ "draft.dflash_config.conv_kernel_size", "2" },
|
||||
{ "draft.dflash_config.lilicorr_candidate_topk", "8" },
|
||||
{ "draft.dflash_config.lilicorr_enabled", "1" },
|
||||
{ "draft.dflash_config.lilicorr_factor_dim", "1024" },
|
||||
{ "draft.dflash_config.lilicorr_hidden_size", "1024" },
|
||||
{ "draft.dflash_config.lilicorr_logit_scale", "8" },
|
||||
{ "draft.dflash_config.lilicorr_mlp_ratio", "2" },
|
||||
{ "draft.dflash_config.lilicorr_num_heads", "8" },
|
||||
{ "draft.dflash_config.lilicorr_num_layers", "2" },
|
||||
{ "draft.dflash_config.lilicorr_vector_eps", "0.0001" },
|
||||
{ "draft.dflash_config.mask_token_id", "990" },
|
||||
{ "draft.dflash_config.projector_type", "lilicorr" },
|
||||
{ "draft.dflash_config.swa_window_size", "1024" },
|
||||
{ "draft.dflash_config.target_layer_ids", "[1,2,3,5,6,8]" },
|
||||
{ "draft.dflash_config.use_swa", "1" },
|
||||
{ "draft.head_dim", "128" },
|
||||
{ "draft.hidden_size", "4096" },
|
||||
{ "draft.intermediate_size", "12288" },
|
||||
{ "draft.layer_types", "sliding_attention sliding_attention sliding_attention "
|
||||
"sliding_attention sliding_attention" },
|
||||
{ "draft.num_attention_heads", "32" },
|
||||
{ "draft.num_hidden_layers", "5" },
|
||||
{ "draft.num_key_value_heads", "2" },
|
||||
{ "draft.rms_norm_eps", "9.9999999999999995e-07" },
|
||||
{ "draft.rope_theta", "10000" },
|
||||
{ "draft.sliding_window", "1024" },
|
||||
{ "draft.use_sliding_window", "1" },
|
||||
{ "draft.vocab_size", "131072" },
|
||||
};
|
||||
|
||||
struct Nemo {
|
||||
std::vector<const char*> keys, vals;
|
||||
Nemo() {
|
||||
for (const auto& kv : k_nemo) {
|
||||
keys.push_back(kv[0]);
|
||||
vals.push_back(kv[1]);
|
||||
}
|
||||
}
|
||||
RadModelMeta meta() const {
|
||||
RadModelMeta m{};
|
||||
m.arch_id = "nemotronh";
|
||||
m.name = "test-nemotron-3.5-bolt-c9";
|
||||
m.quant = "";
|
||||
m.n_layers = 9;
|
||||
m.n_embd = 4096;
|
||||
m.n_head = 32;
|
||||
m.n_head_kv = 2;
|
||||
m.head_dim = 128;
|
||||
m.n_ff = 2688;
|
||||
m.n_vocab = 131072;
|
||||
m.n_ctx_train = 262144;
|
||||
m.rms_eps = 1e-5f;
|
||||
m.rope_theta = 10000.0f;
|
||||
m.rope_scale = 1.0f;
|
||||
m.n_kv = (int)keys.size();
|
||||
m.kv_key = keys.data();
|
||||
m.kv_val = vals.data();
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
/* The weights as the release recipes store them: the drafter's linears and every trunk linear block
|
||||
* fp8, dt's rows of in_proj bf16 (32 a rank at four ranks, no whole scale block). The drafter's
|
||||
* keys come first: the fake answers the first key a name contains. */
|
||||
void nemo_encs(RadBuilder& b) {
|
||||
const RadEncoding fp8 = rad_enc_affine(RAD_F8E4M3, RAD_BF16, 128, 128);
|
||||
b.encs = { { "dflash.fc.", fp8 }, { "dflash.blk.", fp8 }, { "ssm_dt", rad_enc_plain(RAD_BF16) },
|
||||
{ "blk.", fp8 } };
|
||||
}
|
||||
|
||||
int buf_named(const RadBuilder& b, const char* name) {
|
||||
for (size_t i = 0; i < b.bufs.size(); ++i)
|
||||
if (b.bufs[i].name == name) return (int)(i + 1);
|
||||
return 0;
|
||||
}
|
||||
bool noted(const RadBuilder& b, const char* text) {
|
||||
for (const auto& n : b.notes)
|
||||
if (n.find(text) != std::string::npos) return true;
|
||||
return false;
|
||||
}
|
||||
rad_kvgroup kv_named(const RadBuilder& b, const char* name) {
|
||||
for (size_t i = 0; i < b.kv_groups.size(); ++i)
|
||||
if (b.kv_groups[i].name == name) return (rad_kvgroup)(i + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RadBuildCtx nemo_ctx(int rank, int world) {
|
||||
RadBuildCtx c = build_ctx(rank, world);
|
||||
c.max_spec = 7; /* LiLiCorr's trained block of 8 */
|
||||
return c;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/* drafter_geom keeps refusing fewer KV heads than ranks unless the drafter block reads k and v at
|
||||
* kv_off; with `kv_repl_ok` it replicates them as geom_from does the target's: one head a rank,
|
||||
* ranks {0, 1} on head 0 and {2, 3} on head 1. The target's own kv_off is not inherited. */
|
||||
TEST(drafter_geom_replicates_kv_heads_only_when_the_block_asks) {
|
||||
using namespace rad::arch;
|
||||
Nemo f;
|
||||
const RadModelMeta meta = f.meta();
|
||||
for (int world : { 2, 4 })
|
||||
for (int rank = 0; rank < world; ++rank) {
|
||||
const RadBuildCtx ctx = nemo_ctx(rank, world);
|
||||
Geom t{};
|
||||
REQUIRE_EQ(geom_from(t, &meta, &ctx, "bf16", RAD_BF16), RAD_OK);
|
||||
Geom dg{};
|
||||
if (world == 4) {
|
||||
CHECK_EQ(t.kv_off, (int64_t)(rank / 2) * 128); /* the target replicates too */
|
||||
CHECK_EQ(drafter_geom(dg, t, &meta, "LiLiCorr"), (int)RAD_E_INVAL);
|
||||
}
|
||||
REQUIRE_EQ(drafter_geom(dg, t, &meta, "LiLiCorr", true), RAD_OK);
|
||||
CHECK_EQ(dg.n_head, 32 / world);
|
||||
CHECK_EQ(dg.n_head_kv, 1);
|
||||
CHECK_EQ(dg.n_head_kv_all, 2);
|
||||
CHECK_EQ(dg.gqa(), 32 / world);
|
||||
CHECK_EQ(dg.kv_off, world == 4 ? (int64_t)(rank / 2) * 128 : (int64_t)0);
|
||||
}
|
||||
}
|
||||
|
||||
/* The drafter at two and four ranks. Each rank keeps one KV head in `kv_draft`; at four its k and v
|
||||
* are the rows of its replicated head, [kv_off, kv_off + 128) of the 256-row projection (codes, and
|
||||
* the scale plane in 128-row blocks), and q stays an even share. The sinked attention then runs 8
|
||||
* query heads over that head (gqa 8, a libr4d row of its own) where two ranks run 16 (gqa 16). At
|
||||
* two ranks nothing is spanned: the even shard is the head. */
|
||||
TEST(lilicorr_replicates_its_two_kv_heads_at_four_ranks) {
|
||||
Nemo f;
|
||||
const RadModelMeta meta = f.meta();
|
||||
for (int world : { 2, 4 })
|
||||
for (int rank = 0; rank < world; ++rank) {
|
||||
RadBuilder b;
|
||||
nemo_encs(b);
|
||||
const RadBuildCtx ctx = nemo_ctx(rank, world);
|
||||
REQUIRE_EQ(nemotronh::declare(&b, &meta, &ctx), RAD_OK);
|
||||
CHECK(nemotronh::models[rank]->have_df);
|
||||
const rad_kvgroup kvd = kv_named(b, "kv_draft");
|
||||
REQUIRE(kvd != 0);
|
||||
CHECK_EQ(b.kv_groups[kvd - 1].d.n_head_kv, 1);
|
||||
CHECK_EQ(b.kv_groups[kvd - 1].d.head_dim, 128);
|
||||
CHECK_EQ(b.bufs[buf_named(b, "df_q") - 1].d.shape[1], (int64_t)(32 / world) * 128);
|
||||
CHECK_EQ(b.bufs[buf_named(b, "df_k") - 1].d.shape[1], (int64_t)128);
|
||||
CHECK_EQ(b.bufs[buf_named(b, "df_cv") - 1].d.shape[1], (int64_t)128);
|
||||
int sinks = 0;
|
||||
for (const auto& o : b.ops)
|
||||
if (o.op == "attn_paged_sink") {
|
||||
CHECK_EQ(pint(&o, "gqa"), 32 / world);
|
||||
CHECK_EQ(pint(&o, "n_head"), 32 / world);
|
||||
CHECK_EQ(pint(&o, "head_dim"), 128);
|
||||
++sinks;
|
||||
}
|
||||
CHECK_EQ(sinks, 5);
|
||||
const int64_t kv0 = (rank / 2) * 128;
|
||||
for (int l = 0; l < 5; ++l) {
|
||||
for (const char* kv : { "attn_k", "attn_v" }) {
|
||||
const std::string base = "dflash.blk." + std::to_string(l) + "." + kv;
|
||||
const RecWeight* w = find_w(b, base + ".weight");
|
||||
const RecWeight* s = find_w(b, base + ".scale");
|
||||
REQUIRE(w != nullptr && s != nullptr);
|
||||
CHECK_EQ(w->d.shape[0], 128);
|
||||
CHECK_EQ(w->span_set, world == 4);
|
||||
CHECK_EQ(s->span_set, world == 4);
|
||||
if (world == 4) {
|
||||
CHECK_EQ(w->span_lo, kv0);
|
||||
CHECK_EQ(w->span_hi, kv0 + 128);
|
||||
CHECK_EQ(s->span_lo, kv0 / 128);
|
||||
CHECK_EQ(s->span_hi, kv0 / 128 + 1);
|
||||
}
|
||||
}
|
||||
const RecWeight* q =
|
||||
find_w(b, "dflash.blk." + std::to_string(l) + ".attn_q.weight");
|
||||
REQUIRE(q != nullptr);
|
||||
CHECK(!q->span_set);
|
||||
CHECK_EQ(q->d.shape[0], (int64_t)(32 / world) * 128);
|
||||
}
|
||||
/* the target's attention replicates its two heads the same way */
|
||||
const rad_kvgroup kva = kv_named(b, "kv_attn");
|
||||
REQUIRE(kva != 0);
|
||||
CHECK_EQ(b.kv_groups[kva - 1].d.n_head_kv, 1);
|
||||
CHECK(noted(b, world == 4 ? "kv (replicated) x 128" : "/ 1 kv x 128"));
|
||||
}
|
||||
}
|
||||
|
||||
/* A speculative step at four ranks: the trunk's verify of two sequences, the drafter's context pass
|
||||
* over its rows and its query pass, each without a step failure and lint-clean. */
|
||||
TEST(nemotronh_tp4_steps_lint_clean_with_the_lilicorr_drafter) {
|
||||
Nemo f;
|
||||
const RadModelMeta meta = f.meta();
|
||||
for (int rank : { 0, 3 }) {
|
||||
RadBuilder b;
|
||||
nemo_encs(b);
|
||||
const RadBuildCtx ctx = nemo_ctx(rank, 4);
|
||||
REQUIRE_EQ(nemotronh::declare(&b, &meta, &ctx), RAD_OK);
|
||||
auto trunk = kit(b, { 8, 8 }, {});
|
||||
auto cpass = context_pass(b, *trunk);
|
||||
auto qpass = query_pass(b, 2, 8, 7);
|
||||
std::vector<int32_t> anchors = { 7, 15 }; /* each sequence's last committed row */
|
||||
qpass->b.anchor_rows = anchors.data();
|
||||
auto v = run_passes(b, nemotronh::step, { trunk.get(), cpass.get(), qpass.get() }, rank, 4);
|
||||
CHECK_PASSES(b, v);
|
||||
/* the drafter ran: its five layers' sinked attention and its keys into the cache */
|
||||
const std::vector<std::string> q = issued_ops(b, *v[2]);
|
||||
CHECK_EQ(count_issued(q, "attn_paged_sink"), 5);
|
||||
CHECK_EQ(count_issued(q, "kv_store"), 5);
|
||||
CHECK_EQ(count_issued(issued_ops(b, *v[1]), "kv_store"), 5);
|
||||
}
|
||||
}
|
||||
|
||||
/* The engine's arena levels declare again at a smaller max_tok (RadBuildCtx::shape_probe) and
|
||||
* must get the real declare's graph: the same ops with the same fixed parameters, only ranged row
|
||||
* counts and buffer rows smaller. The drafter's split fc gathers its message as a range; a fixed
|
||||
* numel there left every level unplanned, and sixteen sequences short of the lent arena. */
|
||||
TEST(nemotronh_sizing_declares_match_the_real_graph_at_every_arena_level) {
|
||||
Nemo f;
|
||||
const RadModelMeta meta = f.meta();
|
||||
for (int world : { 2, 4 })
|
||||
for (int64_t R : { 256, 1024 }) {
|
||||
RadBuildCtx c = nemo_ctx(1, world);
|
||||
c.max_tok = 4096;
|
||||
c.max_seqs = 16;
|
||||
RadBuilder full;
|
||||
nemo_encs(full);
|
||||
REQUIRE_EQ(nemotronh::declare(&full, &meta, &c), RAD_OK);
|
||||
RadBuildCtx p = c;
|
||||
p.max_tok = R;
|
||||
p.shape_probe = 1;
|
||||
RadBuilder small;
|
||||
nemo_encs(small);
|
||||
REQUIRE_EQ(nemotronh::declare(&small, &meta, &p), RAD_OK);
|
||||
REQUIRE_EQ(small.ops.size(), full.ops.size());
|
||||
int differ = 0;
|
||||
for (size_t i = 0; i < full.ops.size(); ++i) {
|
||||
if (small.ops[i].op != full.ops[i].op) {
|
||||
++differ;
|
||||
continue;
|
||||
}
|
||||
REQUIRE_EQ(small.ops[i].p.size(), full.ops[i].p.size());
|
||||
for (size_t k = 0; k < full.ops[i].p.size(); ++k) {
|
||||
const RecParam& a = full.ops[i].p[k];
|
||||
const RecParam& q = small.ops[i].p[k];
|
||||
if (a.kind == RAD_P_RANGE) continue;
|
||||
if (a.ival != q.ival || a.sval != q.sval || a.dval != q.dval) {
|
||||
fprintf(stderr, " world %d R %lld: op %zu '%s' param '%s': %lld real, "
|
||||
"%lld small\n", world, (long long)R, i,
|
||||
full.ops[i].op.c_str(), a.key.c_str(), a.ival, q.ival);
|
||||
++differ;
|
||||
}
|
||||
}
|
||||
}
|
||||
CHECK_EQ(differ, 0);
|
||||
REQUIRE_EQ(small.bufs.size(), full.bufs.size());
|
||||
for (size_t i = 0; i < full.bufs.size(); ++i)
|
||||
for (uint32_t d = 1; d < full.bufs[i].d.rank; ++d)
|
||||
CHECK_EQ(small.bufs[i].d.shape[d], full.bufs[i].d.shape[d]);
|
||||
}
|
||||
}
|
||||
|
||||
/* The probe states LiLiCorr's fixed depth, the trained block less its anchor: what --tp 4 serves
|
||||
* with `--num-speculative-tokens 7`. */
|
||||
TEST(nemotronh_probe_names_lilicorrs_depth) {
|
||||
Nemo f;
|
||||
const RadModelMeta meta = f.meta();
|
||||
RadArchProbe pr{};
|
||||
REQUIRE_EQ(nemotronh::probe(&meta, &pr), RAD_OK);
|
||||
CHECK_EQ(pr.draft_depth, 7);
|
||||
CHECK_EQ(pr.draft_depth_fixed, 1);
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
@@ -97,7 +97,7 @@ TEST(the_shipped_architectures_load_with_distinct_selection_keys) {
|
||||
{ "gemma4", "compressed-tensors" }, { "glm5next", "" },
|
||||
{ "hunyuan3d2", "" }, { "hyv3", "" }, { "hyv3", "fp8" }, { "hyv3", "gguf_ftype_15" },
|
||||
{ "laya", "" }, { "lfm2", "" }, { "llama", "" }, { "mistral3", "" },
|
||||
{ "llama", "fp8_e4m3" }, { "nomicbert", "" }, { "qwen35", "" },
|
||||
{ "llama", "fp8_e4m3" }, { "nemotronh", "" }, { "nomicbert", "" }, { "qwen35", "" },
|
||||
{ "qwen35", "fp8_e4m3" }, { "qwen35", "w8a8_fwht128" }, { "qwen35moe", "fp8_e4m3" },
|
||||
{ "qwen3asr", "" }, { "krea2", "" }, { "ltx2", "" }, { "minimaxh3", "" },
|
||||
{ "minimaxmusic3", "" }, { "qwen4exp", "" }, { "qwenimage21", "" },
|
||||
|
||||
Reference in new issue
Block a user