n-gram table: --ngram-table ram reads it from a locked copy in RAM

embed_lookup_q reads the n-gram table through a row cache and direct reads,
and about half of a step's rows are first-seen, so steps wait on the drive.
--ngram-table ram (default disk, unchanged) copies the table into locked
huge pages in the background, checks the copy against the mapping and then
serves the gather from memory. MemAvailable, RLIMIT_MEMLOCK and the cgroup
limit are checked first; if any is short the table stays on disk. The flag
reaches the plugin as an optional `resident` parameter of embed_lookup_q.
This commit is contained in:
keptn42 authored and StillDeadcode committed 2026-10-05 12:52:50 +02:00
1 parent 4252353bc2
commit e6c8a3d7fa
18 files changed
+363 -56

No files matched your search

+7 -1
View File
@@ -783,7 +783,7 @@ either wire, byte-identical to the three kernels it stands in for.
| op | params | operands |
|---|---|---|
| `embed_lookup` | `M`(range) `n_embd` `n_vocab` `dtype` `vocab_offset`/opt `wscale`:f64/opt | `tokens`, `wte`w → `x` |
| `embed_lookup_q` | `M`(range) `n_embd` `n_vocab` `dtype` `vocab_offset`/opt `wscale`:f64/opt | `tokens`, `wte`w, `scale`w? → `x`, `ahead`? |
| `embed_lookup_q` | `M`(range) `n_embd` `n_vocab` `dtype` `vocab_offset`/opt `wscale`:f64/opt `resident`/opt | `tokens`, `wte`w, `scale`w? → `x`, `ahead`? |
| `logits_gemm` | `M`(range) `n_vocab` `n_embd` `dtype` | `x`, `lm_head`w → `logits` |
| `ngram_ids` | `M`(range) `heads` `ngram` `eos` | `tok`, `state`:inout, `cu`, `mult`w, `vocab_sizes`w, `offsets`w, `cache_idx`?, `has_init`?, `num_accepted`? → `ids`, `ahead_ids`? |
| `ple_gate` | `M`(range) `n` `hc` `eps`:f64 `dtype` `wadd`:f64/opt `gate_eps`:f64/opt | `k`, `q`, `v`, `w_key`w, `w_query`w, `w_conv`w → `gv`, `gvn` |
@@ -891,6 +891,12 @@ the alignment the filesystem reports for direct I/O, or its block size where it
btrfs does; one read of the table proves it before the first row is served. A filesystem with no
direct I/O at all cannot hold a container with this table.
**`resident` keeps the table in RAM instead**, for a deployment that has the memory: libavx copies
it once into locked huge pages, in the background from the first gather that carries it, and reads
the copy from then on; until the copy is in place, and wherever the process cannot lock that much,
the rows come from the file as above. The result is the same either way. An architecture sets it
from `RadBuildCtx::ngram_table_ram` (`--ngram-table ram`).
The placement planner runs an op on the host when **every weight operand of it** is `Site::Host`,
which is why the table must be a weight operand at all: `gather_rows` takes a plain `IN` operand and
would never trigger it. And the host kernel has to live in a production plugin — libavx, the host