induwara.lk
induwara.lkAI · LLM context

RoPE Scaling Calculator — Extend LLM Context Length

Enter a model's trained context, head dimension and rope_theta, plus the longer context you want. Get the exact Linear, NTK-aware, Dynamic NTK and YaRN scaling parameters — with copy-ready Hugging Face configs. Runs fully in your browser, no signup.

By Induwara AshinsanaUpdated Jul 10, 2026
RoPE context extensionconfig generator
RoFormer · PI · NTK · YaRN
Model presets
tokens

What the model was trained on — its max_position_embeddings.

tokens

The longer context you want the model to handle.

hidden_size ÷ num_attention_heads. Usually 64 or 128.

From config.json. 10000 for Llama 2, 500000 for Llama 3.

Extension factor s
16,384 ÷ 4,096
NTK-aware rope_theta
40,890
θ × s^(d/(d−2)) — cross-check 40,890
YaRN attn temperature m
1.14
0.1·ln(s) + 1 — multiplies logits

Medium extension — prefer YaRN

Beyond 2×, plain interpolation degrades. YaRN keeps quality best at this range; a short fine-tune (a few hundred steps on long samples) sharpens it further. Dynamic NTK is a reasonable no-training fallback.

Ready-to-paste config per method

Linear Position Interpolation

Divides every position index by s before RoPE. Simple, but almost always needs fine-tuning at s ≥ 2.

Chen et al., 2023
{
  "rope_scaling": {
    "type": "linear",
    "factor": 4
  }
}

NTK-aware scaling (static)

Rescales the base so short-range dims are barely touched. Set rope_theta to the value below — no rope_scaling block needed.

bloc97 / kaiokendev
{
  "rope_theta": 40890
}

Dynamic NTK

Same base math, but applied progressively as the sequence grows past L_train, so short prompts are undisturbed.

bloc97 / kaiokendev
{
  "rope_scaling": {
    "type": "dynamic",
    "factor": 4
  }
}

YaRN

NTK-by-parts plus an attention-softmax temperature. Best quality at large s; still gains from a short fine-tune.

Peng et al., 2023
{
  "rope_scaling": {
    "type": "yarn",
    "factor": 4,
    "original_max_position_embeddings": 4096
  }
}

How this was computed

s = L_target / L_train = 16,384 / 4,096 = 4
d/(d−2) = 128/126 = 1.02
θ′ = θ · s^(d/(d−2)) = 10,000 · 4^1.02 = 10,000 · 4.09 = 40,889.94 40,890
YaRN m = 0.1·ln(s) + 1 = 0.1·ln(4) + 1 = 1.14

Linear PI uses factor = s. Dynamic NTK uses the same θ′ but applies it progressively at inference. These are configuration values only — extending far beyond the trained length still typically needs a short fine-tune.

Formulas from the RoPE, Position Interpolation, NTK and YaRN papers.

How it works

Rotary Position Embedding (RoPE) encodes token position by rotating each query/key pair at a per-dimension frequency θ_i = θ^(−2i/d) for i = 0 … d/2−1, where θ is the base (rope_theta) and d is the head dimension (Su et al., 2021). A model only learns rotation angles up to the positions it saw in training. To read longer sequences you keep those long-position angles inside the trained range by rescaling RoPE.

The extension factor is the whole story's starting point: s = L_target / L_train. The four methods differ in how they apply it:

  1. Linear Position Interpolation. Divide every position index by s before applying RoPE, so position L_target lands on the angle of L_train. Config {"type":"linear","factor":s}. It stretches all frequencies equally, blurring short-range detail, so it almost always needs fine-tuning at s ≥ 2 (Chen et al., 2023).
  2. NTK-aware scaling. Instead of scaling positions, scale the base so high-frequency (short-range) dimensions are barely touched while low-frequency (long-range) dimensions interpolate: θ′ = θ · s^(d/(d−2)). Set the model's rope_theta to θ′. This often gives usable zero-shot extension up to ~2× (bloc97 / kaiokendev).
  3. Dynamic NTK.The same θ′ formula, but the scale is recomputed as the sequence grows past L_train, so short prompts run at the original base and are not degraded. Config {"type":"dynamic","factor":s}.
  4. YaRN. NTK-by-parts — interpolate low-frequency dimensions, extrapolate high-frequency ones, with boundary wavelengths set by α=1, β=32 for Llama-class models — plus an attention-softmax temperature. The recommended temperature satisfies √(1/t) = 0.1·ln(s) + 1, i.e. logits are multiplied by m = 0.1·ln(s) + 1. Config {"type":"yarn","factor":s,"original_max_position_embeddings":L_train}. It holds quality best at large s (Peng et al., 2023).

Every output is a deterministic function of the four inputs — no data source drift, no network call. As a self-check, the NTK-aware base is derived a second way: requiring the lowest-frequency dimension pair (i = d/2−1) to have its wavelength stretched by exactly s and solving for the new base gives the same θ′ to the integer. The accepted Hugging Face rope_scaling types are linear, dynamic and yarn; static NTK is applied by overwriting rope_theta directly.

Worked examples

Llama 2 7B — 4k → 16k (d = 128, θ = 10000)

  1. s = 16384 / 4096 = 4
  2. d/(d−2) = 128/126 = 1.015873
  3. NTK: θ' = 10000 · 4^1.015873 = 10000 · 4.088994 = 40,890
  4. → set rope_theta = 40890, or use {"type":"linear","factor":4}
  5. YaRN: m = 0.1·ln(4) + 1 = 1.138629, factor 4, original_max_position_embeddings 4096

Llama 3 8B — 8k → 32k (d = 128, θ = 500000)

  1. s = 32768 / 8192 = 4 (same s and d as above)
  2. NTK multiplier is identical: 4.088994
  3. θ' = 500000 · 4.088994 = 2,044,497 → rope_theta = 2044497
  4. YaRN m = 1.138629 (m depends only on s, so it matches the 4k→16k case)
  5. Teaching point: the multiplier is fixed by s and d; θ' scales with the model's own base.

Edge case — 4k → 1M (256×, d = 128, θ = 10000)

  1. s = 1048576 / 4096 = 256
  2. NTK: θ' = 10000 · 256^1.015873 = 10000 · 279.554184 = 2,795,542
  3. YaRN m = 0.1·ln(256) + 1 = 1.554518
  4. Verdict: a 256× jump — YaRN plus fine-tuning strongly advised.
  5. The zero-shot config is a smoke test here, not a finished long-context model.

Frequently asked questions

Sources & references

The RoPE, Position Interpolation, NTK and YaRN formulas were last cross-checked against the arXiv sources above on 2026-07-10. The NTK-aware base is computed in double precision and verified a second way from the lowest-frequency wavelength, so both derivations agree to the integer.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.