From c2beb7106e0bc164601a5392878eecbe37010454 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Fri, 2 Oct 2026 22:53:55 +0200 Subject: [PATCH] #496: the engine chooses a small card's reserve; setup only gives the tip Setup no longer writes a fixed 300 MiB reserve for cards under 8 GB: the engine's own rule (lower the reserve only as far as the smallest working cache needs, down to 300) chooses better, and a fixed 300 left an emulated small card with 5 MiB free. Setup keeps the tip (an 8K context, --draft-vocab en). When the engine lowered the reserve and the card ends below the 256 MiB LOW line, it prints one warning (requests may stall; close other programs that use the GPU, or lower --max-context) instead of advising a larger reserve, which would leave the cache no room. --- docs/INSTALL.md | 7 ++++--- setup.py | 30 +++++++++--------------------- src/program/generate.cpp | 21 +++++++++++++++------ tools/test_setup_choices.py | 25 ++++++++----------------- 4 files changed, 36 insertions(+), 47 deletions(-) diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 5e051451..735a10c6 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -201,9 +201,10 @@ By hand: add `"--vram-reserve-mib", "2048"` to the config's `"args"` list and re much smaller, so answers can be a little slower. The engine sizes its cache from the VRAM free when it starts: what another program already holds then is left alone anyway; the reserve is room for what it takes later. -**A card under 8 GB (#496):** setup writes a 300 MiB reserve there, and the engine itself tries 300 when the default -leaves the expert cache no slot. If the start still stops with "no VRAM is left for the expert cache", that log line -says how much is short; an 8K context and `--draft-vocab en` at setup free the most. +**A card under 8 GB (#496):** when the default reserve leaves the expert cache too little room, the engine lowers the +reserve (down to 300 MiB) until it fits, and warns if the card then ends nearly full. If the start stops with "no VRAM +is left for the expert cache", that log line says how much is short; an 8K context and `--draft-vocab en` at setup +free the most. **Model files downloaded by hand, or from a mirror (#495):** setup's step 5 prints the folder it expects them in (`Strata-data\models\\`, e.g. `Strata-data\models\IQ3_XXS\`): put them there with their original names, or diff --git a/setup.py b/setup.py index 8075f498..973a2b12 100644 --- a/setup.py +++ b/setup.py @@ -2416,10 +2416,8 @@ def choices_from_config(cfg_path: Path) -> dict: "host": cfg.get("host"), "api_key": cfg.get("api_key"), "port": cfg.get("port"), "gpu": cfg.get("gpu"), "layer_split": cfg.get("layer_split"), # #493: --vram-reserve-mib given at setup (images write the default 700 themselves) - # (#496: not the small card's reserve setup chose itself) "vram_reserve_mib": int(val("--vram-reserve-mib")) if (val("--vram-reserve-mib") or "").isdigit() and ( - vis is None or int(val("--vram-reserve-mib")) != VISION["gpu"]["reserve_mib"]) and - not cfg.get("vram_reserve_auto") else None} + vis is None or int(val("--vram-reserve-mib")) != VISION["gpu"]["reserve_mib"]) else None} def find_in(roots: list, rel: str): @@ -2726,13 +2724,13 @@ def draft_vocab_note(vram_gb: float, chosen: str | None) -> list[str]: " fix when the start stops with \"the draft head does not fit\". The model keeps the choice."] -SMALL_CARD_GB = 7.5 # #496: a card under 8 GB gets a smaller VRAM reserve (an 8 GB card lists 7.99) -SMALL_CARD_RESERVE_MIB = 300 +SMALL_CARD_GB = 7.5 # #496: a card under 8 GB gets a tip (an 8 GB card lists 7.99) def small_card_note(ctx: int, draft_vocab: str | None) -> list[str]: - """#496: what frees VRAM on a card under 8 GB when the start still stops with "no VRAM is left for the expert - cache" - a recommendation, setup changes none of it. (The draft layer stays: the server needs it.)""" + """#496: what frees VRAM on a card under 8 GB when the start stops with "no VRAM is left for the expert cache" + (the engine already lowers its own reserve on such a card) - a recommendation, setup changes none of it. (The + draft layer stays: the server needs it.)""" start = "START-HERE.bat --setup" if WIN else "./setup.sh" tips = [] if ctx > 8192: @@ -3553,18 +3551,10 @@ def main() -> int: args += ["--vram-reserve-mib", str(a.vram_reserve_mib)] ok(f"VRAM kept free for other programs: {a.vram_reserve_mib} MiB (--vram-reserve-mib; the expert cache takes " "that much less)") - small_reserve = (a.vram_reserve_mib is None and not multi and vision != "gpu" and - 0 < gpu.get("vram_gb", 0.0) < SMALL_CARD_GB) - if small_reserve: - # #496: on a 6 GB card the engine's default 700 MiB reserve (plus the draft head) took all that the weights, - # the KV cache and the draft layer left, and the expert cache got no slot. A card under 8 GB gets 300 MiB. - if "--vram-reserve-mib" in args: - args[args.index("--vram-reserve-mib") + 1] = str(SMALL_CARD_RESERVE_MIB) - else: - args += ["--vram-reserve-mib", str(SMALL_CARD_RESERVE_MIB)] - ok(f"a {gpu['vram_gb']:.0f} GB card: {SMALL_CARD_RESERVE_MIB} MiB of VRAM kept free instead of 700, so the " - "expert cache gets the rest (--vram-reserve-mib N changes it)") - for line in small_card_note(ctx, draft_vocab): # a recommendation: nothing else changes + if not multi and 0 < gpu.get("vram_gb", 0.0) < SMALL_CARD_GB: + # #496: on a 6 GB card the expert cache can get no room at all; the engine lowers its own reserve when that + # is what it takes, and says what is short when even that is not enough. Setup only says what helps. + for line in small_card_note(ctx, draft_vocab): # a recommendation: nothing changes say(" " + line) if esp is not None: # the package's profile, with llama.cpp's flags (the engine takes the same ones) @@ -3573,8 +3563,6 @@ def main() -> int: cfg = {"exe": str(eng / EXE), "args": args, "cwd": str(ROOT), "tokenizer": str(pack / "tokenizer"), "model_name": f"{fam['name']}-{model.lower()}", "log": str(ROOT / f"strata-{tag.lower()}.log"), "lib_dirs": lib_dirs, "port": port} - if small_reserve: # #496: setup's own choice - a later setup decides again instead of keeping it as the user's - cfg["vram_reserve_auto"] = True if hip: cfg["backend"] = "hip" # the dense prompt GEMMs through hipBLASLt with kernels measured on this GPU generation (tools/hip; +40-60% diff --git a/src/program/generate.cpp b/src/program/generate.cpp index d1d36cad..5af3d4a9 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -2811,6 +2811,7 @@ int main(int argc, char** argv) { return 1; } const bool auto_cache = o.expert_cache < 0; + bool reserve_adapted = false; // #496: the auto sizing lowered the reserve so a small card's cache fits if (o.expert_cache < 0) { size_t free_b = 0, total_b = 0; cudaMemGetInfo(&free_b, &total_b); @@ -2834,12 +2835,13 @@ int main(int argc, char** argv) { // #496: the verify window cannot start without a cache (#174), and a cache too small to lend the prompt path // a 256-token chunk's buffers (plus the 128 slots a loan leaves; one slot without --prefill) makes it // allocate its own on top - more than the reserve. When the default reserve leaves less than that (a 6 GB - // card), the reserve shrinks to what leaves exactly that cache, down to kSmallReserveMib (what setup writes for - // cards under 8 GB): what is allocated after the cache - the prompt path's own part, the verify buffers, the - // draft head - comes out of the reserve, and below ~550 MiB a card ends with less than the 256 MiB the serve - // check calls LOW (IQ3_XXS, 32K, a 300 MiB reserve: 5 MiB left), so the cache gets no more than it needs. A - // reserve given on the command line is kept. No slot at all: the start stops, saying what is short and what - // makes room. A card the default reserve leaves that much is sized as before. + // card), the reserve shrinks to what leaves exactly that cache, down to kSmallReserveMib: what is allocated + // after the cache - the prompt path's own part, the verify buffers, the draft head - comes out of the reserve, + // and below ~550 MiB a card ends with less than the 256 MiB the serve check calls LOW (IQ3_XXS, 32K, a 300 MiB + // reserve: 5 MiB left), so the cache gets no more than it needs, and the serve check says so plainly when it + // ends LOW (`reserve_adapted`). A reserve given on the command line is kept. No slot at all: the start + // stops, saying what is short and what makes room. A card the default reserve leaves that much is sized as + // before. constexpr int kSmallReserveMib = 300; const int64_t min_slots = (o.prefill_chunk > 0 && pf_borrow) ? ((int64_t) strata::prefill::Prefill::bytes_needed(g, ss, 256) + blob - 1) / blob + 128 : 1; @@ -2855,6 +2857,7 @@ int main(int argc, char** argv) { o.vram_reserve_mib, (long long) min_slots, r, (long long) s2); o.vram_reserve_mib = r; o.expert_cache = (int) s2; + reserve_adapted = true; } } if (o.expert_cache == 0) { @@ -4916,6 +4919,12 @@ int main(int argc, char** argv) { const int64_t free_mib = (int64_t) (free_b >> 20); if (free_mib >= 256) { std::fprintf(stderr, "strata serve: %lld MiB of VRAM free with everything loaded\n", (long long) free_mib); + } else if (reserve_adapted) { + // #496: the reserve was already lowered to make the cache fit - a bigger one would leave it no room + std::fprintf(stderr, "strata serve: WARNING: %lld MiB of VRAM free with everything loaded - this card " + "only just fits the model (the VRAM reserve was lowered to %d MiB so the expert " + "cache fits): requests may stall. Close other programs that use the GPU, or lower " + "--max-context\n", (long long) free_mib, o.vram_reserve_mib); } else { std::fprintf(stderr, "strata serve: %lld MiB of VRAM free with everything loaded - LOW: requests may stall;" " add --vram-reserve-mib %lld to the config's args (or lower --max-context)\n", diff --git a/tools/test_setup_choices.py b/tools/test_setup_choices.py index 41e21b71..c28127bb 100644 --- a/tools/test_setup_choices.py +++ b/tools/test_setup_choices.py @@ -330,9 +330,9 @@ class VramReserve(unittest.TestCase): self.assertTrue(call.called) -class SmallCardReserve(unittest.TestCase): - """#496: a card under 8 GB (a 6 GB laptop RTX 3060) gets a 300 MiB VRAM reserve instead of the engine's 700, and a - tip for when the start still has no room for the expert cache; an 8 GB card's config is unchanged.""" +class SmallCardTip(unittest.TestCase): + """#496: a card under 8 GB (a 6 GB laptop RTX 3060) gets a tip for when the start has no room for the expert cache; + the engine chooses its own reserve there, so the config is the one any card gets. An 8 GB card: no tip.""" def install(self, vram, *extra): from test_setup_golden import card, install @@ -342,32 +342,23 @@ class SmallCardReserve(unittest.TestCase): def test_a_6gb_card(self): code, out, cfg, _ = self.install(6.0) self.assertEqual(code, 0, out) - a = cfg["args"] - self.assertEqual(a.count("--vram-reserve-mib"), 1) - self.assertEqual(a[a.index("--vram-reserve-mib") + 1], "300") - self.assertTrue(cfg.get("vram_reserve_auto")) - self.assertIn("300 MiB of VRAM kept free instead of 700", out) + self.assertNotIn("--vram-reserve-mib", cfg["args"]) # the engine decides (no fixed reserve) self.assertIn("no VRAM is left for the expert cache", out) self.assertIn("--draft-vocab en", out) - self.assertIn("--mtp", a) # the draft layer stays: the server needs it - with tempfile.TemporaryDirectory() as d: # setup's own choice is not kept as the user's - p = Path(d) / "strata-q2_0.json" - p.write_text(json.dumps(cfg)) - self.assertIsNone(setup.choices_from_config(p)["vram_reserve_mib"]) + self.assertIn("--mtp", cfg["args"]) # the draft layer stays: the server needs it - def test_an_8gb_card_is_unchanged(self): + def test_an_8gb_card_has_no_tip(self): for vram in (8188 / 1024, 8.0): # nvidia-smi lists an 8 GB card as 8188 MiB code, out, cfg, _ = self.install(vram) self.assertEqual(code, 0, out) + self.assertNotIn("no VRAM is left for the expert cache", out) self.assertNotIn("--vram-reserve-mib", cfg["args"]) - self.assertNotIn("vram_reserve_auto", cfg) - def test_a_given_reserve_wins(self): + def test_a_given_reserve_is_kept(self): code, out, cfg, _ = self.install(6.0, "--vram-reserve-mib", "500") self.assertEqual(code, 0, out) a = cfg["args"] self.assertEqual(a[a.index("--vram-reserve-mib") + 1], "500") - self.assertNotIn("vram_reserve_auto", cfg) def test_the_tip(self): self.assertIn("an 8K context", " ".join(setup.small_card_note(32768, None)))