Models / gpt-oss-20b

GPT-OSS 20B

A 21B-parameter mixture-of-experts decoder, 32 experts per layer with 4 active per token, alternating 128-position sliding-window and full causal attention with learned attention sinks, YaRN rope scaling for a 131072-token context, and expert weights read straight from the checkpoint's MXFP4 blocks and scales.

20.9B parametersgpt_ossApache-2.0text-generationdecoder-onlymixture-of-expertsgrouped-query-attentionattention-sinkssliding-window-attentionmxfp4

The forward entry with one level of blocks expanded. Every edge carries the tensor type the compiler inferred at that point, in the model's own generics.

GPT-OSS 20B: forwardGPT-OSS 20B: forward

Entries ​

EntrySignature
forwardforward<B: Dim, S: Dim>(tokens: Tensor[B, S; i32]) -> Tensor[B, S, Vocab; T]
next_tokennext_token<B: Dim, S: Dim>(tokens: Tensor[B, S; i32]) -> Tensor[B, Vocab; T]
decodedecode(token: Tensor[Batch, 1; i32], pos: i32) -> Tensor[Batch, Vocab; T]
prefillprefill<S: Dim>(tokens: Tensor[Batch, S; i32], pos: i32) -> Tensor[Batch, Vocab; T]
decode_rowsdecode_rows(tokens: Tensor[Batch, 1; i32], positions: Tensor[Batch; i32]) -> Tensor[Batch, Vocab; T]
prefill_slotsprefill_slots<M: Dim, S: Dim>(tokens: Tensor[M, S; i32], slots: Tensor[M; i32], lengths: Tensor[M; i32]) -> Tensor[M, Vocab; T]
prefill_packedprefill_packed<P: Dim>(tokens: Tensor[P; i32], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], last: Tensor[Batch; i32]) -> Tensor[Batch, Vocab; T]
step_packedstep_packed<P: Dim>(tokens: Tensor[P; i32], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], last: Tensor[Batch; i32], step_tokens: Tensor[Batch, 1; i32], step_positions: Tensor[Batch; i32]) -> Tensor[2 * Batch, Vocab; T]
statesstates<B: Dim, S: Dim>(tokens: Tensor[B, S; i32]) -> Tensor[B, S, H; T]

Generics ​

The root block's generics as this checkpoint binds them.

Vocab201088
H2880
Heads64
KvHeads8
HeadDim64
Inner2880
Experts32
TopK4
Layers24
Window128
Batch1
MaxSeq4096
Tbf16

Blocks ​

Every block of the program with its members and functions, as linnet inspect prints them.

DecoderLayer ​

text
gpt_oss::DecoderLayer<H: Dim, Heads: Dim, KvHeads: Dim, HeadDim: Dim, Inner: Dim, Experts: Dim, TopK: Dim, Blocks: Dim, InnerBlocks: Dim, Batch: Dim, MaxSeq: Dim, T: Float>
  sub input_layernorm: RmsNorm<H, T>
  sub self_attn: SinkAttention<H, Heads, KvHeads, HeadDim, Batch, MaxSeq, T>
  sub post_attention_layernorm: RmsNorm<H, T>
  sub mlp: MixtureOfExperts<H, Inner, Experts, TopK, Blocks, InnerBlocks, T>
  pub fn forward<B: Dim, S: Dim>(x: Tensor[B, S, H; T], window: i32) -> Tensor[B, S, H; T]
  pub fn decode(x: Tensor[Batch, 1, H; T], pos: i32, window: i32) -> Tensor[Batch, 1, H; T]
  pub fn prefill<S: Dim>(x: Tensor[Batch, S, H; T], pos: i32, window: i32) -> Tensor[Batch, S, H; T]
  pub fn decode_rows(x: Tensor[Batch, 1, H; T], positions: Tensor[Batch; i32], window: i32) -> Tensor[Batch, 1, H; T]
  pub fn prefill_slots<M: Dim, S: Dim>(x: Tensor[M, S, H; T], slots: Tensor[M; i32], window: i32) -> Tensor[M, S, H; T]
  pub fn prefill_packed<P: Dim>(x: Tensor[1, P, H; T], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], window: i32) -> Tensor[1, P, H; T]
  pub fn step_packed<P: Dim>(x: Tensor[1, Batch + P, H; T], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], step_positions: Tensor[Batch; i32], window: i32) -> Tensor[1, Batch + P, H; T]

Embedding ​

text
std.nn.embedding::Embedding<Vocab: Dim, H: Dim, T: Float = bf16>
  param weight: Tensor[Vocab, H; T]
  pub fn forward<*S: Shape>(ids: Tensor[*S; i32]) -> Tensor[*S, H; T]

Int4GroupLinear ​

