placement: --host-weights keeps an embedding table in the pinned host pool, read in place

The embedding table is the largest model-level weight a dense model has --
248320 x 5120 in bf16 is 1.18 GiB a card at --tp 2 -- and a step reads only
its rows: M of them, a few KiB at decode. On a 16 GiB card that is VRAM the
KV cache wants, and no strategy could move it: layer_offload spills whole
layers only, and the derived split charges every model-level weight to VRAM.

--host-weights NAMES places the named weights in the pinned host pool before
any strategy runs. The site is DeviceZeroCopy: the pool is mapped, so the
lookup kernel is handed its device-side address and reads the rows over the
link in place. The unit is never movable, and every assignment pass and VRAM
total skips it through one MoveUnit::preplaced(), as they skip the mapped
tier.

- weight_footprint() counts hosted units in their own bucket, so a derived
  split leaves them out of the weight budget and the KV pool gets the room
  without stating --vram-*-mib
- only a weight embedding lookups alone read is accepted: a GEMM operand
  (the head) would stream its shard every step, and is refused
- names are parsed at config time (comma-separated, trimmed, a trailing '*'
  a prefix); each one that matches nothing is warned about by name
- a weight the host pool cannot hold is refused with the plan filled in, and
  the placement report gives host weights their own line beside the pool
- GUIDE.md §4.3 and the flags table; engine info carries host_weights

Measured on Qwen3.8-27B-FP8 with its MTP head, 2x RX 9070 XT (16 GiB),
--tp 2, two sequences, a 2560-token step, the split derived:

                       table in VRAM   --host-weights token_embd.weight
  KV pool (tokens)            70,976              144,576
  decode, 500 tokens       115.8 tok/s          115.7 tok/s
  prefill, 22K prompt       2773 tok/s           2798 tok/s

Tests: place_test covers the footprint bucket, the pinned zero-copy
placement, the refusal of a GEMM's weight and of a pool too small; ctest
-LE 'gpu|oot' passes.
This commit is contained in:
Andrew Bowen authored and StillDeadcode committed 2026-10-05 12:52:38 +02:00
1 parent 20d6c2119f
commit bb4dddc424
8 files changed
+259 -13

No files matched your search

+21 -1
View File
@@ -95,6 +95,11 @@ struct MoveUnit {
Site site = Site::Device;
int32_t slab_slot = -1;
bool movable = false; /* may the heat engine relocate it after load */
bool host_forced = false; /* --host-weights put it in the pinned pool; no strategy moves it */
/* PLACED BEFORE ANY STRATEGY RAN, so every assignment pass skips it and no VRAM total counts
* it: the mapped tier (no device kernel can read it) and --host-weights. */
bool preplaced() const { return tier == Tier::Mapped || host_forced; }
const char* reason = "fits in vram"; /* a fixed string, so the report never guesses */
/* The group's INTERNAL LAYOUT, computed once here so the mover never has to. `offset[i]` is
@@ -239,6 +244,9 @@ public:
int64_t vram_budget = 0, host_budget = 0;
int64_t file_stage_reserve = 0;
int64_t file_windows = 0; /* the read windows' part of it */
/* --host-weights: taken out of --host-pool-mib before any strategy ran, like the file staging
* above, and reported beside it rather than among the pooled units. */
int64_t host_weights_bytes = 0;
/* ROUTED EXPERTS ON THE FILE TIER have no address of their own: a routed layer's are read into
* one of two VRAM buffers before the layer's first expert op and published there until the next
* routed layer starts (place/stager.h, FileStager). `file_layer_max` is the most one layer's
@@ -317,6 +325,7 @@ private:
void resolve_sites(const Program& prog);
void build_units(const Program& prog, Plan* p);
void pin_mapped(const Program& prog, Plan* p);
int pin_host_weights(const Program& prog, const Config& cfg, Plan* p) const;
void build_classes(Plan* p);
void rank_units(Plan* p, std::vector<int32_t>* order) const;
int assign(Plan* p);
@@ -361,9 +370,20 @@ struct WeightFootprint {
int64_t experts = 0; /* the elastic plane: what streams from host when it does not fit */
int64_t expert_layer_max = 0; /* the most expert bytes any one routed layer holds */
int64_t mapped = 0; /* no device kernel can read them; they never enter a pool at all */
int64_t hosted = 0; /* --host-weights: in the pinned host pool, never on the card */
int64_t n_units = 0;
};
void weight_footprint(const Program& prog, WeightFootprint* out);
void weight_footprint(const Program& prog, WeightFootprint* out,
const std::vector<std::string>& host_weights = {});
/* Does `name` match the --host-weights list: comma-separated, a trailing '*' matching a prefix.
* One definition, because Planner::pin_host_weights and weight_footprint must agree on it or the
* budget is resolved for weights the planner then puts somewhere else. */
bool host_weight_match(const std::vector<std::string>& list, const std::string& name);
/* Is every op that reads weight `w` an embedding lookup? Only those read a few rows a step; any
* other reader (a GEMM) would stream the whole weight over the link on every step. */
bool read_only_by_lookups(const Program& prog, rad_weight w);
/* "blk.12.ffn_gate_exps.3.weight" -> "blk.*.ffn_gate_exps.*.weight". The report's grouping key:
* one line per weight class rather than per weight (spec §16). */