From bef32ed6c3ae4d92f027b5398ce9d1f53fa7d0d1 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 28 Sep 2026 12:49:25 +0200 Subject: [PATCH] engine: load every CUDA kernel at start (CUDA_MODULE_LOADING=EAGER) With lazy loading, a kernel first used mid-prompt found no VRAM left for its code once the expert cache and the prompt path had taken it: IQ3_XXS at 64K and 128K on a 12 GB card ended with 'out of memory: cudaFuncSetAttribute' in the MMQ launch. Loaded at start the kernels cost ~30 MB, accounted before the cache is sized (~23 fewer slots). A user's own CUDA_MODULE_LOADING is kept. --- src/program/generate.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index b699ee19..4b060741 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -759,6 +759,16 @@ int main(int argc, char** argv) { // pipe or a file is block-buffered, so a program that dies loses every line it had already printed - which // turns "it crashed at step 7" into "it crashed somewhere", and the difference is a debugging session. std::setvbuf(stdout, nullptr, _IONBF, 0); + // Load every CUDA kernel when the context is created, before the expert cache takes the free VRAM. With the + // default lazy loading, a kernel first used mid-prompt (MMQ for IQ3_XXS at 64K+ on a 12 GB card) found no VRAM + // left for its code and the engine ended ("out of memory: cudaFuncSetAttribute"). Costs ~30 MB of VRAM. + if (std::getenv("CUDA_MODULE_LOADING") == nullptr) { +#if defined(_WIN32) + _putenv_s("CUDA_MODULE_LOADING", "EAGER"); +#else + setenv("CUDA_MODULE_LOADING", "EAGER", 0); +#endif + } Options o; bool have_tokens = false; bool have_logits_stride = false;