Native head: opt-in STRATA_EMBED_VRAM=1 keeps the token-embedding table in VRAM (#3779, #3712)

Problem: the token-embedding table of a native pack lives in mapped pinned host
memory, so every prompt's scattered row gather crosses the PCIe link. On a Gen2
x4 link that costs more than the table's size in VRAM is worth.

Change, opt-in: with STRATA_EMBED_VRAM=1 the table is copied into the current
device's VRAM when the table plus 512 MiB stay free (322 MiB for an IQ4_XS
table). The gather kernels read the same bytes through dev_ as before. If the
VRAM is not there or the copy fails, the table stays in mapped host memory as
before and one line says so. The start-up line now says where the table is
("in VRAM" also for the two existing VRAM fallbacks, which it called mapped
host memory).

With the variable unset nothing changes (one getenv at load).

Not covered: a layer split across several devices places the table on the
device that is current when it loads, as the existing VRAM fallback does. No
unit test (it moves the same bytes to a different memory; the gather kernel is
unchanged).

Reporter's numbers (linxuhao, CMP 170HX): measured together with
STRATA_PLE_COPY_STREAM and STRATA_DEQUANT_SIDE on a 51.8K-token prompt, the
embedding step went from 191-201 to 70 ms. Theirs, not measured here.

Original change by linxuhao (PR #3779, commit 952dd784).
This commit is contained in:
linxuhao authored and Niko1221 committed 2026-10-26 20:41:23 +01:00
1 parent d6428bf291
commit 884e37dfdf
3 files changed
+37 -3

No files matched your search

+4 -2
View File
@@ -3848,9 +3848,11 @@ int main(int argc, char** argv) {
}
strata::core::set_native_embed(&native_embed);
std::fprintf(stderr, "strata generate: native pack: %s experts (largest blob %.2f MB), token embedding "
"%s in mapped host memory (%.0f MiB, %.1f s)\n",
"%s %s (%.0f MiB, %.1f s)\n",
o.pack.c_str(), (double) strata::kernels::cpu::expert_layout().max_blob / 1e6,
strata::ggml_type_name((uint32_t) native_embed.type()), (double) native_embed.bytes() / 1048576.0,
strata::ggml_type_name((uint32_t) native_embed.type()),
native_embed.in_vram() ? "in VRAM" : "in mapped host memory",
(double) native_embed.bytes() / 1048576.0,
std::chrono::duration<double>(std::chrono::steady_clock::now() - embed_t0).count());
}
// Plan v0.3 P1: tensors served in native form are not also loaded in canonical form (~2.7 GB of VRAM back