[GH-ISSUE #33] RoPE scaling (YaRN) to serve beyond the native 262144, is it on the roadmap, and would the selection budget make it moot? #19

Closed
opened 2026-11-04 01:39:05 +07:00 by bsakaguchi · 8 comments
Owner

Originally created by @enkynakamura on GitHub (Sep 28, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/33

Hi and thanks for the engine it is doing 2x the decode of my llama.cpp build on the same machine (RTX 5080 16 GB + Xeon w7-2475X, IQ3_S, 4178-slot expert cache).

I run llama.cpp with --rope-scaling yarn --rope-scale 2 --yarn-orig-ctx 262144 for a 524288 window, so I went looking for the equivalent here and found qsa_freq_base() in include/strata/kernels/qsa.hpp:121:

/// rope.freq_base, no rope.scaling keys, so freq_scale = 1 and no YaRN.

Two questions, one practical and one architectural.

  1. Is rope scaling something you'd accept?

If so, the natural place looks like build_rope_table (src/kernels/cuda/rope.cu:34), which is already host float64 and feeds both rope_neox_apply and the indexer. I prototyped the change against ggml's reference (rope_yarn in ggml-cpu/ops.cpp, ggml_rope_yarn_corr_dims in ggml.c) and verified numerically outside the engine:

with freq_scale = 1 and ext_factor = 0 the table is bit-identical to the current one (max abs diff 0.0), so it is a no-op when off
with freq_scale = 0.5, orig_ctx = 262144, base = 1e7, beta_fast/slow = 32/1, it agrees with ggml's float32 reference to 3.0e-4 at position 8192 — and the unmodified table already differs from that reference by 2.8e-4 at the same position, which is your deliberate float64 choice, not the change

What I am less sure about is the other places that recompute theta from qsa_freq_base() rather than reading the table: src/prefill/kernels.cu:494, native_rope_apply (src/kernels/cuda/native_rope.cu:66), native_qsa_indexer_append (src/core/layer.cpp:873) and the verify window (src/core/verify.cpp:450,701). ALL FIVE would need the identical transform or prefill-K and decode-Q disagree silently. Would you want a shared RopeScaling struct plus one host device helper so the five sites cannot drift, or do you have a different plan for that?

  1. Would it actually buy anything?

This is the part I would rather ask than assume. qsa_selection_width (qsa.hpp:124-133) caps the selection at idx_top_k + idx_block - 1 = 2051, and kTopkMaxCells = 32768 (qsa.hpp:276-279) carries the note that Phase 3 replaces the one-block selection with a radix select and Phase 7 raises the cap.

So is the selection budget intended to grow with the context window, or is it fixed by design? If it is fixed, doubling the window doubles what the indexer cannot select, and rope scaling would be the wrong lever entirely, in which case I would rather know that than send you a pull request that makes a number bigger without making the model better.

Happy to open a pull request for the table path if the direction is right, and happy to run the parity tests on the above hardware either way.

Originally created by @enkynakamura on GitHub (Sep 28, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/33 Hi and thanks for the engine it is doing 2x the decode of my llama.cpp build on the same machine (RTX 5080 16 GB + Xeon w7-2475X, IQ3_S, 4178-slot expert cache). I run llama.cpp with --rope-scaling yarn --rope-scale 2 --yarn-orig-ctx 262144 for a 524288 window, so I went looking for the equivalent here and found qsa_freq_base() in include/strata/kernels/qsa.hpp:121: /// `rope.freq_base`, no rope.scaling keys, so freq_scale = 1 and no YaRN. Two questions, one practical and one architectural. 1. Is rope scaling something you'd accept? If so, the natural place looks like build_rope_table (src/kernels/cuda/rope.cu:34), which is already host float64 and feeds both rope_neox_apply and the indexer. I prototyped the change against ggml's reference (rope_yarn in ggml-cpu/ops.cpp, ggml_rope_yarn_corr_dims in ggml.c) and verified numerically outside the engine: with freq_scale = 1 and ext_factor = 0 the table is bit-identical to the current one (max abs diff 0.0), so it is a no-op when off with freq_scale = 0.5, orig_ctx = 262144, base = 1e7, beta_fast/slow = 32/1, it agrees with ggml's float32 reference to 3.0e-4 at position 8192 — and the unmodified table already differs from that reference by 2.8e-4 at the same position, which is your deliberate float64 choice, not the change What I am less sure about is the other places that recompute theta from qsa_freq_base() rather than reading the table: src/prefill/kernels.cu:494, native_rope_apply (src/kernels/cuda/native_rope.cu:66), native_qsa_indexer_append (src/core/layer.cpp:873) and the verify window (src/core/verify.cpp:450,701). ALL FIVE would need the identical transform or prefill-K and decode-Q disagree silently. Would you want a shared RopeScaling struct plus one __host__ __device__ helper so the five sites cannot drift, or do you have a different plan for that? 2. Would it actually buy anything? This is the part I would rather ask than assume. qsa_selection_width (qsa.hpp:124-133) caps the selection at idx_top_k + idx_block - 1 = 2051, and kTopkMaxCells = 32768 (qsa.hpp:276-279) carries the note that Phase 3 replaces the one-block selection with a radix select and Phase 7 raises the cap. So is the selection budget intended to grow with the context window, or is it fixed by design? If it is fixed, doubling the window doubles what the indexer cannot select, and rope scaling would be the wrong lever entirely, in which case I would rather know that than send you a pull request that makes a number bigger without making the model better. Happy to open a pull request for the table path if the direction is right, and happy to run the parity tests on the above hardware either way.
Author
Owner

@Niko1221 commented on GitHub (Sep 28, 2026):

Thanks for the careful write-up - and good to hear about 2x decode on the 5080.

The selection budget is fixed, by the model, not by Strata. idx_top_k = 2048 comes from the GGUF (the model was trained with a 2,048-cell sparse selection plus the unfinished block, 2,051 cells), and it is the same at 8K as at 262K: at the native window the indexer already ranks 128x more cells than it keeps. So a longer window does not make YaRN moot. The question is only whether the indexer still ranks the right blocks at stretched positions, and that is empirical. (The kTopkMaxCells = 32768 cap you found belongs to the per-cell topk_512 kernel, which only the parity test uses; the engine selects whole blocks (qsa_select), which covers the full 262K.)

Would I accept it? Yes, as an opt-in (off = bit-identical, as you measured), with:

  • one RopeScaling struct and one __host__ __device__ helper that all five sites call (the table, prefill, native_rope, the indexer append, the verify window) - you are right that any drift between prefill-K and decode-Q would fail silently, so the struct is the right shape;
  • a parity test: scaling off = the current table bit for bit; scaling on = ggml's rope_yarn within float tolerance;
  • evidence that it helps: needles past 262K (the harness is tools/needle_bench.py; 300K/400K/512K prompts would be new) and one long-document perplexity at 262K with and without it (YaRN usually costs a little inside the native window). Memory is the practical limit: the KV cache grows linearly (with 8-bit KV about 13.7 KB/token in RAM under KV streaming), and --max-context above the GGUF's context length needs to be allowed explicitly.
<!-- gh-comment-id:5867756178 --> @Niko1221 commented on GitHub (Sep 28, 2026): Thanks for the careful write-up - and good to hear about 2x decode on the 5080. **The selection budget is fixed, by the model, not by Strata.** `idx_top_k = 2048` comes from the GGUF (the model was trained with a 2,048-cell sparse selection plus the unfinished block, 2,051 cells), and it is the same at 8K as at 262K: at the native window the indexer already ranks 128x more cells than it keeps. So a longer window does not make YaRN moot. The question is only whether the indexer still ranks the right blocks at stretched positions, and that is empirical. (The `kTopkMaxCells = 32768` cap you found belongs to the per-cell `topk_512` kernel, which only the parity test uses; the engine selects whole blocks (`qsa_select`), which covers the full 262K.) **Would I accept it?** Yes, as an opt-in (off = bit-identical, as you measured), with: - one `RopeScaling` struct and one `__host__ __device__` helper that all five sites call (the table, prefill, native_rope, the indexer append, the verify window) - you are right that any drift between prefill-K and decode-Q would fail silently, so the struct is the right shape; - a parity test: scaling off = the current table bit for bit; scaling on = ggml's `rope_yarn` within float tolerance; - evidence that it helps: needles past 262K (the harness is `tools/needle_bench.py`; 300K/400K/512K prompts would be new) and one long-document perplexity at 262K with and without it (YaRN usually costs a little inside the native window). Memory is the practical limit: the KV cache grows linearly (with 8-bit KV about 13.7 KB/token in RAM under KV streaming), and `--max-context` above the GGUF's context length needs to be allowed explicitly.
Author
Owner

@enkynakamura commented on GitHub (Sep 28, 2026):

Sounds good, i will work on it and send a PR to judge.

I will write my own needle harness rather than bother you for tools/needle_bench.py, which I could not find in the repo, and I will document the methodology in the PR so you can see where it differs from the runs behind the 5/5 in bench/results/2026-09-27-kv-q4. If you would rather I reran it with yours, say the word.

This box is a 5080 16 GB, a Xeon w7-2475X with 20 physical cores (40 logical) at 4.5ghz and 128 GB of quad channel ECC RAM, so the 300K to 512K needles and the 262K perplexity pair are comfortable here rather than at the edge. Happy to run other things on it too.

<!-- gh-comment-id:5869759440 --> @enkynakamura commented on GitHub (Sep 28, 2026): Sounds good, i will work on it and send a PR to judge. I will write my own needle harness rather than bother you for tools/needle_bench.py, which I could not find in the repo, and I will document the methodology in the PR so you can see where it differs from the runs behind the 5/5 in bench/results/2026-09-27-kv-q4. If you would rather I reran it with yours, say the word. This box is a 5080 16 GB, a Xeon w7-2475X with 20 physical cores (40 logical) at 4.5ghz and 128 GB of quad channel ECC RAM, so the 300K to 512K needles and the 262K perplexity pair are comfortable here rather than at the edge. Happy to run other things on it too.
Author
Owner

@Niko1221 commented on GitHub (Sep 28, 2026):

@enkynakamura sorry, that harness was in my development tree only (and its prompts contain private notes, so they can't be published). v0.1.17 ships tools/needle_bench.py instead: it builds the long texts from the repository's own files at run time, hides a code word at the depths you choose and asks a running server (python tools/needle_bench.py --lengths 32k,128k,262k --depths 10,50,90 --url http://127.0.0.1:8080). Beyond 262K you'd need --max-context above the model's, which your YaRN change would allow - so it should work for your 300K-512K runs as is. Documenting your own method in the PR is great either way; your box sounds ideal for it.

<!-- gh-comment-id:5871078015 --> @Niko1221 commented on GitHub (Sep 28, 2026): @enkynakamura sorry, that harness was in my development tree only (and its prompts contain private notes, so they can't be published). [v0.1.17](https://github.com/Niko1221/Strata/releases/tag/v0.1.17) ships `tools/needle_bench.py` instead: it builds the long texts from the repository's own files at run time, hides a code word at the depths you choose and asks a running server (`python tools/needle_bench.py --lengths 32k,128k,262k --depths 10,50,90 --url http://127.0.0.1:8080`). Beyond 262K you'd need `--max-context` above the model's, which your YaRN change would allow - so it should work for your 300K-512K runs as is. Documenting your own method in the PR is great either way; your box sounds ideal for it.
Author
Owner

@enkynakamura commented on GitHub (Sep 28, 2026):

Perfect, tools/needle_bench.py is exactly what we needed and we are already running it. No problem about the private harness. We will document the method in the PR, and we will come back with numbers rather than questions.

<!-- gh-comment-id:5873967833 --> @enkynakamura commented on GitHub (Sep 28, 2026): Perfect, tools/needle_bench.py is exactly what we needed and we are already running it. No problem about the private harness. We will document the method in the PR, and we will come back with numbers rather than questions.
Author
Owner

@Niko1221 commented on GitHub (Sep 29, 2026):

@j-luwierski's #84 implements none/linear/YaRN scaling; let's continue there (one implementation). The open points are in its description; it also needs a perplexity check inside 262K so the default path is unchanged.

<!-- gh-comment-id:5887959550 --> @Niko1221 commented on GitHub (Sep 29, 2026): @j-luwierski's #84 implements none/linear/YaRN scaling; let's continue there (one implementation). The open points are in its description; it also needs a perplexity check inside 262K so the default path is unchanged.
Author
Owner

@j-luwierski commented on GitHub (Sep 29, 2026):

If anyone is interested in helping with the implementation, I’d be very happy to collaborate! I’d also love to hear any feedback or suggestions you might have.

<!-- gh-comment-id:5888636439 --> @j-luwierski commented on GitHub (Sep 29, 2026): If anyone is interested in helping with the implementation, I’d be very happy to collaborate! I’d also love to hear any feedback or suggestions you might have.
Author
Owner

@enkynakamura commented on GitHub (Sep 29, 2026):

If anyone is interested in helping with the implementation, I’d be very happy to collaborate! I’d also love to hear any feedback or suggestions you might have.

I'm elaborating right now a document for you about what i've done this morning and yesterday

<!-- gh-comment-id:5889810341 --> @enkynakamura commented on GitHub (Sep 29, 2026): > If anyone is interested in helping with the implementation, I’d be very happy to collaborate! I’d also love to hear any feedback or suggestions you might have. I'm elaborating right now a document for you about what i've done this morning and yesterday
Author
Owner

@Niko1221 commented on GitHub (Sep 29, 2026):

Thanks @enkynakamura. Your analysis shaped the implementation, and your review of #84 and the paired perplexity runs you posted there (the YaRN result at 293K) are exactly what it needed. Let's keep the discussion in #84, so I'm closing this one.

<!-- gh-comment-id:5898159224 --> @Niko1221 commented on GitHub (Sep 29, 2026): Thanks @enkynakamura. Your analysis shaped the implementation, and your review of #84 and the paired perplexity runs you posted there (the YaRN result at 293K) are exactly what it needed. Let's keep the discussion in #84, so I'm closing this one.
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#19
No description provided.