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 automatic rope factor derives from the context actually served
Jakub Luwierski79926c0d3f0d
diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex af63b963d..7f5a8184b 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -436,10 +436,13 @@ the attention temperature where training put it. Scaled contexts also need propofor 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 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.+ question when run interactively) and derives the factor from the final context for you (final context /+ 262,144, at least 1: 1.5 at 393K, 2 at 512K, 1 inside the trained range; `--rope-scaling`/`--rope-scale`+ override, an explicit factor is kept as given). 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, an omitted method adds no+ scaling, and an explicitly chosen one stays at factor 1 - the trained angles, no expansion (not a+ switch for rope as a whole: explicitly supplied rope settings keep their behavior).- 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 adiff --git a/setup.py b/setup.pyindex d218ee122..0293d6b20 100644--- a/setup.py+++ b/setup.py@@ -20,8 +20,9 @@ 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 modelOptions: --family qwen|swift, --model Q2_0|IQ2_XS|IQ3_XXS|IQ3_S, --context 32768, --rope-scaling none|linear|yarn-(--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+(--rope-scale F; past the trained 262144 the setup adds yarn and the factor is the final context over 262144,+at least 1 - an explicit --rope-scaling none is refused for such a context), --vision yes|no|gpu|cpu, --port+8080, --yes (recommendedanswers, 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),@@ -80,9 +81,10 @@ MODELS = {"ram_gb": 32, "arena_gb": 23.4, "families": ("coder",)},}# 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.+# serve the setup resolves the method (yarn, or one question when interactive) and derives the factor+# from the final context (final / 262144, at least 1) 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 = {@@ -1589,24 +1591,26 @@ def write_run_script(model, cfg_path, port):# ------------------------------------------------------------------------------------------------ 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."""- for f in (1.5, 2.0, 3.0, 4.0):- if trained * f >= ctx:- return f- raise ValueError(f"a {ctx} token context is {ctx / trained:.1f}x the trained 262144 - past anything this "- "setup picks a factor for: pass --rope-scale explicitly if you know what you are asking for")+def derived_factor(ctx: int, trained: int = 262144) -> float:+ """The automatic extension factor: the FINAL context over the trained one, at least 1.++ Factor 1 removes the automatic expansion - the trained angles stand as they are - but it is not a+ switch for rope as a whole: an explicitly chosen method's settings keep their defined behavior.+ """+ return max(1.0, float(ctx) / float(trained))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.+ An explicit --rope-scaling/--rope-scale always wins - a user-supplied factor is kept verbatim even+ when a reduction changed the context. 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 is derived from the+ final context (final / trained, at least 1), as is an explicitly chosen method's missing factor+ inside the trained range: factor 1, the trained angles, no expansion. 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"):@@ -1614,13 +1618,13 @@ def resolve_rope(ctx: int, scaling, scale, trained: int = 262144):"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+ return scaling, scale if scale is not None else derived_factor(ctx, trained)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)+ return scaling or "yarn", scale if scale is not None else derived_factor(ctx, trained)# ------------------------------------------------------------------------------------------------ main@@ -1634,8 +1638,8 @@ def main() -> int:"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)")+ help="the extension factor (default: the final context over the trained 262144, at least 1 - "+ "1.5 for 384K, 2 for 512K, 1 inside the trained range)")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)")@@ -1928,8 +1932,9 @@ def main() -> int: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"))+ origin = ("final context / trained 262144; override with --rope-scale" if a.rope_scale is None+ else "as requested")+ ok(f"rope scaling: {scaling}, factor {rope_scale:g} ({origin})")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:diff --git a/tools/test_setup_rope.py b/tools/test_setup_rope.pyindex c81c3fddc..8e90f5287 100644--- a/tools/test_setup_rope.py+++ b/tools/test_setup_rope.py@@ -1,6 +1,7 @@-"""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.+"""Tests for setup.py's automatic rope configuration (§4 + §6): the factor derives from the FINAL context+actually served - RAM reductions first, then final / trained 262144 clamped at 1 - explicit+--rope-scaling/--rope-scale choices win verbatim, an explicit none is refused past the trained range, and+nothing turns on by itself inside it. Pure functions - no GPU, no downloads, no prompts.python -m unittest tools.test_setup_rope"""@@ -15,30 +16,30 @@ 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+class DerivedFactor(unittest.TestCase):+ """The formula itself: max(1.0, final / trained)."""- 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+ def test_the_task_table(self):+ self.assertEqual(setup.derived_factor(131072), 1.0) # below the trained range: clamped at 1+ self.assertEqual(setup.derived_factor(262144), 1.0) # exactly the trained range: 1+ self.assertEqual(setup.derived_factor(393216), 1.5) # 384K+ self.assertEqual(setup.derived_factor(524288), 2.0) # 512K- def test_a_free_form_context_past_the_menu_gets_the_next_factor(self):- self.assertEqual(setup.covering_factor(600000), 3.0) # --context is not limited to the menu+ def test_free_form_contexts_get_the_exact_ratio(self):+ # /262144 = /2**18 is exact in binary floating point, so no dust+ self.assertEqual(setup.derived_factor(600000), 600000 / 262144)+ self.assertGreater(setup.derived_factor(600000), 2.0)- def test_a_context_past_the_whole_ladder_is_a_clean_refusal(self):- with self.assertRaises(ValueError) as cm:- setup.covering_factor(1048577) # 262144 * 4 is the last rung- self.assertIn("--rope-scale", str(cm.exception))+ def test_the_clamp_is_what_keeps_128k_at_one(self):+ self.assertEqual(setup.derived_factor(131072), 1.0) # NOT the raw 0.5class 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):+ def test_omitted_384k_gets_yarn_and_1_5(self):self.assertEqual(setup.resolve_rope(393216, None, None), ("yarn", 1.5))- def test_omitted_512k_gets_yarn_and_the_covering_factor(self):+ def test_omitted_512k_gets_yarn_and_2(self):self.assertEqual(setup.resolve_rope(524288, None, None), ("yarn", 2.0))def test_deterministic_for_yes(self):@@ -50,14 +51,19 @@ class ResolveRope(unittest.TestCase):# --rope-scale alone still expresses the intent to extend: the method defaults, the factor is keptself.assertEqual(setup.resolve_rope(393216, None, 1.8), ("yarn", 1.8))- # ---- explicit selections are respected- def test_explicit_method_gets_the_covering_factor(self):+ # ---- explicit selections are respected, verbatim+ def test_explicit_method_gets_the_derived_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))+ def test_an_explicit_override_survives_a_context_reduction(self):+ # §4: the RAM check reduced the final context to 128K - a user-supplied factor is NOT recalculated+ self.assertEqual(setup.resolve_rope(131072, "yarn", 2.0), ("yarn", 2.0))+ self.assertEqual(setup.resolve_rope(131072, "linear", 1.75), ("linear", 1.75))+# ---- an explicit none past the trained range is refused with an explanation, not overriddendef test_explicit_none_past_trained_is_refused(self):with self.assertRaises(ValueError) as cm:@@ -68,7 +74,7 @@ class ResolveRope(unittest.TestCase):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+ # ---- inside the trained range nothing turns on by itself; a chosen method gets factor 1def 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))@@ -77,15 +83,20 @@ class ResolveRope(unittest.TestCase):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))+ def test_a_chosen_method_within_trained_gets_factor_1(self):+ # no more unconditional factor 2: 1 = the trained angles, no automatic expansion+ self.assertEqual(setup.resolve_rope(131072, "yarn", None), ("yarn", 1.0))+ self.assertEqual(setup.resolve_rope(262144, "linear", None), ("linear", 1.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))+ # ---- §4 coordination: the RAM reduction lands BEFORE the rope config, so the factor matches the+ # context actually served - the 512K-on-IQ3_S-with-under-90-GB case from the task, end to end+ def test_512k_on_a_small_ram_machine_resolves_to_128k_factor_1(self):+ # asked 524288 with --rope-scaling yarn and no factor; the RAM check brings the final context to 131072+ self.assertEqual(setup.resolve_rope(131072, "yarn", None), ("yarn", 1.0))++ def test_no_reduction_384k_and_512k_resolve_as_documented(self):+ self.assertEqual(setup.resolve_rope(393216, "yarn", None), ("yarn", 1.5))+ self.assertEqual(setup.resolve_rope(524288, "yarn", None), ("yarn", 2.0))if __name__ == "__main__":