diff --git a/arch/glm5next/glm5next.cpp b/arch/glm5next/glm5next.cpp index 0b535c51..e2cfdc04 100644 --- a/arch/glm5next/glm5next.cpp +++ b/arch/glm5next/glm5next.cpp @@ -430,6 +430,10 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c m.expand = copy(b, g, m.x, m.h0); m.layers.resize(45); for (int l = 0; l < 45; ++l) RAD_ARCH_TRY(layer(b, m, m.layers[l], nm, l, false)); + // Every rank computes the whole normed latent and pools into the whole index cache + // (rad_block_glm_mla.h, rad_block_glm_indexer.h), so the host tier keeps each once a slot. + RAD_ARCH_TRY(rad_kv_group_replicated(b, m.latent)); + if (m.index) RAD_ARCH_TRY(rad_kv_group_replicated(b, m.index)); m.contract = rw(b, RAD_OP(b, "mhc_contract", RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok), RAD_INT("n", 4096), diff --git a/docs/ARCHITECTURES.md b/docs/ARCHITECTURES.md index 8ad2deeb..9cde6552 100644 --- a/docs/ARCHITECTURES.md +++ b/docs/ARCHITECTURES.md @@ -506,9 +506,13 @@ declare. | `kv_kda` | `RAD_KV_LINEAR`, f32, 128 x 128 a head | the recurrent state, 64 / tp heads a rank | 34 KDA | | `kv_kda_conv` | `RAD_KV_CONV`, bf16, width 4 | the convolution history, 3 x 8192 / tp channels a rank | 34 KDA | -The latent and the index are replicated: every rank keeps the whole latent cache. The model is a -hybrid, so a prefix-cache hit is usable only from a state checkpoint at or below it, and -`--checkpoint-interval` decides how much of a shared system prompt is reused. +The latent and the index are replicated: every rank keeps the whole latent cache, and the plugin +declares both so (`rad_kv_group_replicated`), which lets the host tier (`--prefix-cache-mib`) hold +each once a slot: 49.59 KiB a 4-token block at any rank count (`kv_latent` 48.00 KiB over its 12 +layers, `kv_dsa_index` 1.59 KiB), 12.4 KiB a token, where a copy per rank would make a slot +396.75 KiB at eight. The model is a hybrid, so a prefix-cache hit is usable only from a state +checkpoint at or below it, and `--checkpoint-interval` decides how much of a shared system prompt +is reused. **Linears.** Each weight is served as the export stores it: diff --git a/tests/glm5next_test.cpp b/tests/glm5next_test.cpp index c6ce1adf..c646a1c1 100644 --- a/tests/glm5next_test.cpp +++ b/tests/glm5next_test.cpp @@ -1440,6 +1440,35 @@ RadBuildCtx glm53_vl_ctx(int rank, int world, int64_t patches, int max_spec = 3) } /* namespace */ +/* The latent and the index cache are computed whole on every rank (rad_block_glm_mla.h, + * rad_block_glm_indexer.h) and the plugin says so, which lets the host tier keep each once a slot + * under tensor parallelism instead of once a rank. The linear groups travel in the checkpoint + * store and carry no such flag. The flag is outside graph_hash(), so the pinned graphs stand. */ +TEST(glm53_declares_its_latent_and_index_caches_replicated) { + MetaKV mk = glm53_vl_meta(); + auto ends_with = [](const std::string& s, const char* t) { + const size_t n = std::strlen(t); + return s.size() >= n && s.compare(s.size() - n, n, t) == 0; + }; + for (int world : { 1, 2, 8 }) { + for (int rank : { 0, world - 1 }) { + RadBuilder b; + glm53_encs(b); + RadBuildCtx ctx = glm53_vl_ctx(rank, world, 0); + REQUIRE_EQ(glm5next::declare(&b, mk.meta(), &ctx), RAD_OK); + REQUIRE_EQ(b.kv_groups.size(), 5u); + int replicated = 0; + for (const RecKV& g : b.kv_groups) { + const bool want = ends_with(g.name, "kv_latent") || ends_with(g.name, "kv_dsa_index"); + CHECK(g.replicated == want); + CHECK(!g.zero); + replicated += g.replicated; + } + CHECK_EQ(replicated, 2); + } + } +} + /* The tower is declared only with an encoder budget, last, its weights replicated in their own * groups past the 45 layers and the MTP layer's, its 2-D rotary the axial one at sixteen * frequencies an axis, gate and up joined gate first; one scatter over the trunk's embedding and