gpt-oss is pretrained with a 4,096-token context and served at 131,072 tokens. It gets there with YaRN, which rescales RoPE's rotation frequencies per dimension pair. Implement the computation as gpt-oss does it.
yarn_rope_params(head_dim, base, factor, initial_context_length, ntk_alpha=1.0, ntk_beta=32.0) returns (concentration, inv_freq) where inv_freq has length D=head_dim/2:
- The plain RoPE frequencies are θi=base−2i/head_dim for i=0,…,D−1.
- If
factor ≤1, return (1.0, theta).
- Otherwise compute the two boundaries
low=lnbaseDln(L0/(2πβ)),high=lnbaseDln(L0/(2πα)),
with L0 =
initial_context_length, β = ntk_beta, α = ntk_alpha.
- The ramp is ri=clip((i−low)/(high−low),0,1). Each frequency blends the unchanged value with the interpolated one:
inv_freqi=(1−ri)θi+rifactorθi.
concentration =0.1ln(factor)+1.
Return inv_freq as a float64 numpy array and concentration as a float.