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

+10 -11
View File
@@ -367,19 +367,18 @@ inline int PleLayer::declare(RadBuilder* b, Names& nm, const Geom& geom, const C
{}, {b_ids});
/* M IS T * heads HERE, not T: the gather fetches one table row per HEAD per token, and the
* band this op resolves on is that count. */
* band this op resolves on is that count. `resident` only when the deployment asked for the
* table in RAM (--ngram-table ram), so the default declares exactly the op it always has. */
const RadParam gp[] = { RAD_RANGE("M", 1, g.max_tok * c.heads), RAD_INT("n_embd", HD),
RAD_INT("n_vocab", c.rows), RAD_STR("dtype", g.dtype),
RAD_INT("resident", 1) };
const int n_gp = g.ngram_ram ? 5 : 4;
if (table_bf16)
op_gather = rw(b, RAD_OP(b, "embed_lookup_q",
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok * c.heads), RAD_INT("n_embd", HD),
RAD_INT("n_vocab", c.rows), RAD_STR("dtype", g.dtype)),
RAD_WEIGHTS(w_table)),
{b_ids}, {b_emb});
op_gather = rw(b, RAD_OP(b, "embed_lookup_q", gp, n_gp, RAD_WEIGHTS(w_table)),
{b_ids}, {b_emb});
else
op_gather = rw(b, RAD_OP(b, "embed_lookup_q",
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok * c.heads), RAD_INT("n_embd", HD),
RAD_INT("n_vocab", c.rows), RAD_STR("dtype", g.dtype)),
RAD_WEIGHTS(w_table, w_scale)),
{b_ids}, {b_emb});
op_gather = rw(b, RAD_OP(b, "embed_lookup_q", gp, n_gp, RAD_WEIGHTS(w_table, w_scale)),
{b_ids}, {b_emb});
op_embd = rw(b, RAD_OP(b, "cast",
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok), RAD_INT("n", c.embed_dim),