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

+5 -1
View File
@@ -900,7 +900,7 @@ int Ctx::lane_join(int from, int to) {
/* The key below reads every RadBatch field a pass's shape or arguments can depend on, by hand. A
* field added to RadBatch changes its size: decide whether the key must read it, then update the
* size here. */
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 312,
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 320,
"RadBatch changed: check that Ctx::pass_key reads every new field a pass depends on");
static_assert(sizeof(void*) != 8 || sizeof(RadKVGroupBatch) == 72,
"RadKVGroupBatch changed: check that Ctx::pass_key reads every new field");
@@ -927,6 +927,10 @@ uint64_t Ctx::pass_key(const RadBatch* b) const {
ptr(b->token_ids); ptr(b->positions); ptr(b->cu_seqlens); ptr(b->seq_ids);
ptr(b->out_ids); ptr(b->q_lens); ptr(b->ctx_lens); ptr(b->num_accepted);
ptr(b->spec_parent); ptr(b->checkpoint_tok); ptr(b->checkpoint_slot); ptr(b->draft_out_ids);
/* The adapter ops' slot pointer. One address per rank for the engine's life, null without
* adapters; the slots themselves are read on the card, and the ops are issued whether or not a
* row has an adapter, so what a recorded pass launches never depends on their values. */
ptr(b->lora_slot);
for (int g = 0; g < b->n_kv_groups; ++g) {
const RadKVGroupBatch& k = b->kv[g];
mix((uint64_t)k.group); ptr(k.slot_mapping); ptr(k.block_table);
+10 -1
View File
@@ -477,9 +477,18 @@ int Ctx::issue_lora(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
return abort_step_msg(h, RAD_E_STATE,
fmt("LoRA site: the gemm wrote rows [%lld, %lld) of a %lld-token step",
(long long)r0, (long long)(r0 + n), (long long)batch_->n_tok));
/* Each row's adapter is the step batch's (RadBatch::lora_slot), which the builder fills from
* every request's slot. It sits at one address per rank for the engine's life and is
* rewritten in stream order before each step's kernels, so the pointer this launch records is
* the one a replay of it reads. */
if (!batch_->lora_slot)
return abort_step_msg(h, RAD_E_STATE, "LoRA site: the step batch carries no per-row adapter "
"slot (RadBatch::lora_slot), so the engine was started "
"without adapters and should have declared no site");
const LoraPool& pool = program_->lora_pools[(size_t)s.pool];
const rad_buf t = program_->lora_t[(size_t)s.t].lane[lane_ ? 1 : 0];
const RadOperand slot = RAD_B_N(program_->lora_slot_buf, r0, n);
RadOperand slot = RAD_P_T(batch_->lora_slot + r0, RAD_I32);
slot.rows = n;
const RadOperand tv = RAD_B_N(t, 0, n);
const RadOperand sh[5] = { xa,
s.opd_a_scale >= 0 && s.opd_a_scale < n_opd ? opd[s.opd_a_scale]