Expand description
2026-09-25: PEFT LoRA adapters: audit, pack into the rank-padded slot pool
and the expert pool, slot routing and swap, and token overlays. “LoRA”
here means adapters; kv_lora_rank / q_lora_rank in the model config are
MLA dimensions, unrelated.
Owner: model-layers (lora). Invariants: none beyond the types.
Modules§
- rdma_
stage - 2026-09-25: The model-layers side of the RDMA adapter swap: fetch a
peer-staged adapter’s manifest, map each tensor to its landing offset in a
pool slot, and rebuild the slot’s pairs after model-engine’s
swap_lora_slot_from_peerhas landed them withRdmaLoraLoader.
Structs§
- Adapter
Slot - 2026-09-25: One pool slot: the resident adapter’s name and config, and its
pairs, which point into this slot’s region of the shared pool.
layersis indexed by global layer and hasnum_hidden_layersentries. An emptynamemarks a placeholder that holds no adapter. - Embed
Overlay - 2026-09-25: One adapter slot’s embed overlay:
rows([n_override, h]BF16) in the order ofids_dev(ascending u32 vocab ids), andslot_map(i32[vocab], the row index for an overridden id, else -1), which the embed kernel indexes by token id.lmheadisSomeonly for an untied head with its own overlay tensors. - Expert
Lora Layer - 2026-09-25: One MoE layer’s routed-expert pairs, keyed by
(expert_index, projection); only adapted experts have entries. - Expert
Work - 2026-09-25: One expert’s contiguous block of sorted rows. The planner,
expert_delta_workitems, emits none withrows == 0. - LmHead
Overlay - 2026-09-25: The overlay of an untied lm_head:
rows([n_override, h]BF16) and their vocab ids. The lm_head kernel writesdot(hidden, row)to each overridden id’s logit. - Lora
Adapter Input - 2026-09-25: One adapter to pack.
storeholds its tensors on the device as BF16:metrale_model_weights::weights::adapter::load_adapter_safetensorsconverts F16 and F32 on the host. - Lora
Layer Weights - 2026-09-25: One layer’s adapted modules, as
LoraPairs;Nonemeans the module is not adapted.Clonebecause a rotation copies the new active slot’s layers out of the pool set before re-installing them. - Lora
Weights - 2026-09-25: The loaded adapter set: one fixed-address pool of
max_lorasequal-size slots padded tomax_rank, oneAdapterSlotper pool slot, and per-(layer, module)[max_loras]device pointer tables. - Overlay
Raw - 2026-09-25: The adapter’s overlay tensors copied to device buffers of their
own, with their row counts:
*_baseis[*_r, h]and*_deltais[*_t, h].*_baseholds either thetoken_adapterbase table or amodules_to_savefull table. - Overlay
RawSlot - 2026-09-25: One adapter’s
OverlayRawand its trainable ids. - Overlay
Tensor - 2026-09-25: A classified overlay tensor: its table and its role.
- Overlay
Tensors - 2026-09-25: One adapter’s overlay tensor names by (table, role); each field is set at most once.
- Slot
View - 2026-09-25: A cache slot’s state as
select_victim_slotreads it, built byLoraWeights::cache_slot_views. - Token
Overlay Set - 2026-09-25: The overlay tables for the whole adapter pool, built from the
per-slot
EmbedOverlays. Model-engine keeps it only when some slot has an overlay (any_active).
Enums§
- Adapter
Ab - Expert
Proj - 2026-09-25: Which routed-expert projection a delta targets.
- Lora
Module - Lora
Sites - 2026-10-03: Which attention LoRA sites a step of one sequence runs.
- Lora
Target - 2026-09-25: The decoded target of one PEFT LoRA tensor.
- Overlay
Module - 2026-09-25: The table an overlay tensor belongs to.
- Overlay
Tensor Kind - 2026-09-25: The role an overlay tensor plays in
build_overlay. - Victim
Error - 2026-09-25: Why a promotion found no victim slot.
Constants§
- ROWDIFF_
THRESH - 2026-09-25: A base row whose largest absolute difference from the served
row exceeds this is overridden (
embed_rowdiff_bf16).
Functions§
- adapter_
id_ hash - 2026-09-25: The adapter’s cache-identity key, which keeps prefix and KV
reuse within one adapter. It is FNV-1a over the adapter’s name, then over
generation’s little-endian bytes whengeneration != 0. It never depends on the pool slot, so an adapter moved to another slot keeps its id. A swap into a slot bumps that slot’s generation, which changes the id.0is reserved for the base model, so a hash of 0 becomes 1. - allow_
partial_ targets - 2026-09-25:
METRALE_LORA_ALLOW_PARTIAL(1ortrue, any case): load an adapter that names target modules the engine cannot apply, skipping those. Re-exported from metrale-config, whose parse-time check reads the same switch, so both checks see one value. 2026-09-26:METRALE_LORA_ALLOW_PARTIAL(1ortrue, any case), read once per process: load an adapter that names target modules the engine cannot apply, skipping those. - apply_
expert_ lora_ sorted - 2026-09-25: Fold
proj’s per-expert deltas onto the expert-sorted grouped-GEMM output.xis the sorted input ([total_expanded, k_in]),base_outthe sorted output ([total_expanded, n_out], in place), andexpert_offsets_hosta host copy ofexpert_offsets. Only experts with a pair forprojand at least one row are folded, each over its own row block. - apply_
router_ lora - 2026-09-25: Fold the router (
mlp.gate) delta ontogate_logits([n, num_experts], in place) fromrouter_in([n, hidden]), in blocks of at mostmax_rowsrows. - build_
moe_ row_ adapter_ decode - 2026-09-25: The
[padded_n]per-row adapter map of a decode batch, one token per sequence, whichmoe_lora_gather_bgmv.cureads asrow_adapter[row / top_k]and skips when negative. Rowiisactivewhenresolve_moe_lora_routegivesFold, else-1; soSkip,Refuseand padding rows (i >= adapter_slots.len()) are all-1, which is not the attentionseq_slotconvention (there-1means the active adapter). Model-engine uploads it inupload_moe_row_adapter. - build_
moe_ row_ adapter_ host - 2026-09-25: The
[total_tokens]per-row adapter map of a packed prefill batch.cu_seqlens_hostis the[batch + 1]prefix sum of per-stream token counts; streamb’sadapter_slots[b]is written, unchanged, over rowscu_seqlens_host[b]..cu_seqlens_host[b + 1]. Only tests call it today. - build_
overlay - 2026-09-25: Build one slot’s
EmbedOverlay: clamp the trainable ids, diff and compact the embed rows, build theslot_map, and, for an untied head (!tied) with its own base, the lm_head rows. The staged buffers are freed when an overlay is returned.Ok(None)when the slot has no embed base or overrides no row. An error when the overlay kernels are not loaded. Model-engine passestiedwhen the lm_head shares the embed buffer or is served quantized;TokenOverlaySet::from_slotsthen points the lm_head at the embed rows. - build_
override_ set - 2026-09-25: The vocab rows the overlay replaces: the indices
iwithrow_diff[i]set, plustrainable, sorted ascending without duplicates. - build_
seq_ slot_ host - 2026-09-25: The host
seq_slot[padded_n]buffer the bgmv reads, one entry per row: row i < n:adapter_slots[i]if>= 0, elseactive(a negative slot means the active adapter); row i >= n (padding):-1, whichlora_bgmv.cutreats as no delta. - clamp_
trainable_ to_ vocab - 2026-09-25: Split
trainableids at the served vocab, keeping list order, since delta rowkbelongs to thek-th id. Returns(kept_ids, skipped_count): - classify_
key - 2026-09-25: PEFT tensor name → (layer, target, A or B). Every name it
cannot place is an error naming the reason (
REJECT[...]), never a skip. Whatever precedes.layers.is ignored, somodel.layers.{i}.*andmodel.language_model.layers.{i}.*both parse; the layer index follows.layers.. - classify_
overlay_ key - 2026-09-25: Classify a PEFT tensor name as an overlay tensor.
Nonefor a name without thebase_model.model.prefix, alora_A/lora_Bweight (forsuper::classify_key), or a name matching no overlay form. Only the module name and suffix are matched, somodel.embed_tokensandmodel.language_model.embed_tokensboth work. Thetoken_adapterandlora_embeddingsuffixes are tested before the bare.weightform, so…token_adapter.base_layer.weightis not taken for a full table. - ensure_
decode_ route_ servable - 2026-09-25: An error when
routeisRefuse. The batched decode entries (model-enginedecode_batch_compute_main,mixed_forward) call it before any graph lookup:build_moe_row_adapter_decodewrites aRefuserow as-1, so the batch would otherwise run that request without its adapter. - expert_
delta_ workitems - 2026-09-25: Work items for the adapted experts, from the
expert_offsetsprefix sum ([num_experts + 1]; experte’s sorted rows areexpert_offsets[e]..expert_offsets[e + 1]). An expert index past the table, or withend <= start, is skipped. - expert_
router_ bytes - 2026-09-25: Padded bytes of the expert/router pool for the given audited
keys:
(stride * in + out * stride) * 2per expert key and per router layer.strideisexpert_pack::packed_stride(max_rank), the strideexpert_pack::pack_intoadvances by, so the size matches what is packed. - full_
attention_ layers - is_
gdn_ key - 2026-09-25: Whether
keynames alinear_attn.*tensor other thanlinear_attn.out_proj, the familyclassify_keyrefuses withREJECT[gdn-target].audit_adapterskips these underMETRALE_LORA_ALLOW_PARTIALinstead of matching on the refusal message. - load_
lora_ adapters_ generic - 2026-09-25:
load_lora_adapters_multiwith one adapter, whose slot name is empty. - load_
lora_ adapters_ multi - 2026-09-25: Load startup adapters: audit each one, check free memory, pack
adapter k into slot k, then build the per-module
[max_loras]pointer tables (0 where a slot has no pair) and the[max_loras]scale table. Slots past the adapter count are empty placeholders. - lora_
eager_ env - 2026-09-25:
METRALE_LORA_EAGER(1ortrue, any case), from the process-wideModelLevers::get(). The model reads its own copy,levers.lora_eager, and runs decode and verify without CUDA graphs while an adapter is loaded. - lora_
experts_ env - 2026-09-25:
METRALE_LORA_EXPERTS(1ortrue, any case), read once: load routed-expert and router LoRA deltas. Unset, an adapter with expert or router tensors is refused at load (expert_pack.rs). - lora_
peer_ env - 2026-09-25:
METRALE_LORA_PEER, the host:port of the weight peer that stages adapters, when set and non-empty. Setting it also sets the model’slora_rotatable(seelora_rotate_env). - lora_
rotate_ env - 2026-09-25:
METRALE_LORA_ROTATE(1ortrue, any case), from the process-wideModelLevers::get(). It, orlora_peer_env, sets the model’slora_rotatable, which permits runtime adapter rotation and swap whatever the number of resident adapters. It does not make decode eager; onlyMETRALE_LORA_EAGERdoes.met serverefuses--lora-stageable-diskunless this or a peer is set. - max_
lora_ expert_ rank - 2026-09-25: The padded rank of the expert and router LoRA pools,
METRALE_LORA_EXPERT_RANK(a positive integer; otherwise 16), read once. It is separate from--max-lora-rank, which sizes the slot pool. An adapter whoserexceeds it is refused at load (expert_pack.rs). - no_
batch_ verify - 2026-09-25:
METRALE_LORA_NO_BATCH_VERIFY=1, read once: while an adapter is loaded, cross-sequence batched verify is not eligible (model-enginetrait_impl/verify_e.rs). - override_
source - 2026-09-25: Where an overridden id’s row comes from:
Some(k), delta rowk, whenidis thek-th trainable id (this wins over a differing base row);None, the adapter’s base rowid. - pack_
store_ into_ slot - 2026-09-25: Disk swap: audit
storeand pack it into existing poolslotoflwin place, with the sameaudit_adapterandpack_slotas the startup load. The slot region is zeroed first, since it still holds the previous adapter. Then the slot’s name, config and pairs are replaced, its pointer and scale table entries refreshed, and its generation bumped. Returns the new pairs so the caller can re-install them when the slot is active. - prefill_
bgmv_ forced - 2026-09-25:
METRALE_LORA_PREFILL_BGMV=1, read once: the attention QKV prefill applies LoRA with the per-rowapply_lora_bgmvinstead ofapply_lora_deltawhen the call has a slot buffer and a route (layers/qwen3_attention/prefill/paged_qkv.rs). - reject_
pending_ overlay - 2026-09-25: An error when the adapter has a
lora_embedding_A/Btensor; every other overlay tensor is loaded. - resolve_
moe_ lora_ route - 2026-09-25: The MoE LoRA fold decision for one request:
- routed_
prefill_ slot_ of - 2026-09-25: The predicate behind
LoraWeights::routed_prefill_slot. Resolvesadapter_slot(>= 0is that slot, negative isactive) and returns it only when it is notactiveand is< num_slots; otherwiseNone. - router_
dims - 2026-09-25:
(out_dim, in_dim)of the router (mlp.gate) projection. Its delta is added to the routing logits before top-k. - select_
routed_ pair - 2026-09-25: The
LoraPairfor (global layer, module) in a slot’s global-layer-indexedlayers.Nonewhen the index is out of range, the layer has no pairs, or the adapter has no pair for that module. - select_
victim_ slot - 2026-09-25: Pick the slot a promotion overwrites, from
cache, the(slot_index, view)pairs the caller passes (model-engine passescache_slot_views(), slots[pinned, max_loras)): - stage_
overlay_ raw - 2026-09-25: Copy one adapter’s overlay tensors to device buffers of their
own.
Ok(None)when it has none, or has alora_embeddingtensor (the audit refuses those). Amodules_to_savetable goes into*_basewhen there is notoken_adapterbase. An error when neither table has a base. - uniform_
seq_ slots - 2026-10-03: The
count-row slot buffer a step of one sequence uploads, orNonefor the installed-pair path: only a request that resolves to the active adapter, on sites with a pair fallback, takes the pair. Multi-sequence sites always get their rows’ slots, or the attention would run without the adapter (the active-adapter MTP verify did until 2026-10-03). - validate_
peft_ config - 2026-09-25: Adapter-config checks that need
--max-lora-rank: the rank fits the pool, and every target module is oneLoraModuleor the router (gate). The parse-time checks are inmetrale_config::parse_peft_adapter_config.