Archived
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:
1 parent
09ff76701c
commit
582cda0a53
15 files changed
+141
-84
No files matched your search
+1
-1
@@ -17,7 +17,7 @@ extern "C" {
|
||||
* kind of plugin reports it, and a plugin that does not report exactly this version is refused at
|
||||
* load with both versions printed. A new optional export (e.g. rad_plugin_reference) is not a
|
||||
* change of shape: a plugin without it gets the default. */
|
||||
#define RAD_ABI_VERSION 17u
|
||||
#define RAD_ABI_VERSION 18u
|
||||
|
||||
/* ================================================================== plugin identity */
|
||||
/* One value per plugin, not flags (QUANT is 3). RAD_PLUGIN_QUANT is a quantiser plugin:
|
||||
|
||||
@@ -49,6 +49,17 @@ typedef struct RadBatch {
|
||||
const int32_t* positions; /* [n_tok] device */
|
||||
const int32_t* cu_seqlens; /* [n_seq+1] device: sequence boundaries within this step */
|
||||
const int32_t* seq_ids; /* [n_seq] device: engine-side sequence identity */
|
||||
/* [n_tok] device: the runtime LoRA adapter each token's row runs with, as a slot of the
|
||||
* adapter pools the core declared (docs/OPS.md, lora_shrink / lora_expand). A row whose slot is
|
||||
* < 0 or >= the pools' slot count S is a base row, which an adapter op leaves untouched. Every
|
||||
* row of a sequence carries its request's slot, fixed when the request was admitted, so a step
|
||||
* that mixes adapters and the base needs nothing else.
|
||||
*
|
||||
* Null when the engine serves no adapters (no --lora and no --max-loras). The core issues the
|
||||
* adapter ops itself and reads it there; a block with an adapter epilogue of its own reads it
|
||||
* too. Like every array above it sits at one address per rank for the engine's life and is
|
||||
* rewritten every step, so a recorded pass replays it. */
|
||||
const int32_t* lora_slot;
|
||||
|
||||
/* The tokens the sampler wants logits for: indices into this step's tokens, [n_out].
|
||||
*
|
||||
|
||||
+2
-13
@@ -29,14 +29,13 @@ bool is_coded(uint32_t dt) {
|
||||
}
|
||||
|
||||
rad_buf decl_persist(Builder& b, const std::string& name, uint32_t dtype, uint32_t rank,
|
||||
const int64_t* shape, int kind = RAD_BUF_PERSIST, const char* derive = nullptr) {
|
||||
const int64_t* shape) {
|
||||
RadBufDecl d{};
|
||||
d.dtype = dtype;
|
||||
d.rank = rank;
|
||||
for (uint32_t i = 0; i < rank; ++i) d.shape[i] = shape[i];
|
||||
d.kind = kind;
|
||||
d.kind = RAD_BUF_PERSIST;
|
||||
d.domain = RAD_DOMAIN_DEVICE;
|
||||
d.derive = derive;
|
||||
return b.decl_buffer(name.c_str(), &d);
|
||||
}
|
||||
|
||||
@@ -130,16 +129,6 @@ int lora_declare(Builder& b, const LoraDeclare& d) {
|
||||
P.lora_t.push_back(sc);
|
||||
}
|
||||
|
||||
/* ---- the per-token slot, derived by the core each step (core/sched/derive.cpp) */
|
||||
{
|
||||
const int64_t sh[1] = { max_tok };
|
||||
P.lora_slot_buf = decl_persist(b, "lora.slot", RAD_I32, 1, sh, RAD_BUF_DERIVED, "lora_slot");
|
||||
if (!P.lora_slot_buf) {
|
||||
RAD_ERR("lora: could not declare the per-token slot buffer");
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- the two ops behind each targeted GEMM */
|
||||
P.lora_sites.clear();
|
||||
int n_refused = 0;
|
||||
|
||||
@@ -349,7 +349,6 @@ public:
|
||||
std::vector<LoraIssueSite> lora_sites;
|
||||
std::vector<LoraPool> lora_pools;
|
||||
std::vector<LoraScratch> lora_t;
|
||||
rad_buf lora_slot_buf = 0; /* RAD_BUF_DERIVED "lora_slot", [max_tok] i32 */
|
||||
|
||||
/* The declared draft head (rad_declare_drafter). `kind == RAD_DRAFT_NONE` when none, the
|
||||
* normal case: the engine then speculates with the scheduler's prompt-lookup drafter or not at
|
||||
|
||||
@@ -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
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -205,6 +205,9 @@ private:
|
||||
* mm_rows): carved only when the program declared an encoder, empty otherwise. */
|
||||
int32_t *h_rope = nullptr, *d_rope = nullptr;
|
||||
int32_t *h_mmrow = nullptr, *d_mmrow = nullptr;
|
||||
/* [n_tok] each row's runtime LoRA adapter slot (RadBatch::lora_slot): carved only when the
|
||||
* engine serves adapters, empty otherwise. */
|
||||
int32_t *h_lora = nullptr, *d_lora = nullptr;
|
||||
/* [n_kv_groups][max_seqs]: every conv group's state slot per sequence (see init()). */
|
||||
int32_t* h_convslot = nullptr;
|
||||
|
||||
@@ -310,6 +313,8 @@ private:
|
||||
* (see RadBatch::mm_embd). The staging is refilled only after its last upload has run
|
||||
* (`mm_ev_`). */
|
||||
bool mm_on_ = false;
|
||||
/* The engine serves runtime LoRA adapters (Config::lora): the batch carries each row's slot. */
|
||||
bool lora_on_ = false;
|
||||
int64_t n_embd_ = 0;
|
||||
std::vector<void*> mm_dev_;
|
||||
uint16_t* mm_host_ = nullptr;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* derive.cpp -- the derivation table, one row per name.
|
||||
*/
|
||||
#include "derive.h"
|
||||
#include "rad_core.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -82,24 +81,6 @@ static int d_state_chunk_seq(const DeriveInput& in, int32_t* out, int64_t cap, i
|
||||
return chunk_walk<true>(in, out, cap, n_out);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ lora_slot */
|
||||
/* [n_tok] -- the runtime LoRA adapter slot each token's row is multiplied with, -1 for the base
|
||||
* model (core/lora/). A sequence's slot is its request's, fixed when the request was admitted, so
|
||||
* every row of one sequence carries the same value and a step mixing adapters needs nothing but
|
||||
* this array: the LoRA kernels read the slot of each row they touch and leave a -1 row alone. */
|
||||
static int d_lora_slot(const DeriveInput& in, int32_t* out, int64_t cap, int64_t* n_out) {
|
||||
if (in.n_tok > cap || !in.plan || (int64_t)in.plan->e.size() < in.n_seq) return RAD_E_FULL;
|
||||
for (int64_t i = 0; i < in.n_seq; ++i) {
|
||||
const Request* r = in.plan->e[(size_t)i].req;
|
||||
const int32_t slot = r ? r->lora_slot : -1;
|
||||
const int64_t b = in.cu_seqlens[i], e = in.cu_seqlens[i + 1];
|
||||
if (b < 0 || e < b || e > in.n_tok) return RAD_E_STATE;
|
||||
for (int64_t k = b; k < e; ++k) out[k] = slot;
|
||||
}
|
||||
*n_out = in.n_tok;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ the table */
|
||||
static const DeriveRow g_rows[] = {
|
||||
{ "seq_start_index", d_seq_start_index,
|
||||
@@ -110,8 +91,6 @@ static const DeriveRow g_rows[] = {
|
||||
"[n_chunks+1] token indices bounding each linear-state chunk; never crosses a sequence" },
|
||||
{ "state_chunk_seq", d_state_chunk_seq,
|
||||
"[n_chunks] the sequence each chunk belongs to" },
|
||||
{ "lora_slot", d_lora_slot,
|
||||
"[n_tok] the runtime LoRA adapter slot of each token's sequence, -1 for the base model" },
|
||||
};
|
||||
|
||||
int derive_index(const char* name) {
|
||||
|
||||
+5
-4
@@ -630,10 +630,11 @@ implementation reads `res` before it stores the product over it.
|
||||
|
||||
The two halves of `y += scale ⊙ (B · (A · x))` at a trunk GEMM, issued by the core right after the
|
||||
GEMM in the GEMM's own row slice, with several adapters and no adapter mixed in one step. `slot` is
|
||||
an i32 per row naming its adapter's pool slot; **a row with `slot < 0 || slot >= S` is a base row
|
||||
and neither op touches it**: `lora_shrink` writes nothing into its `t` row, and `lora_expand` does
|
||||
not read or write its `y` row at all — so a base row stays bit for bit what the GEMM wrote, where
|
||||
`y + 0` would already have turned a -0 into +0.
|
||||
an i32 per row naming its adapter's pool slot -- the step batch's `RadBatch::lora_slot` from the
|
||||
GEMM's first row on; **a row with `slot < 0 || slot >= S` is a base row and neither op touches
|
||||
it**: `lora_shrink` writes nothing into its `t` row, and `lora_expand` does not read or write its
|
||||
`y` row at all — so a base row stays bit for bit what the GEMM wrote, where `y + 0` would already
|
||||
have turned a -0 into +0.
|
||||
|
||||
- `lora_shrink`: `t[m, j] = Σ_k x(m, k) · lora_a[s, j, k]`, `s = slot[m]`, f32 accumulate.
|
||||
`a`/`a_scale` are the GEMM's own first two operands, and `x(m, k)` is the value `gemm_nt_q` uses
|
||||
|
||||
@@ -1096,7 +1096,8 @@ every KV group, rather than per group and per layer.
|
||||
It carries: token ids and positions; per-group slot mappings and block tables; sequence boundaries
|
||||
(`cu_seqlens`); query and context lengths with their host-side upper bounds; the speculative window
|
||||
layout (§10); encoder rows and M-RoPE positions (§11); checkpoint destinations (§7.3); the phase,
|
||||
which the run phase uses to index bucket tables (§2.2); and the decode/prefill split.
|
||||
which the run phase uses to index bucket tables (§2.2); the decode/prefill split; and each row's
|
||||
runtime LoRA adapter slot (`lora_slot`, null when the engine serves no adapters).
|
||||
|
||||
The split is `n_seq_decode` and `n_tok_decode`: the core orders every step so its decode rows come
|
||||
first, and those two say where they end. A block that treats the two kinds of row differently (a
|
||||
|
||||
@@ -32,6 +32,7 @@ ABI_FIELD(RadBatch, token_ids)
|
||||
ABI_FIELD(RadBatch, positions)
|
||||
ABI_FIELD(RadBatch, cu_seqlens)
|
||||
ABI_FIELD(RadBatch, seq_ids)
|
||||
ABI_FIELD(RadBatch, lora_slot)
|
||||
ABI_FIELD(RadBatch, n_out)
|
||||
ABI_FIELD(RadBatch, out_ids)
|
||||
ABI_FIELD(RadBatch, q_lens)
|
||||
|
||||
+39
-38
@@ -1,4 +1,4 @@
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 17 and
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 18 and
|
||||
* RAD_FORMAT_VER 2, as { type, field, offset, size } rows ("" is the struct itself). A snapshot
|
||||
* of the headers on x86-64 Linux, which abi_layout_test.cpp holds the layout to; regenerate it
|
||||
* from the test's printout only together with a version bump. */
|
||||
@@ -20,7 +20,7 @@
|
||||
{ "RadArgs", "instance", 48, 8 },
|
||||
{ "RadArgs", "rank", 56, 4 },
|
||||
{ "RadArgs", "world_size", 60, 4 },
|
||||
{ "RadBatch", "", 0, 312 },
|
||||
{ "RadBatch", "", 0, 320 },
|
||||
{ "RadBatch", "phase", 0, 4 },
|
||||
{ "RadBatch", "step", 4, 4 },
|
||||
{ "RadBatch", "n_tok", 8, 8 },
|
||||
@@ -29,42 +29,43 @@
|
||||
{ "RadBatch", "positions", 32, 8 },
|
||||
{ "RadBatch", "cu_seqlens", 40, 8 },
|
||||
{ "RadBatch", "seq_ids", 48, 8 },
|
||||
{ "RadBatch", "n_out", 56, 8 },
|
||||
{ "RadBatch", "out_ids", 64, 8 },
|
||||
{ "RadBatch", "q_lens", 72, 8 },
|
||||
{ "RadBatch", "ctx_lens", 80, 8 },
|
||||
{ "RadBatch", "max_q_len", 88, 4 },
|
||||
{ "RadBatch", "max_ctx_len", 92, 4 },
|
||||
{ "RadBatch", "n_kv_groups", 96, 4 },
|
||||
{ "RadBatch", "kv", 104, 8 },
|
||||
{ "RadBatch", "n_spec", 112, 4 },
|
||||
{ "RadBatch", "num_accepted", 120, 8 },
|
||||
{ "RadBatch", "spec_parent", 128, 8 },
|
||||
{ "RadBatch", "draft_pass", 136, 4 },
|
||||
{ "RadBatch", "n_checkpoints", 140, 4 },
|
||||
{ "RadBatch", "checkpoint_tok", 144, 8 },
|
||||
{ "RadBatch", "checkpoint_slot", 152, 8 },
|
||||
{ "RadBatch", "n_seq_decode", 160, 8 },
|
||||
{ "RadBatch", "n_tok_decode", 168, 8 },
|
||||
{ "RadBatch", "max_q_len_decode", 176, 4 },
|
||||
{ "RadBatch", "max_q_len_prefill", 180, 4 },
|
||||
{ "RadBatch", "n_draft_out", 184, 8 },
|
||||
{ "RadBatch", "draft_out_ids", 192, 8 },
|
||||
{ "RadBatch", "n_ahead", 200, 8 },
|
||||
{ "RadBatch", "rope_pos", 208, 8 },
|
||||
{ "RadBatch", "rope_mixed", 216, 4 },
|
||||
{ "RadBatch", "n_mm_rows", 224, 8 },
|
||||
{ "RadBatch", "mm_rows", 232, 8 },
|
||||
{ "RadBatch", "mm_embd", 240, 8 },
|
||||
{ "RadBatch", "enc", 248, 4 },
|
||||
{ "RadBatch", "enc_n_patch", 256, 8 },
|
||||
{ "RadBatch", "enc_pixels", 264, 8 },
|
||||
{ "RadBatch", "enc_coord", 272, 8 },
|
||||
{ "RadBatch", "enc_n_seg", 280, 8 },
|
||||
{ "RadBatch", "enc_cu", 288, 8 },
|
||||
{ "RadBatch", "enc_max_seg", 296, 4 },
|
||||
{ "RadBatch", "gen", 300, 4 },
|
||||
{ "RadBatch", "gen_b", 304, 8 },
|
||||
{ "RadBatch", "lora_slot", 56, 8 },
|
||||
{ "RadBatch", "n_out", 64, 8 },
|
||||
{ "RadBatch", "out_ids", 72, 8 },
|
||||
{ "RadBatch", "q_lens", 80, 8 },
|
||||
{ "RadBatch", "ctx_lens", 88, 8 },
|
||||
{ "RadBatch", "max_q_len", 96, 4 },
|
||||
{ "RadBatch", "max_ctx_len", 100, 4 },
|
||||
{ "RadBatch", "n_kv_groups", 104, 4 },
|
||||
{ "RadBatch", "kv", 112, 8 },
|
||||
{ "RadBatch", "n_spec", 120, 4 },
|
||||
{ "RadBatch", "num_accepted", 128, 8 },
|
||||
{ "RadBatch", "spec_parent", 136, 8 },
|
||||
{ "RadBatch", "draft_pass", 144, 4 },
|
||||
{ "RadBatch", "n_checkpoints", 148, 4 },
|
||||
{ "RadBatch", "checkpoint_tok", 152, 8 },
|
||||
{ "RadBatch", "checkpoint_slot", 160, 8 },
|
||||
{ "RadBatch", "n_seq_decode", 168, 8 },
|
||||
{ "RadBatch", "n_tok_decode", 176, 8 },
|
||||
{ "RadBatch", "max_q_len_decode", 184, 4 },
|
||||
{ "RadBatch", "max_q_len_prefill", 188, 4 },
|
||||
{ "RadBatch", "n_draft_out", 192, 8 },
|
||||
{ "RadBatch", "draft_out_ids", 200, 8 },
|
||||
{ "RadBatch", "n_ahead", 208, 8 },
|
||||
{ "RadBatch", "rope_pos", 216, 8 },
|
||||
{ "RadBatch", "rope_mixed", 224, 4 },
|
||||
{ "RadBatch", "n_mm_rows", 232, 8 },
|
||||
{ "RadBatch", "mm_rows", 240, 8 },
|
||||
{ "RadBatch", "mm_embd", 248, 8 },
|
||||
{ "RadBatch", "enc", 256, 4 },
|
||||
{ "RadBatch", "enc_n_patch", 264, 8 },
|
||||
{ "RadBatch", "enc_pixels", 272, 8 },
|
||||
{ "RadBatch", "enc_coord", 280, 8 },
|
||||
{ "RadBatch", "enc_n_seg", 288, 8 },
|
||||
{ "RadBatch", "enc_cu", 296, 8 },
|
||||
{ "RadBatch", "enc_max_seg", 304, 4 },
|
||||
{ "RadBatch", "gen", 308, 4 },
|
||||
{ "RadBatch", "gen_b", 312, 8 },
|
||||
{ "RadBufDecl", "", 0, 80 },
|
||||
{ "RadBufDecl", "dtype", 0, 4 },
|
||||
{ "RadBufDecl", "rank", 4, 4 },
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Checked: a C translation unit (abi_c_test.c, strict C11) lays every struct out as C++ does; every
|
||||
* struct's listed fields account for its size, so the list in abi_layout_rows.h is complete; and
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 17 and RAD_FORMAT_VER 2. Under
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 18 and RAD_FORMAT_VER 2. Under
|
||||
* those versions a listed field may not move or change size, an ABI struct may only grow by fields
|
||||
* past its old end, and an on-disk struct may not change at all. The table is a snapshot of the
|
||||
* headers: nothing else states the layout. When it disagrees the test prints the live table.
|
||||
@@ -57,8 +57,8 @@ std::vector<Row> cpp_rows() {
|
||||
};
|
||||
}
|
||||
|
||||
/* The layout at RAD_ABI_VERSION 17 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 17, kTableFormat = 2;
|
||||
/* The layout at RAD_ABI_VERSION 18 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 18, kTableFormat = 2;
|
||||
const AbiRow kTable[] = {
|
||||
#include "abi_layout_table.h"
|
||||
};
|
||||
|
||||
@@ -1121,6 +1121,52 @@ TEST(derived_metadata_is_computed_once_per_step_into_the_arena) {
|
||||
CHECK_EQ(ci[0], cslot * 4 + (p.e[0].conv_cursor % 4));
|
||||
}
|
||||
|
||||
/* RadBatch::lora_slot: every row of a sequence carries its request's runtime LoRA slot, -1 for a
|
||||
* base request, in the step's row order (decode rows first). */
|
||||
TEST(the_step_batch_carries_each_rows_adapter_slot) {
|
||||
Fixture f;
|
||||
f.build();
|
||||
f.cfg.lora.max_loras = 2;
|
||||
CHECK_OK(f.start());
|
||||
|
||||
auto r = f.request(100, 64);
|
||||
r->lora_slot = 1;
|
||||
r->lora_uid = 7;
|
||||
CHECK(f.add(std::move(r)) != 0);
|
||||
const RadBatch* b = f.sch.step();
|
||||
CHECK(b != nullptr);
|
||||
CHECK(b->lora_slot != nullptr);
|
||||
CHECK_EQ(b->n_tok, (int64_t)100);
|
||||
for (int64_t i = 0; i < b->n_tok; ++i) CHECK_EQ(b->lora_slot[i], 1);
|
||||
f.commit_plain();
|
||||
|
||||
f.submit(64, 64);
|
||||
b = f.sch.step();
|
||||
CHECK(b != nullptr);
|
||||
CHECK_EQ(b->n_tok, (int64_t)65);
|
||||
CHECK_EQ(b->lora_slot[0], 1); /* the adapter request's decode row */
|
||||
for (int64_t i = 1; i < 65; ++i) CHECK_EQ(b->lora_slot[i], -1); /* the base prefill */
|
||||
}
|
||||
|
||||
/* With no adapters served the field is null and the step slab is byte for byte what it was before
|
||||
* the field existed: the slot array is the only thing adapters add to it. */
|
||||
TEST(no_adapters_no_slot_array) {
|
||||
Fixture f;
|
||||
f.build();
|
||||
CHECK_OK(f.start());
|
||||
f.submit(32, 8);
|
||||
const RadBatch* b = f.sch.step();
|
||||
CHECK(b != nullptr);
|
||||
CHECK(b->lora_slot == nullptr);
|
||||
|
||||
Config on = f.cfg;
|
||||
on.lora.max_loras = 2;
|
||||
const int64_t off_bytes = BatchBuilder::device_bytes(f.prog, f.cfg, f.kv.geom);
|
||||
const int64_t on_bytes = BatchBuilder::device_bytes(f.prog, on, f.kv.geom);
|
||||
CHECK(off_bytes > 0);
|
||||
CHECK_EQ(on_bytes - off_bytes, (f.cfg.max_tok * 4 + 255) / 256 * 256);
|
||||
}
|
||||
|
||||
TEST(state_chunk_bounds_split_a_long_prefill_at_absolute_multiples) {
|
||||
DeriveInput in;
|
||||
StepPlan plan;
|
||||
|
||||
Reference in new issue
Block a user