Archived
vocab edges at a world that does not divide them: block-aligned split, declared as a span
token_embd / output are RAD_SHARD_ROW; at three ranks 248320 rows do not divide, and share.cpp refuses a row shard without a declared span. qwen4exp now declares [vocab_off, vocab_off + n_vocab) for both. The split rule (rad_arch.h shard_extent/shard_begin, restated in core/engine.cpp) keeps the even share whenever the world divides the vocabulary -- two and four ranks are untouched -- and only otherwise rounds the per-rank count up to a 128-row block, because a block-scaled fp8 head refuses a cut inside a tile: at three the ranks take 82816, 82816, 82688.
This commit is contained in:
1 parent
b60e329d93
commit
72947681c3
3 files changed
+33
-4
No files matched your search
+18
-2
@@ -675,14 +675,30 @@ inline int divide_or_fail(int64_t v, int world, const char* what, int64_t* out)
|
||||
* absurd. So the last rank holds fewer rows. The sampler merges candidate sets rather than
|
||||
* gathering full logits (spec §9, §13), so a ragged shard costs it nothing; a padded one would
|
||||
* cost a fake token id that has to be masked everywhere forever. */
|
||||
inline int64_t shard_extent(int64_t total, int world, int rank) {
|
||||
/* THE VOCABULARY SPLIT: ceil(total / world) rows a rank, ROUNDED UP TO A WHOLE 128-ROW BLOCK, the
|
||||
* last rank short. The block is RAD_FP8_BLOCK: a block-scaled fp8 lm_head is stored in 128x128
|
||||
* tiles and a row span that cuts a tile is refused (rad_weight_shard_span), so the cut has to land
|
||||
* on one. At two ranks on 248320 or 151936 the rounding changes nothing -- both halves are block
|
||||
* multiples -- and a vocabulary the world divides is never rounded; at three it is what makes the
|
||||
* head shardable at all (248320 / 3 = 82773.3; the ranks take 82816, 82816, 82688). core/engine.cpp
|
||||
* RESTATES this rule and checks it against the width the plugin declared; the two must move together. */
|
||||
inline int64_t vocab_per_rank(int64_t total, int world) {
|
||||
/* A vocabulary the world divides keeps the even share, whatever the world: every container
|
||||
* served today splits that way (248320 at 2 and 4, 151936 at 2 -- the last halves mid-block and
|
||||
* is served with an untiled head). Only a vocabulary the world does NOT divide takes the
|
||||
* block-aligned ceil, which is what makes a tiled head shardable at all. */
|
||||
if (total % world == 0) return total / world;
|
||||
const int64_t per = (total + world - 1) / world;
|
||||
return (per + 127) / 128 * 128;
|
||||
}
|
||||
inline int64_t shard_extent(int64_t total, int world, int rank) {
|
||||
const int64_t per = vocab_per_rank(total, world);
|
||||
const int64_t beg = per * rank;
|
||||
const int64_t end = beg + per < total ? beg + per : total;
|
||||
return end > beg ? end - beg : 0;
|
||||
}
|
||||
inline int64_t shard_begin(int64_t total, int world, int rank) {
|
||||
const int64_t per = (total + world - 1) / world;
|
||||
const int64_t per = vocab_per_rank(total, world);
|
||||
const int64_t beg = per * rank;
|
||||
return beg < total ? beg : total;
|
||||
}
|
||||
|
||||
@@ -914,6 +914,14 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
weight_codes_dtype(b, nm.f("output.weight"), RAD_BF16),
|
||||
{g.n_vocab, g.n_embd}, RAD_ACCESS_VOCAB, RAD_SHARD_ROW, grp_model());
|
||||
if (!m.w_tok || !m.w_lm_head) return RAD_E_INVAL;
|
||||
/* THE RANK'S ROWS, STATED: a vocabulary that does not divide by the world (248320 at three
|
||||
* ranks) is split by rad_arch.h's rule -- ceil to a 128-row block, last rank short -- and that
|
||||
* is a span, not the even share the core would otherwise cut. Harmless where it does divide
|
||||
* (the span IS the even share). */
|
||||
if (g.world > 1) {
|
||||
RAD_ARCH_TRY(rad_weight_shard_span(b, m.w_tok, g.vocab_off, g.vocab_off + g.n_vocab));
|
||||
RAD_ARCH_TRY(rad_weight_shard_span(b, m.w_lm_head, g.vocab_off, g.vocab_off + g.n_vocab));
|
||||
}
|
||||
|
||||
m.op_embed = rw(b, RAD_OP(b, "embed_lookup",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, T), RAD_INT("n_embd", g.n_embd),
|
||||
|
||||
+7
-2
@@ -122,13 +122,18 @@ int Engine::declare_sampler(int rank, RadBuilder* b, int64_t logits_width, bool
|
||||
sc.n_vocab_local = logits_width > 0 ? logits_width : meta_.n_vocab;
|
||||
/* THIS RANK'S FIRST VOCABULARY ROW, and it is the one thing the declared width cannot say:
|
||||
* a width tells you how many rows a rank owns, not which. The rule is arch/common/rad_arch.h's
|
||||
* shard_begin -- ceil(total/world) per rank with the last one short -- and it is restated here
|
||||
* shard_begin -- ceil(total/world) per rank, rounded up to a 128-row block, the last one short -- and it is restated here
|
||||
* rather than carried through the ABI, so the restatement is CHECKED against what the plugin
|
||||
* actually declared. A plugin that shards some other way gets a named refusal at startup
|
||||
* instead of a sampler that names rank 0's tokens with rank 1's ids. */
|
||||
sc.vocab_off = 0;
|
||||
if (sc.n_vocab_local < sc.n_vocab) {
|
||||
const int64_t per = (sc.n_vocab + cfg_.tp - 1) / cfg_.tp;
|
||||
/* rad_arch.h vocab_per_rank, restated: the even share when the world divides the vocabulary;
|
||||
* otherwise ceil(n / tp) rounded up to a whole 128-row block so a block-scaled head can be
|
||||
* cut there. */
|
||||
const int64_t ceil_per = (sc.n_vocab + cfg_.tp - 1) / cfg_.tp;
|
||||
const int64_t per = (sc.n_vocab % cfg_.tp == 0) ? sc.n_vocab / cfg_.tp
|
||||
: (ceil_per + 127) / 128 * 128;
|
||||
sc.vocab_off = per * rank;
|
||||
const int64_t want = std::min<int64_t>(per, sc.n_vocab - sc.vocab_off);
|
||||
if (sc.vocab_off >= sc.n_vocab || want != sc.n_vocab_local) {
|
||||
|
||||
Reference in new issue
Block a user