[PR #84] [CLOSED] EXPERIMENTAL Rope scaling: contexts past the trained 262K (none / linear / YaRN) #2445

Closed
opened 2026-11-04 02:00:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/84
Author: @j-luwierski
Created: 9/28/2026
Status: ❌ Closed

Base: main ← Head: feat/rope-scaling


📝 Commits (10+)

  • df08bd0 kernels: rope scaling config and the scaled cos/sin table (none/linear/YaRN)
  • 18ea6a9 rope: thread scaling through the native, indexer and prefill rotation sites
  • 0bc73ea engine: --rope-scaling/--rope-scale/--yarn-* flags; rope keys as GGUF defaults
  • d814039 setup: --rope-scaling/--rope-scale; contexts past 262144 require scaling
  • 551acae docs: context extension (rope scaling)
  • 00f030c generate: an explicit --rope-scaling none or --rope-scale 1 overrides the GGUF rope keys
  • f8777f9 bench: rope-scaling needles past the trained 262K (linear 2, yarn 2)
  • 7d581d8 indexer: the batched append takes the one rope config, with a parity test
  • 193408b setup: the documented automatic rope configuration actually happens now
  • b167abd setup: a free-form --context past the menu got a raw StopIteration

📊 Changes

32 files changed (+1871 additions, -84 deletions)

View changed files

📝 README.md (+3 -1)
➕ bench/results/2026-09-28-rope-scaling/README.md (+49 -0)
➕ bench/results/2026-09-28-rope-scaling/config-A-none-262144.json (+38 -0)
➕ bench/results/2026-09-28-rope-scaling/config-B-linear2.json (+42 -0)
➕ bench/results/2026-09-28-rope-scaling/config-C-yarn2.json (+42 -0)
➕ bench/results/2026-09-28-rope-scaling/kv-sweep-tgs.json (+121 -0)
➕ bench/results/2026-09-28-rope-scaling/needle-A-none.json (+29 -0)
➕ bench/results/2026-09-28-rope-scaling/needle-B-linear2-512k.json (+11 -0)
➕ bench/results/2026-09-28-rope-scaling/needle-B-linear2.json (+16 -0)
➕ bench/results/2026-09-28-rope-scaling/needle-C-yarn2-rebased.json (+11 -0)
➕ bench/results/2026-09-28-rope-scaling/needle-C-yarn2.json (+20 -0)
📝 docs/DETAILS.md (+49 -0)
📝 include/strata/kernels/native_qsa_indexer.hpp (+6 -2)
📝 include/strata/kernels/native_rope.hpp (+11 -5)
📝 include/strata/kernels/qsa.hpp (+4 -1)
📝 include/strata/kernels/rope.hpp (+14 -0)
➕ include/strata/kernels/rope_scaling.hpp (+209 -0)
📝 include/strata/prefill/kernels.hpp (+5 -2)
📝 setup.py (+97 -8)
📝 src/core/layer.cpp (+4 -3)

...and 12 more files

📄 Description

What

--rope-scaling none|linear|yarn - llama.cpp's types and flag names - extends the context past the model's trained 262,144 positions by rescaling the rotary angles: Position Interpolation for linear, ggml's rope_yarn (the corr_dims ramp and the mscale magnitude correction) for yarn. Engine 0.1.21; setup grows --rope-scaling/--rope-scale and 383K/512K context choices that pick the factor themselves.

How it fits the engine

  • The default path needs no kernel change. Scaling is baked into the float64 host cos/sin table (build_rope_table), so rope_neox_apply and the indexer's pooled-key rotation cannot tell a scaled table from an unscaled one.
  • The analytic paths (--native-rope, the native indexer, prefill's rope) take the resolved constants (freq_scale, corr_dims, ext_factor, attn_factor) as kernel arguments. They are process constants set once before session_init, so CUDA-graph capture bakes them correctly; positions keep riding device memory (st.pos_dev).
  • One float32 helper (rope_scaled_angle), transcribed line-for-line from the vendored ggml with the MIT headers kept, serves all three analytic sites; one RopeScaling struct with a rope_scaling_set() startup setter follows the house pattern (native_rope_set_enabled, mrope_table_set).
  • Precedence: CLI over the model file's qwen4exp.rope.* keys over the struct defaults (the artifact ships no rope keys today, so that channel is a no-op for now). The scaling is fixed per process - K sits in the cache post-RoPE, so one cache must never mix two scalings; there is no per-request form.
  • rope_parity grows to 13 checks; docs (DETAILS.md) gain the "Context extension" section and a troubleshooting row.

Validation

  • Parity. none is bit-identical to the old table builder; linear(4) is bit-exact against a float64 reference and row-equal to none at p/4; YaRN against a float64 transcription of ggml's spec; structural checks a tolerance cannot fake (cos_tab[0] == mscale; first pair extrapolates, last interpolates); an observability assertion; and native-vs-table agreement on the same input - the fixture that caught a real double-mscale bug in a first draft.
  • No regression. With no scaling flags the engine produces token-identical 64-token greedy output to the plain 0.1.20 build; the full parity suite and serve.test_server stay green.
  • Recall past the trained end (tools/needle_bench.py, depth 50%, temperature 0, RTX 4070 Ti SUPER + IQ3_XXS): 8/8 probes found - baseline (none) at 1k/32k/128K, then linear 2x and yarn 2x at 262k and 512k probe lengths; the 512k probes are 527k prompt tokens, 2.01x the trained 262,144, recalled at mid-depth (a 262k yarn probe re-ran green after the rebase onto 0.1.20). The raw runs stay on the development machine, out of this tree.

Notes

  • Inside the trained range a scaled run is a slightly different model (YaRN's mscale applies at every position) - documented, with a startup warning when the context is within the trained range.
  • Pictures read the same scaled table; expected to compose, unmeasured (the recall runs are text).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/84 **Author:** [@j-luwierski](https://github.com/j-luwierski) **Created:** 9/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/rope-scaling` --- ### 📝 Commits (10+) - [`df08bd0`](https://github.com/Niko1221/Strata/commit/df08bd02d3195f902575a54a6b44052572a51ae4) kernels: rope scaling config and the scaled cos/sin table (none/linear/YaRN) - [`18ea6a9`](https://github.com/Niko1221/Strata/commit/18ea6a9056544e036135a1fcc361c6c96ddf7d24) rope: thread scaling through the native, indexer and prefill rotation sites - [`0bc73ea`](https://github.com/Niko1221/Strata/commit/0bc73eac697bfefa205cb657d3d9176bfb409efd) engine: --rope-scaling/--rope-scale/--yarn-* flags; rope keys as GGUF defaults - [`d814039`](https://github.com/Niko1221/Strata/commit/d814039c769591d6fc5e7fad45553ab6cade2d53) setup: --rope-scaling/--rope-scale; contexts past 262144 require scaling - [`551acae`](https://github.com/Niko1221/Strata/commit/551acaed16a1657059e5e06e0126f46b177ec531) docs: context extension (rope scaling) - [`00f030c`](https://github.com/Niko1221/Strata/commit/00f030cc427a527c31680a0ae1a71284de547507) generate: an explicit --rope-scaling none or --rope-scale 1 overrides the GGUF rope keys - [`f8777f9`](https://github.com/Niko1221/Strata/commit/f8777f9b3939018e8826b41de23b461f7f1cca01) bench: rope-scaling needles past the trained 262K (linear 2, yarn 2) - [`7d581d8`](https://github.com/Niko1221/Strata/commit/7d581d849ee5289d63c61e4b21e703430bd59e16) indexer: the batched append takes the one rope config, with a parity test - [`193408b`](https://github.com/Niko1221/Strata/commit/193408b19b9a19cff11251d1e7783ac7047a89ba) setup: the documented automatic rope configuration actually happens now - [`b167abd`](https://github.com/Niko1221/Strata/commit/b167abd842964ec3f31705ea9af1d5b8276c14eb) setup: a free-form --context past the menu got a raw StopIteration ### 📊 Changes **32 files changed** (+1871 additions, -84 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+3 -1) ➕ `bench/results/2026-09-28-rope-scaling/README.md` (+49 -0) ➕ `bench/results/2026-09-28-rope-scaling/config-A-none-262144.json` (+38 -0) ➕ `bench/results/2026-09-28-rope-scaling/config-B-linear2.json` (+42 -0) ➕ `bench/results/2026-09-28-rope-scaling/config-C-yarn2.json` (+42 -0) ➕ `bench/results/2026-09-28-rope-scaling/kv-sweep-tgs.json` (+121 -0) ➕ `bench/results/2026-09-28-rope-scaling/needle-A-none.json` (+29 -0) ➕ `bench/results/2026-09-28-rope-scaling/needle-B-linear2-512k.json` (+11 -0) ➕ `bench/results/2026-09-28-rope-scaling/needle-B-linear2.json` (+16 -0) ➕ `bench/results/2026-09-28-rope-scaling/needle-C-yarn2-rebased.json` (+11 -0) ➕ `bench/results/2026-09-28-rope-scaling/needle-C-yarn2.json` (+20 -0) 📝 `docs/DETAILS.md` (+49 -0) 📝 `include/strata/kernels/native_qsa_indexer.hpp` (+6 -2) 📝 `include/strata/kernels/native_rope.hpp` (+11 -5) 📝 `include/strata/kernels/qsa.hpp` (+4 -1) 📝 `include/strata/kernels/rope.hpp` (+14 -0) ➕ `include/strata/kernels/rope_scaling.hpp` (+209 -0) 📝 `include/strata/prefill/kernels.hpp` (+5 -2) 📝 `setup.py` (+97 -8) 📝 `src/core/layer.cpp` (+4 -3) _...and 12 more files_ </details> ### 📄 Description ## What `--rope-scaling none|linear|yarn` - llama.cpp's types and flag names - extends the context past the model's trained 262,144 positions by rescaling the rotary angles: Position Interpolation for `linear`, ggml's `rope_yarn` (the corr_dims ramp and the mscale magnitude correction) for `yarn`. Engine 0.1.21; setup grows `--rope-scaling`/`--rope-scale` and 383K/512K context choices that pick the factor themselves. ## How it fits the engine - **The default path needs no kernel change.** Scaling is baked into the float64 host cos/sin table (`build_rope_table`), so `rope_neox_apply` and the indexer's pooled-key rotation cannot tell a scaled table from an unscaled one. - **The analytic paths** (`--native-rope`, the native indexer, prefill's `rope`) take the resolved constants (`freq_scale`, `corr_dims`, `ext_factor`, `attn_factor`) as kernel arguments. They are process constants set once before `session_init`, so CUDA-graph capture bakes them correctly; positions keep riding device memory (`st.pos_dev`). - One float32 helper (`rope_scaled_angle`), transcribed line-for-line from the vendored ggml with the MIT headers kept, serves all three analytic sites; one `RopeScaling` struct with a `rope_scaling_set()` startup setter follows the house pattern (`native_rope_set_enabled`, `mrope_table_set`). - Precedence: CLI over the model file's `qwen4exp.rope.*` keys over the struct defaults (the artifact ships no rope keys today, so that channel is a no-op for now). The scaling is fixed per process - K sits in the cache post-RoPE, so one cache must never mix two scalings; there is no per-request form. - `rope_parity` grows to 13 checks; docs (`DETAILS.md`) gain the "Context extension" section and a troubleshooting row. ## Validation - **Parity.** `none` is bit-identical to the old table builder; linear(4) is bit-exact against a float64 reference and row-equal to `none` at p/4; YaRN against a float64 transcription of ggml's spec; structural checks a tolerance cannot fake (`cos_tab[0] == mscale`; first pair extrapolates, last interpolates); an observability assertion; and native-vs-table agreement on the same input - the fixture that caught a real double-mscale bug in a first draft. - **No regression.** With no scaling flags the engine produces token-identical 64-token greedy output to the plain 0.1.20 build; the full parity suite and `serve.test_server` stay green. - **Recall past the trained end** (`tools/needle_bench.py`, depth 50%, temperature 0, RTX 4070 Ti SUPER + IQ3_XXS): 8/8 probes found - baseline (none) at 1k/32k/128K, then linear 2x and yarn 2x at 262k and 512k probe lengths; **the 512k probes are 527k prompt tokens, 2.01x the trained 262,144, recalled at mid-depth** (a 262k yarn probe re-ran green after the rebase onto 0.1.20). The raw runs stay on the development machine, out of this tree. ## Notes - Inside the trained range a scaled run is a slightly different model (YaRN's mscale applies at every position) - documented, with a startup warning when the context is within the trained range. - Pictures read the same scaled table; expected to compose, unmeasured (the recall runs are text). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:00:11 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2445
No description provided.