mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2961] [CLOSED] rope: --rope-scaling dynamic (opt-in): yarn by the dialog's length past the trained context; cached keys rotated when the factor changes #4361
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4361
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2961
Author: @sergqwer
Created: 10/17/2026
Status: ❌ Closed
Base:
main← Head:pr/rope-dynamic📝 Commits (1)
6dd7475rope: --rope-scaling dynamic (opt-in): yarn by the dialog's length past the trained context; cached keys rotated when the factor changes📊 Changes
13 files changed (+985 additions, -12 deletions)
View changed files
📝
CMakeLists.txt(+8 -1)📝
docs/DETAILS.md(+12 -0)📝
include/strata/core/conversation_cache.hpp(+3 -0)➕
include/strata/core/rope_dynamic.hpp(+47 -0)📝
include/strata/kernels/mrope.hpp(+4 -0)➕
include/strata/kernels/rope_dynamic.hpp(+48 -0)📝
src/core/conversation_file.cpp(+10 -3)📝
src/core/conversation_file_test.cpp(+15 -0)➕
src/core/rope_dynamic.cpp(+88 -0)📝
src/kernels/cuda/native_rope.cu(+5 -2)➕
src/kernels/cuda/rope_dynamic.cu(+242 -0)➕
src/kernels/rope_dynamic_parity.cpp(+333 -0)📝
src/program/generate.cpp(+170 -6)📄 Description
Static yarn, which setup writes for a context past 262,144, changes every dialog, the short ones too: at factor 2 the first-token distribution of a dialog inside the trained range moves by KL 0.056, and the top-1 token differs in 9.2% of positions (measured on our fork, below).
--rope-scaling dynamickeeps such a dialog on the trained angles and turns yarn on only for the dialog that passes 262,144.What it does
--rope-dynamic-step(0.125) and capped at--rope-scale(default--max-context/ 262,144, so 2 at 524,288). It is chosen per request from the prompt's length, and again in decode when the reply grows past the table's positions.src/kernels/cuda/rope_dynamic.cu) applies this to everything the session holds: K (int8 or fp16, with or withoutSTRATA_KV_ROT's Hadamard: dequantize, H, turn the 32 rotary pairs, H, requantize), the indexer's pooled keys, its spare row anddead, the checkpoints'dead, and the drafter's K. With--kv-residentthe pinned host copy is turned and the VRAM slots are fetched again.STRATA_ROPE_DYNAMIC_REREAD=1reads the prompt again instead.build_rope_table), so the captured CUDA graphs keep their pointer and read the new angles. That needs #280's table on the analytic paths too (--native-rope, the native indexer, the prompt path): their constants are baked into the graphs at capture. So dynamic turns the table on, asSTRATA_ROPE_TABLE=1does (rope_table_force_on()).conversation_file_test's golden file passes unchanged). A restored image is turned to the next request's factor. The session config fingerprint takes the yarn template and arope_dynamicswitch.--batchslots, a layer split and--kv q4_0/k8v4. The engine refuses them at start and names static yarn as the alternative. One-shot (non-serve) runs pick one factor for prompt +--max-new.Default behaviour
Without the flag nothing changes. With it, a dialog below 262,144 runs the bits of
STRATA_ROPE_TABLE=1with no scaling. These are not the bits of the default run: there the angles come from fast-mathcosf/sinf(#280), and on long_32k the two differ by KL 0.047 with the same greedy tokens.Measured on this branch
RTX 5090 (Windows 11, CUDA 13.3, driver 617.14), 9950X3D, 128 GB. upstream/main
477ac13cand this branch, the same release configure. The NVFP4 GPTQ pack (Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata, upstream setup's--family nvfp4 --model NVFP4).Identity.
--exact --cache 3000, the p2k and long_32k prompts, first-token logits (sha256) and 32 greedy tokens:1e9c612c...f5b2872c...1e9c612c...identicalf5b2872c...identicalSTRATA_ROPE_TABLE=167da66a7...a9cf6bf8...--rope-scaling dynamic --max-context 52428867da66a7...identicala9cf6bf8...identicalA switch in decode, at small scale. The run uses
--rope-scaling dynamic --yarn-orig-ctx 8100and the 8,035-token long_8k prompt, so the reply passes the "trained" 8,100 positions:STRATA_ROPE_TABLE=1.rope dynamic: factor 1 -> 1.125 (decode): 8098 cells re-rotated in 0.4 ms, table 18.4 ms. The table covers the 262,144 cells of--max-context.The rotation against writing at the new factor (
rope_dynamic_parity, new ctest, GPU, synthetic). Random keys at positions 0 to 519,999 (48 pages at the real page size, both sides of 262,144 among them) are rotated on the host by A and by B as the table path does. The engine's own append kernels write them:kv_append_step(fp16),kv_append_q8_step(int8), and int8 throughfwht256first. A's pool is then turned to B and compared with the float64 key at B. The error of the key written directly at B is the yardstick:deadare exactly mscale_B / mscale_A times their old values.build_rope_table_mtequalsbuild_rope_tablebitwise (factors 1, 1.125 and 2; 1, 7 and 16 threads). So a dialog that goes back below 262,144 gets the startup table.Measured earlier on our fork
The same change on our fork's 0.1.44 code (sergqwer/strata-nvfp4), RTX 5090, the same pack,
--kv int8. I did not repeat these on upstream's code: each band run reads 13 bands up to 516K, about 72 s per run.Teacher-forced NLL on a corpus of C++ sources read once in order. At 13 band starts from 8K to 516K the next 1,024 tokens are scored. Paired per-token differences vs
none, pooled over the 7 bands past 262,144 (7,168 tokens), with the SE in brackets:--kv-resident 32768--kv-resident: 354-677 ms (the host copy over PCIe). There are at most 8 switches between 262K and 512K, each paid once per dialog. Prompt time was unchanged within noise: 72.4-72.6 s for the 13 band reads, vs 72.1-77.5 s for none and static yarn.nonealso finds 13/13 there, so this test does not separate the arms.The gain is small: about 1% perplexity past 262,144, 2.4 SE on one corpus. The case for dynamic is yarn's gain past the trained context without yarn's cost on every short dialog.
How to reproduce
--family nvfp4 --model NVFP4.strata --servewith setup's model files and--expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000, envSTRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<dir>/first. It sends two requests (a 2,100-token and a 32,037-token prompt, 32 greedy tokens each) and compares the logits dumps and the tokens.--max-context 524288 --rope-scaling dynamicfor this branch.STRATA_ROPE_TABLE=1for upstream/main.--max-context 524288 --rope-scaling dynamicin place of--rope-scaling yarn --rope-scale 2.ctest -R rope_dynamic_parityon a CUDA build with tests.Not measured
--batch: refused.Setup and the Model settings page do not offer
dynamicyet. If this is wanted, I would send that as a follow-up: setup would write dynamic instead of static yarn past 262,144 where it runs (one GPU, no--batch,--kv int8orfp16).🤖 Generated with Claude Code
https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.