text
std.quant::Int4GroupLinear<In: Dim, Out: Dim, Group: Dim = 128, T: Float = bf16>
  param weight: Tensor[Out, In / Group, Group / 2; u8]
  param scale: Tensor[Out, In / Group; T]
  param zero: Tensor[Out, In / Group; u8]
  param order: Tensor[In; i32]?
  param bias: Tensor[Out; T]?
  pub fn forward<*S: Shape>(x: Tensor[*S, In; T]) -> Tensor[*S, Out; T]

Int4Linear ​

text
std.quant::Int4Linear<In: Dim, Out: Dim, T: Float = bf16>
  param weight: Tensor[Out, In / 2; i8]
  param scale: Tensor[Out; f32]
  param bias: Tensor[Out; T]?
  pub fn forward<*S: Shape>(x: Tensor[*S, In; T]) -> Tensor[*S, Out; T]

Int8Linear ​

text
std.quant::Int8Linear<In: Dim, Out: Dim, T: Float = bf16>
  param weight: Tensor[Out, In; i8]
  param scale: Tensor[Out; f32]
  param bias: Tensor[Out; T]?
  pub fn forward<*S: Shape>(x: Tensor[*S, In; T]) -> Tensor[*S, Out; T]

LayerPair ​

text
gpt_oss::LayerPair<H: Dim, Heads: Dim, KvHeads: Dim, HeadDim: Dim, Inner: Dim, Experts: Dim, TopK: Dim, Window: Dim, Blocks: Dim, InnerBlocks: Dim, Batch: Dim, MaxSeq: Dim, T: Float>
  sub sliding: DecoderLayer<H, Heads, KvHeads, HeadDim, Inner, Experts, TopK, Blocks, InnerBlocks, Batch, MaxSeq, T>
  sub full: DecoderLayer<H, Heads, KvHeads, HeadDim, Inner, Experts, TopK, Blocks, InnerBlocks, Batch, MaxSeq, T>
  pub fn forward<B: Dim, S: Dim>(x: Tensor[B, S, H; T]) -> Tensor[B, S, H; T]
  pub fn decode(x: Tensor[Batch, 1, H; T], pos: i32) -> Tensor[Batch, 1, H; T]
  pub fn prefill<S: Dim>(x: Tensor[Batch, S, H; T], pos: i32) -> Tensor[Batch, S, H; T]
  pub fn decode_rows(x: Tensor[Batch, 1, H; T], positions: Tensor[Batch; i32]) -> Tensor[Batch, 1, H; T]
  pub fn prefill_slots<M: Dim, S: Dim>(x: Tensor[M, S, H; T], slots: Tensor[M; i32]) -> Tensor[M, S, H; T]
  pub fn prefill_packed<P: Dim>(x: Tensor[1, P, H; T], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32]) -> Tensor[1, P, H; T]
  pub fn step_packed<P: Dim>(x: Tensor[1, Batch + P, H; T], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], step_positions: Tensor[Batch; i32]) -> Tensor[1, Batch + P, H; T]

Linear ​

text
std.nn.linear::Linear<In: Dim, Out: Dim, T: Float = bf16>
  param weight: Tensor[Out, In; T]
  param bias: Tensor[Out; T]?
  pub fn forward<*S: Shape>(x: Tensor[*S, In; T]) -> Tensor[*S, Out; T]

MixtureOfExperts ​

text
gpt_oss.experts::MixtureOfExperts<H: Dim, Inner: Dim, Experts: Dim, TopK: Dim, Blocks: Dim, InnerBlocks: Dim, T: Float>
  sub router: Linear<H, Experts, T>
  param gate_up_blocks: Tensor[Experts, 2 * Inner, Blocks, 16; u8]
  param gate_up_scales: Tensor[Experts, 2 * Inner, Blocks; u8]
  param gate_up_bias: Tensor[Experts, 2 * Inner; T]
  param down_blocks: Tensor[Experts, H, InnerBlocks, 16; u8]
  param down_scales: Tensor[Experts, H, InnerBlocks; u8]
  param down_bias: Tensor[Experts, H; T]
  pub fn forward<B: Dim, S: Dim>(x: Tensor[B, S, H; T]) -> Tensor[B, S, H; T]
  pub fn forward_topk<B: Dim>(x: Tensor[B, 1, H; T]) -> Tensor[B, 1, H; T]
  pub fn forward_routed<B: Dim, S: Dim>(x: Tensor[B, S, H; T]) -> Tensor[B, S, H; T]
  fn experts_of<R: Dim>(x: Tensor[R, 1, H; T]) -> Tensor[R, TopK; i64]
  fn weights_of<R: Dim>(x: Tensor[R, 1, H; T]) -> Tensor[R, TopK; T]
  fn activate<R: Dim>(gate_up: Tensor[R, TopK, 2 * Inner; T], expert: Tensor[R, TopK; i64]) -> Tensor[R, TopK, Inner; T]
  fn down_bias_of<R: Dim>(weight: Tensor[R, TopK; T], expert: Tensor[R, TopK; i64]) -> Tensor[R, H; T]
  fn route<B: Dim, S: Dim>(logits: Tensor[B, S, Experts; T]) -> Tensor[B, S, Experts; T]
  fn ranks<B: Dim, S: Dim>(logits: Tensor[B, S, Experts; T]) -> Tensor[B, S, Experts; i32]

