abi: RadBatch::lora_slot, each row's runtime LoRA adapter; RAD_ABI_VERSION 18

The per-row adapter slot moves from the core's `lora_slot` derivation into the step batch, beside
the other per-row arrays: [n_tok] i32 device, the row's slot in the adapter pools, < 0 or >= S a
base row, null when the engine serves no adapters. The batch builder fills it from
Request::lora_slot where it fills token_ids and positions, in the slab every rank's batch already
points into -- one address per rank for the engine's life, uploaded in stream order ahead of the
step's kernels -- so a recorded pass replays it the way it replays token_ids. Ctx::pass_key reads
the pointer; the adapter ops are issued whatever the slots hold, so nothing a pass launches depends
on their values.

Off: the slab carves nothing for it (a zero-length carve), no buffer is declared, and every other
slab offset and the arena are what they were. The derivation, its program buffer and
Program::lora_slot_buf are gone. abi_layout_table regenerated at 18 (RadBatch grows to 320 bytes,
the fields after seq_ids move by 8); sched_test holds the per-row fill, and that the slot array is
the only thing adapters add to the slab.
This commit is contained in:
baKon committed 2026-10-16 20:52:09 -05:00
1 parent 09ff76701c
commit 582cda0a53
15 files changed
+141 -84

No files matched your search

+11
View File
@@ -124,6 +124,9 @@ void BatchBuilder::carve(Set& s, char* h) {
* moves a rotary position off the token index. */
pair(&s.h_rope, &s.d_rope, mm_on_ ? 3 * T : 0);
pair(&s.h_mmrow, &s.d_mmrow, mm_on_ ? T : 0);
/* Each row's adapter slot, only when the engine serves adapters: with none the slab and every
* offset in it are what they were before adapters existed. */
pair(&s.h_lora, &s.d_lora, lora_on_ ? T : 0);
/* Host-only (derived metadata is copied into the planned arena), but carved on both sides to
* keep device offsets equal to host offsets. */
{
@@ -459,6 +462,7 @@ int BatchBuilder::layout(Program& prog, const Config& cfg) {
});
mm_on_ = prog.encoder.modalities != 0 || prog.audio_encoder.modalities != 0;
lora_on_ = cfg.lora.enabled();
return RAD_OK;
}
@@ -893,6 +897,12 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
s.h_tok[k + j] = token_at(e, (int64_t)e.ctx_len + j + shift);
s.h_pos[k + j] = e.ctx_len + j;
}
/* Every row of a sequence runs with its request's adapter (RadBatch::lora_slot), fixed at
* admission; a placeholder row with no request is a base row. */
if (lora_on_) {
const int32_t ls = e.req ? e.req->lora_slot : -1;
for (int32_t j = 0; j < e.n_tokens; ++j) s.h_lora[k + j] = ls;
}
/* Rotary position of each row at its own position (draft-head rows rotate at the index
* they write, not the token they embed). Three planes of n_tok. */
if (mm_on_) {
@@ -1098,6 +1108,7 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
B.n_mm_rows = n_mm;
B.mm_rows = n_mm ? on_rank(base, b0, s.d_mmrow) : nullptr;
B.mm_embd = n_mm ? mm_dev_[r] : nullptr;
B.lora_slot = lora_on_ ? on_rank(base, b0, s.d_lora) : nullptr;
B.enc = 0;
B.enc_n_patch = 0;
B.enc_pixels = nullptr;