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
View File
@@ -63,6 +63,10 @@ static const Flag g_flags[] = {
{ "--weights-disk-tier", nullptr, "read weights that fit neither VRAM nor the host pool from the\n"
" container on disk (O_DIRECT); a routed expert is read a layer\n"
" at a time, so a step is paced by the drive" },
{ "--ngram-table", "MODE", "disk (default) or ram: where the n-gram embedding's host gather\n"
" reads its rows. ram copies the table into locked host memory\n"
" in the background from the first request and reads the copy\n"
" (Qwen3.8-Flash-Next: 47.7 GiB; needs a memlock limit that large)" },
{ "--prefix-cache-host-mib", "N", "copy finished conversations' KV to host memory, up to N MiB,\n"
" so their VRAM can go to experts and a return restores\n"
" instead of re-prefilling. 0 is off. Part of it holds\n"
@@ -398,6 +402,12 @@ int config_parse(int argc, char** argv, Config* c) {
}
}
else if (S("--weights-disk-tier")) { c->weights_disk_tier = true; }
else if (S("--ngram-table")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "disk")) c->ngram_table_ram = false;
else if (!std::strcmp(v, "ram")) c->ngram_table_ram = true;
else { RAD_ERR("--ngram-table takes disk or ram, not '%s'", v); return RAD_E_INVAL; }
}
else if (S("--prefix-cache-host-mib")) { if (!(v = need(i))) return RAD_E_INVAL; c->prefix_cache_host_mib = atoll(v); }
else if (S("--prefix-cache-dir")) { if (!(v = need(i))) return RAD_E_INVAL; c->prefix_cache_dir = v; }
else if (S("--prefix-cache-disk-mib")) { if (!(v = need(i))) return RAD_E_INVAL; c->prefix_cache_disk_mib = atoll(v); }
+1
View File
@@ -413,6 +413,7 @@ RadBuildCtx Engine::build_ctx(int rank, int64_t max_tok) const {
/* A row at every token of the step and the sampler's row a sequence before them
* (core/kld.h); the KL mode has no speculation, so a sequence samples one. */
bc.max_out_rows = cfg_.kld() ? max_tok + cfg_.max_seqs : 0;
bc.ngram_table_ram = cfg_.ngram_table_ram ? 1 : 0;
return bc;
}
+8
View File
@@ -614,6 +614,14 @@ struct Config {
* is a server that is correct and several orders of magnitude slow. The tier needs no directory
* of its own; the container is the file. */
bool weights_disk_tier = false;
/* --ngram-table disk|ram: where the host gather of a table too large for any card -- the n-gram
* embedding, 47.7 GiB in Qwen3.8-Flash-Next -- reads its rows. disk, the default, reads them
* from the container through a row cache and holds no more of the table than that. ram copies
* the table once into locked host memory, in the background from the first request, and reads
* the copy: a faster prefill and a few percent of throughput, for the table's size in RAM. A
* process that cannot lock that much says so and stays on disk. A deployment choice and not a
* tuning one, because only the operator knows what else the host's memory is for. */
bool ngram_table_ram = false;
std::string placement = "auto"; /* all_vram | layer_offload | expert_tiered | auto */
/* MODEL-LEVEL WEIGHTS KEPT IN THE PINNED HOST POOL by name, comma-separated (a trailing '*'