Model ​

text
gpt_oss::Model<Vocab: Dim, H: Dim, Heads: Dim, KvHeads: Dim, HeadDim: Dim, Inner: Dim, Experts: Dim, TopK: Dim, Layers: Dim, Window: Dim, Batch: Dim, MaxSeq: Dim, T: Float = bf16>
  sub embed_tokens: Embedding<Vocab, H, T>
  sub pairs: [LayerPair<H, Heads, KvHeads, HeadDim, Inner, Experts, TopK, Window, H / 32, Inner / 32, Batch, MaxSeq, T>; Layers / 2]
  sub norm: RmsNorm<H, T>
  sub lm_head: Linear<H, Vocab, T>
  pub entry forward<B: Dim, S: Dim>(tokens: Tensor[B, S; i32]) -> Tensor[B, S, Vocab; T]
  pub entry next_token<B: Dim, S: Dim>(tokens: Tensor[B, S; i32]) -> Tensor[B, Vocab; T]
  pub entry decode(token: Tensor[Batch, 1; i32], pos: i32) -> Tensor[Batch, Vocab; T]
  pub entry prefill<S: Dim>(tokens: Tensor[Batch, S; i32], pos: i32) -> Tensor[Batch, Vocab; T]
  pub entry decode_rows(tokens: Tensor[Batch, 1; i32], positions: Tensor[Batch; i32]) -> Tensor[Batch, Vocab; T]
  pub entry prefill_slots<M: Dim, S: Dim>(tokens: Tensor[M, S; i32], slots: Tensor[M; i32], lengths: Tensor[M; i32]) -> Tensor[M, Vocab; T]
  pub entry prefill_packed<P: Dim>(tokens: Tensor[P; i32], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], last: Tensor[Batch; i32]) -> Tensor[Batch, Vocab; T]
  pub entry step_packed<P: Dim>(tokens: Tensor[P; i32], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], last: Tensor[Batch; i32], step_tokens: Tensor[Batch, 1; i32], step_positions: Tensor[Batch; i32]) -> Tensor[2 * Batch, Vocab; T]
  pub entry states<B: Dim, S: Dim>(tokens: Tensor[B, S; i32]) -> Tensor[B, S, H; T]
  fn hidden<B: Dim, S: Dim>(tokens: Tensor[B, S; i32]) -> Tensor[B, S, H; T]

RmsNorm ​

text
std.nn.norm::RmsNorm<H: Dim, T: Float = bf16>
  param weight: Tensor[H; T]
  pub fn forward<*S: Shape>(x: Tensor[*S, H; T]) -> Tensor[*S, H; T]

SinkAttention ​

text
gpt_oss.attention::SinkAttention<H: Dim, Heads: Dim, KvHeads: Dim, HeadDim: Dim, Batch: Dim, MaxSeq: Dim, T: Float>
  sub q_proj: Linear<H, Heads * HeadDim, T>
  sub k_proj: Linear<H, KvHeads * HeadDim, T>
  sub v_proj: Linear<H, KvHeads * HeadDim, T>
  sub o_proj: Linear<Heads * HeadDim, H, T>
  param sinks: Tensor[Heads; T]
  state cache_k: Tensor[Batch, KvHeads, MaxSeq, HeadDim; T]
  state cache_v: Tensor[Batch, KvHeads, MaxSeq, HeadDim; T]
  pub fn forward<B: Dim, S: Dim>(x: Tensor[B, S, H; T], window: i32) -> Tensor[B, S, H; T]
  pub fn decode(x: Tensor[Batch, 1, H; T], pos: i32, window: i32) -> Tensor[Batch, 1, H; T]
  pub fn prefill<S: Dim>(x: Tensor[Batch, S, H; T], pos: i32, window: i32) -> Tensor[Batch, S, H; T]
  pub fn decode_rows(x: Tensor[Batch, 1, H; T], positions: Tensor[Batch; i32], window: i32) -> Tensor[Batch, 1, H; T]
  pub fn prefill_slots<M: Dim, S: Dim>(x: Tensor[M, S, H; T], slots: Tensor[M; i32], window: i32) -> Tensor[M, S, H; T]
  pub fn prefill_packed<P: Dim>(x: Tensor[1, P, H; T], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], window: i32) -> Tensor[1, P, H; T]
  pub fn step_packed<P: Dim>(x: Tensor[1, Batch + P, H; T], rows: Tensor[P; i32], positions: Tensor[P; i32], segments: Tensor[P; i32], step_positions: Tensor[Batch; i32], window: i32) -> Tensor[1, Batch + P, H; T]