Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

setup: the documented automatic rope configuration actually happens now

Jakub Luwierski9b83998d9d11
diff --git a/README.md b/README.md
index d72bb816c..5df47299b 100644
--- a/README.md
+++ b/README.md
@@ -103,8 +103,8 @@ App). Everything else - Python, the engine, the model - is set up for you.
3. Answer a few questions - or just press Enter each time for the recommended choice:
- **Which model and size?** The original or Swift 1.5, and Q2_0, IQ2_XS, IQ3_XXS or IQ3_S - see [above](#which-model-should-i-pick)
- **How much context?** How much text it can keep in mind at once (it suggests one for your card). 384K and
- 512K extend the model past its trained 262K by rope scaling - the setup adds the flag itself
- ([details](docs/DETAILS.md))
+ 512K extend the model past its trained 262K by rope scaling - the setup turns it on itself (yarn and a
+ covering factor; `--rope-scaling`/`--rope-scale` override) ([details](docs/DETAILS.md))
- **Images?** Whether it should also read pictures
- **Experimental speed projection?** Off unless you say yes - [read what it does](docs/DETAILS.md#experimental-speed-projection-experimental-off-by-default) first
diff --git a/docs/DETAILS.md b/docs/DETAILS.md
index 429dbbd3a..af63b963d 100644
--- a/docs/DETAILS.md
+++ b/docs/DETAILS.md
@@ -435,9 +435,11 @@ high-frequency angles and interpolates the low-frequency ones, with the magnitud
the attention temperature where training put it. Scaled contexts also need proportionally more VRAM/RAM
for the KV cache and the rope tables (~13 KB and ~0.26 KB per token).
-- setup: `START-HERE.bat --setup --context 393216` asks nothing extra - it picks the factor for you
- (`--rope-scale` overrides; 393K wants 1.5, 524K wants 2). Contexts past 262,144 refuse to start without
- `--rope-scaling`.
+- setup: `START-HERE.bat --setup --context 393216` asks nothing extra - it picks the method (yarn; one
+ question when run interactively) and the smallest covering factor for you (`--rope-scaling`/`--rope-scale`
+ override; 393K wants 1.5, 524K wants 2). An explicit `--rope-scaling none` for a context past 262,144 is
+ refused: the setup will not configure a run with the stock angles past the trained range. If the RAM check
+ reduces a chosen 384K/512K back inside the trained range, no scaling is added at all.
- engine: `--rope-scaling none|linear|yarn`, `--rope-scale F`, and the raw ggml knobs `--rope-freq-base`,
`--rope-freq-scale`, `--yarn-orig-ctx` (default 262,144), `--yarn-ext-factor`, `--yarn-attn-factor`,
`--yarn-beta-fast` (32), `--yarn-beta-slow` (1). The model file's `rope.scaling.*` keys, when a
@@ -579,7 +581,7 @@ the document, +0.4% on the chat. Details: `bench/results/2026-09-27-esp/`.
| `the engine stopped unexpectedly (exit code ...)` | The engine process ended mid-answer - usually out of RAM (Linux ends the biggest program: `sudo dmesg \| grep -i -E 'killed process\|out of memory'`). The next request starts it again by itself. If it repeats: close other programs or pick a smaller size. The server also warns at start when the model's experts leave less than ~6 GB of RAM for everything else. |
| Slow output, disk light busy | Not enough free RAM: close other programs, or choose Q2_0 / IQ2_XS. |
| `prompt ... exceeds the context` | The request is longer than the context you chose: run setup again with a bigger `--context`. |
-| `past the model's trained 262144` (setup) / the engine refuses a context over 262,144 | A context past the trained one needs rope scaling (engine 0.1.18+): pass `--rope-scaling linear` or `yarn`, or let setup pick it (`START-HERE.bat --setup --context 393216`). |
+| `the setup refuses --rope-scaling none for a past-trained context` | A context past the trained 262,144 needs the rotary angles rescaled (engine 0.1.18+), and the setup will not configure one with the stock angles there. Let it pick (`START-HERE.bat --setup --context 393216` adds yarn and a covering factor), or pass `--rope-scaling linear` or `yarn` yourself. |
| Slower than the tables | The monitor plugged into the GPU and other GPU programs take VRAM from the expert cache; RAM running below its rated speed (enable EXPO/XMP in the BIOS) slows the CPU half. |
| `this server was started without the vision encoder` | The model was set up for text only: run setup again with `--vision gpu`. |
| A picture is refused or `cannot read the image` | The file is not a picture Pillow can open (JPEG, PNG, WebP, GIF, BMP, TIFF, AVIF work). |
diff --git a/setup.py b/setup.py
index be4e70322..bca08616e 100644
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,8 @@ What the first run does (each step is skipped when it is already done):
7. writes run-<model>.bat / run-<model>.sh and starts the model
Options: --family qwen|swift, --model Q2_0|IQ2_XS|IQ3_XXS|IQ3_S, --context 32768, --rope-scaling none|linear|yarn
-(--rope-scale F, for contexts past the trained 262144), --vision yes|no|gpu|cpu, --port 8080, --yes (recommended
+(--rope-scale F; a context past the trained 262144 gets yarn and a covering factor automatically - an explicit
+--rope-scaling none is refused for such a context), --vision yes|no|gpu|cpu, --port 8080, --yes (recommended
answers, no questions), --setup (install another model / change settings instead of starting), --no-start,
--host 0.0.0.0 --api-key KEY (reach it from other devices on your network), --experimental-speed-projection on|off
(EXPERIMENTAL, off by default),
@@ -78,8 +79,10 @@ MODELS = {
"IQ1_M": {"about": "the Coder's only size: half the experts, stored like IQ3_S (3.5 bits)", "download_gb": 58.4,
"ram_gb": 32, "arena_gb": 23.4, "families": ("coder",)},
}
-# Contexts past 262144 (the model's trained length) extend it by rope scaling - the engine refuses them
-# without --rope-scaling, and the setup adds the flag when the chosen context needs it (below).
+# Contexts past 262144 (the model's trained length) extend it by rope scaling: for the context it will
+# serve the setup resolves the method (yarn, or one question when interactive) and the smallest covering
+# factor itself (below), keeps an explicit --rope-scaling/--rope-scale, and refuses an explicit
+# --rope-scaling none there - the stock angles past the trained range are out of spec.
CONTEXTS = [8192, 32768, 65536, 131072, 262144, 393216, 524288]
# The model families: the same architecture, weights in the same three GSQ-RCO sizes, different files.
FAMILIES = {
@@ -1585,6 +1588,37 @@ def write_run_script(model, cfg_path, port):
return script
+# ------------------------------------------------------------------------------------------------ the rope config
+def covering_factor(ctx: int, trained: int = 262144) -> float:
+ """The smallest extension factor on the safe side that covers a chosen context."""
+ return next(f for f in (1.5, 2.0) if trained * f >= ctx)
+
+
+def resolve_rope(ctx: int, scaling, scale, trained: int = 262144):
+ """The rope config for the context ACTUALLY SERVED: (scaling, scale); scaling None = no scaling flags.
+
+ An explicit --rope-scaling/--rope-scale always wins. Past the trained range an omitted method
+ defaults to yarn - llama.cpp's extension method: the trained angles survive on the high-frequency
+ pairs and the magnitude correction keeps the attention temperature - and an omitted factor to the
+ smallest that covers the context. Inside the trained range nothing is added unless explicitly asked
+ for, and an explicit none is refused past the trained range (the setup will not configure a run it
+ knows is out of spec) rather than silently overridden.
+ """
+ if ctx <= trained:
+ if scale is not None and scaling in (None, "none"):
+ raise ValueError("--rope-scale needs --rope-scaling linear or yarn (the chosen context fits the "
+ "trained 262144, so there is nothing to scale)")
+ if scaling in (None, "none"):
+ return None, None # the stock model, by choice or by default
+ return scaling, scale if scale is not None else 2.0
+ if scaling == "none":
+ raise ValueError(f"a {ctx // 1024}K context is past the model's trained 262144, and --rope-scaling none "
+ "keeps the stock angles there - the model has never seen those positions, so the setup "
+ "refuses the combination instead of quietly overriding it. Pick --rope-scaling yarn or "
+ "linear, or rerun with --context 262144 or lower")
+ return scaling or "yarn", scale if scale is not None else covering_factor(ctx, trained)
+
+
# ------------------------------------------------------------------------------------------------ main
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
@@ -1592,10 +1626,12 @@ def main() -> int:
ap.add_argument("--model", choices=list(MODELS))
ap.add_argument("--context", type=int)
ap.add_argument("--rope-scaling", choices=["none", "linear", "yarn"],
- help="extend the context past the model's trained 262144: linear (position interpolation) or "
- "yarn, llama.cpp's types; required for --context 393216/524288")
- ap.add_argument("--rope-scale", type=float, help="the extension factor for --rope-scaling (default 2 when a "
- "scaled context is chosen without one)")
+ help="the RoPE extension for a context past the model's trained 262144: linear (position "
+ "interpolation) or yarn - llama.cpp's types. Omitted with a scaled context, the setup "
+ "picks yarn; 'none' is refused for such a context")
+ ap.add_argument("--rope-scale", type=float,
+ help="the extension factor (default: the smallest that covers the chosen context - 1.5 for "
+ "384K, 2 for 512K)")
ap.add_argument("--kv", choices=["int8", "q4_0", "k8v4"],
help="KV cache precision above 8K context: int8 (default), q4_0 (half the memory, a little less "
"precise) or k8v4 (hybrid: INT8 K + 4-bit V, 816 B/cell)")
@@ -1860,32 +1896,41 @@ def main() -> int:
say(" Longer needs more VRAM for it, so fewer experts fit on the GPU:")
for i, c in enumerate(CONTEXTS, 1):
note = (" (recommended for your GPU)" if c == rec_ctx else "") + \
- (" (needs rope scaling)" if c > 262144 else "")
+ (" (setup adds rope scaling)" if c > 262144 else "")
say(f" {i}) {c // 1024}K tokens{note}")
ctx = CONTEXTS[int(ask("Context?", [str(i) for i in range(1, len(CONTEXTS) + 1)],
str(CONTEXTS.index(rec_ctx) + 1), a.yes)) - 1]
- if ctx > 262144 and a.rope_scaling in (None, "none"):
- fail(f"a {ctx // 1024}K context is past the model's trained 262144: pass --rope-scaling linear or yarn "
- "(the engine scales the rotary angles; see docs/DETAILS.md)")
- rope_scale = a.rope_scale
- if ctx > 262144 and rope_scale is None:
- # the smallest factor that covers the chosen context, on the safe side
- rope_scale = 1.5 if ctx <= 393216 else 2.0
- ok(f"rope scaling: factor {rope_scale:g} (covers {ctx // 1024}K; override with --rope-scale)")
- elif rope_scale is not None and a.rope_scaling in (None, "none"):
- fail("--rope-scale needs --rope-scaling linear or yarn")
- if a.rope_scaling not in (None, "none") and rope_scale is None:
- rope_scale = 2.0
- ok("rope scaling: factor 2 (override with --rope-scale)")
- # The experts' arena plus the context's KV (in RAM from 64K up: ~13.7 KB/token at 8 bits) must fit, with room
- # for everything else. Counted, not a fixed 90 GB: 24 GB of room keeps the rule for 64 GB PCs as it was (128K
- # for both 3-bit models), while a box with ~84 GB keeps the 262K it asked for (measured: a Colab A100-40G runs
- # IQ3_S at 262K with images in 56 of its 83.5 GiB).
+ # the RAM limit comes FIRST: the rope config must cover the context the engine will actually serve -
+ # a reduced 384K can land back inside the trained 262144, and then nothing needs scaling (§4). Counted,
+ # not a fixed 90 GB (the 0.1.29 arithmetic): arena + the context's KV + 24 GB of room for everything else.
+ asked_ctx = ctx
need_gb = MODELS[model].get("arena_gb", 0) + ctx * 13 * 1056 / 1e9 + 24
if model in ("IQ3_XXS", "IQ3_S") and ram < need_gb and ctx > 131072:
warn(f"{model} with a {ctx // 1024}K context needs about {need_gb:.0f} GB of RAM "
f"({MODELS[model]['arena_gb']:.0f} GB of experts + the context + room for the rest): using 128K")
ctx = 131072
+ scaling = a.rope_scaling
+ if ctx > 262144 and scaling is None:
+ # the automatic path the docs promise: one question when interactive (yarn preselected), the
+ # silent default with --yes - llama.cpp's extension method, recall-tested here at 512K
+ say()
+ say(f" A {ctx // 1024}K context runs the model past its trained 262,144 positions: the rotary angles")
+ say(" get rescaled (llama.cpp's RoPE extension). yarn keeps the trained angles on the high-frequency")
+ say(" pairs and corrects the magnitudes; linear shrinks every angle. Override any time with")
+ say(" --rope-scaling; with --yes the setup takes yarn without asking.")
+ scaling = ask("RoPE extension method?", ["yarn", "linear"], "yarn", a.yes)
+ try:
+ scaling, rope_scale = resolve_rope(ctx, scaling, a.rope_scale)
+ except ValueError as e:
+ fail(str(e))
+ if scaling is not None:
+ ok(f"rope scaling: {scaling}, factor {rope_scale:g} (covers {ctx // 1024}K)"
+ + ("" if a.rope_scale is not None else "; override with --rope-scale"))
+ elif asked_ctx > 262144:
+ ok(f"the RAM limit brings the context to {ctx // 1024}K, inside the trained 262,144: no rope scaling")
+ if scaling is not None and asked_ctx > 262144 and ctx <= 262144:
+ warn(f"the RAM limit reduced the context to {ctx // 1024}K, inside the trained 262,144; keeping your "
+ f"explicit rope scaling ({scaling}) anyway - drop --rope-scaling for the completely stock model")
ok(f"context: {ctx} tokens")
# the KV cache (the model's memory of the conversation): 8-bit, or 4-bit after a Hadamard rotation (PR #21)
kv = "fp16" if ctx <= 8192 else (a.kv or "int8")
@@ -2050,8 +2095,8 @@ def main() -> int:
"--expert-profile", str(ROOT / "data" / fam.get("profile", "expert-profile.bin")), "--expert-cache", "auto",
"--prefill", "auto", "--spec", "4", "--spec-min-p", "0.5", "--mtp", str(rt),
"--max-context", str(ctx)]
- if a.rope_scaling not in (None, "none"):
- args += ["--rope-scaling", a.rope_scaling, "--rope-scale", f"{rope_scale:g}"]
+ if scaling is not None: # the resolved config: explicit flags as given, or the automatic yarn+factor
+ args += ["--rope-scaling", scaling, "--rope-scale", f"{rope_scale:g}"]
if ctx > 8192:
args += ["--kv", kv]
if low_ram:
diff --git a/tools/test_setup_rope.py b/tools/test_setup_rope.py
new file mode 100644
index 000000000..3d4d8b114
--- /dev/null
+++ b/tools/test_setup_rope.py
@@ -0,0 +1,84 @@
+"""Tests for setup.py's automatic rope configuration (the §6 flow): the setup resolves the method and the
+factor for a context past the trained 262144, keeps explicit choices, refuses an explicit none there, and
+adds nothing inside the trained range. Pure functions - no GPU, no downloads, no prompts.
+
+ python -m unittest tools.test_setup_rope
+"""
+from __future__ import annotations
+
+import sys
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT))
+import setup # noqa: E402
+
+
+class CoveringFactor(unittest.TestCase):
+ def test_the_menu_contexts(self):
+ self.assertEqual(setup.covering_factor(393216), 1.5) # 262144 * 1.5 covers 384K exactly
+ self.assertEqual(setup.covering_factor(524288), 2.0) # 262144 * 2.0 covers 512K exactly
+ self.assertEqual(setup.covering_factor(262144), 1.5) # the smallest on the safe side
+
+ def test_the_first_gap_takes_the_bigger_factor(self):
+ self.assertEqual(setup.covering_factor(393217), 2.0) # one token past 1.5's reach
+
+
+class ResolveRope(unittest.TestCase):
+ # ---- the automatic flow the docs promise (an omitted flag, --yes or the interactive default)
+ def test_omitted_384k_gets_yarn_and_the_covering_factor(self):
+ self.assertEqual(setup.resolve_rope(393216, None, None), ("yarn", 1.5))
+
+ def test_omitted_512k_gets_yarn_and_the_covering_factor(self):
+ self.assertEqual(setup.resolve_rope(524288, None, None), ("yarn", 2.0))
+
+ def test_deterministic_for_yes(self):
+ # --yes never prompts, so the resolution must be a pure function of its inputs
+ for _ in range(3):
+ self.assertEqual(setup.resolve_rope(524288, None, None), ("yarn", 2.0))
+
+ def test_omitted_method_with_an_explicit_factor(self):
+ # --rope-scale alone still expresses the intent to extend: the method defaults, the factor is kept
+ self.assertEqual(setup.resolve_rope(393216, None, 1.8), ("yarn", 1.8))
+
+ # ---- explicit selections are respected
+ def test_explicit_method_gets_the_covering_factor(self):
+ self.assertEqual(setup.resolve_rope(524288, "linear", None), ("linear", 2.0))
+
+ def test_explicit_method_and_factor_are_kept_verbatim(self):
+ self.assertEqual(setup.resolve_rope(393216, "linear", 2.0), ("linear", 2.0))
+ self.assertEqual(setup.resolve_rope(524288, "yarn", 1.5), ("yarn", 1.5))
+
+ # ---- an explicit none past the trained range is refused with an explanation, not overridden
+ def test_explicit_none_past_trained_is_refused(self):
+ with self.assertRaises(ValueError) as cm:
+ setup.resolve_rope(524288, "none", None)
+ self.assertIn("262144", str(cm.exception))
+ self.assertIn("yarn", str(cm.exception)) # the message names the way out
+
+ def test_explicit_none_within_trained_is_the_stock_model(self):
+ self.assertEqual(setup.resolve_rope(131072, "none", None), (None, None))
+
+ # ---- inside the trained range nothing turns on by itself
+ def test_omitted_within_trained_adds_nothing(self):
+ self.assertEqual(setup.resolve_rope(262144, None, None), (None, None))
+ self.assertEqual(setup.resolve_rope(131072, None, None), (None, None))
+
+ def test_a_scale_alone_within_trained_is_rejected(self):
+ with self.assertRaises(ValueError):
+ setup.resolve_rope(131072, None, 2.0)
+
+ def test_explicit_method_within_trained_keeps_the_engine_default_factor(self):
+ self.assertEqual(setup.resolve_rope(131072, "yarn", None), ("yarn", 2.0))
+
+ # ---- §4 coordination: the RAM reduction lands BEFORE the rope config, so a reduced 384K needs nothing
+ def test_a_reduced_context_resolves_as_the_reduced_one(self):
+ # asked 393216, the RAM check brought it to 131072: the setup must not scale a trained-range context
+ self.assertEqual(setup.resolve_rope(131072, None, None), (None, None))
+ # ...but an explicit selection survives the reduction (the engine's in-range caveat is its own)
+ self.assertEqual(setup.resolve_rope(131072, "yarn", None), ("yarn", 2.0))
+
+
+if __name__ == "__main__":
+ unittest.main()