Finish GPT-OSS 20B on the open engine
GPT-OSS is the last of the five families in #71 that still refuses to build. The container side is done; what is left is the model side -- a recipe, a packing step for the experts, and kernels.
What already works. The engine reads GPT-OSS's container correctly now: the expert format is identified as MXFP4 and decoded against OpenAI's own weights, the half-width weight chunks are placed, a width that would have produced a corrupt weight pool is refused, and the adapter selects the open engine if a kernel set is ever installed. None of that produces a token. It is the ground a recipe stands on, and until last week each of those returned a plausible wrong answer with nothing raised.
The packing step for the experts. The converter fuses gate, up and down into one tensor per layer; the order is gate and up alternating every 128 rows for the first two thirds, then down as one block. Offline, and the expert biases ship twice -- named, and inside each chunk's own padding -- which gives a way to pin the order by value rather than by inference.
Three small kernels, each following the attention-sink precedent: a new source file or macro under its own flag, defaulting off, with a before/after object diff across every shipped family as the gate. A clamped SwiGLU for the experts; a consts slot and one add for the output projection's bias; and the router widened from its hard-wired expert count to 32 experts and top-4. The arithmetic for all three is already written and checked against transformers in the fp64 reference, so this is plumbing plus the diff. Needs the WSL toolchain.
The long pole is the expert FFN. GPT-OSS's expert intermediate is the same width as its hidden. Every family we run has it at a quarter, and that ratio is spread through four separate places in the hand-placed core layout -- one of them divides by a count that comes out zero at GPT-OSS's shape. That is a design change plus new validated points, each needing a hardware compare. Weeks, and it needs the NPU.
Then the recipe, the fp64 comparison, and oflm-test --llm through
oflm serve, which is where a model starts working.
The requirements and what each is verified by are in specs/open-engine/spec.md
-- OPEN-FAMILY-GPTOSS, OPEN-QUANT-MXFP4, OPEN-PACK-CHUNK-FUSE, OPEN-WIDTH-PAD
and OPEN-EMBED-STRIDE. Happy to send the packer and the small kernels up ahead
of the MoE work if you would rather review them separately.
Analyzed the closed one if it helps
GPT-OSS-20B-NPU2 XCLBIN Analysis
Overview
Six AMD/Xilinx AXLF (xclbin2) accelerator binaries for the GPT-OSS 20B reasoning model, running on AMD Ryzen™ AI NPU2 (XDNA2) hardware. These are pre-compiled AIE (AI Engine) kernel binaries used by FastFlowLM's NPU runtime.
Target Model: GPT-OSS 20B (Q4_1 quantized, reasoning/thinking model) Platform: aie2p (NPU2 / XDNA2) Model Family: gpt-oss Size: ~20B parameters, ~14GB footprint on NPU
Binary Inventory
| File | UUID | Version | Build Date | File Size | AIE Partition |
|---|---|---|---|---|---|
attn.xclbin |
b0c97ebf75473dddd7ab32a04bf4d80c |
2.19.0 | 2026-02-01 13:55:32 | 320,443 B (312.9 KB) | 314,408 B (307.0 KB) |
dequant.xclbin |
7abc4ce111e9e34d0dd5fe39054a376e |
2.19.0 | 2026-01-29 07:58:26 | 319,339 B (311.9 KB) | 313,304 B (306.0 KB) |
expert.xclbin |
695e756b75a8911527cf204b913e84cf |
2.20.0 | 2025-11-08 17:20:23 | 146,027 B (142.6 KB) | 139,992 B (136.7 KB) |
layer.xclbin |
d450332e74a839385c5ad89e8a156d0a |
2.21.75 | 2026-07-30 09:02:46 | 562,732 B (549.5 KB) | 556,696 B (543.6 KB) |
mm.xclbin |
7d8f73695fd9f83d6c419019adefa53e |
2.20.0 | 2026-01-29 08:42:10 | 580,315 B (566.7 KB) | 574,280 B (560.8 KB) |
short_seq_mm.xclbin |
9e9edec2a557ff4f069c937546a11dd8 |
2.20.0 | 2026-01-29 10:34:16 | 547,547 B (534.7 KB) | 541,512 B (528.8 KB) |
Total file size: 2,456,403 B (~2.4 MB) Total AIE partition size: 2,440,272 B (~2.3 MB)
Binary Structure (All Files)
All six binaries share the same AXLF v2 container format with identical structure:
AXLF Header
- Magic:
xclbin2(0x78636c62696e32) - Signature Length:
ffffffff(no signature) - Version: Xilinx XRT version 2.19.0 / 2.20.0 / 2.21.75
- Mode: 0 (Standard)
- Interface UUID: All zeros (no custom IP)
XCLBIN Sections (7 sections per binary, Kind 6/32/2/8/7/27/26)
Each binary contains:
- Kind 6 - mem_topology: Memory topology definition
- Kind 32 - aie_partition: AIE kernel partition data (the actual compiled AIE code)
- Kind 2 - binary data: Raw binary payload
- Kind 8 - ip_layout: IP kernel layout
- Kind 7 - connectivity: Argument-to-memory mappings
- Kind 27 - group_connectivity: Group connectivity mapping
- Kind 26 - group_topology: Group memory topology
Memory Topology (All Files)
HOST: MEM_DRAM, 65536 KB (64 MB), base=0x4000000
SRAM: MEM_DRAM, 49152 KB (48 MB), base=0x4000000
IP Layout (All Files)
Kernel Name: MLIR_AIE:MLIRAIE
Type: IP_PS_KERNEL
Subtype: DPU
Functional: DPU
Kernel ID: 0x901
Kernel Arguments (All Files)
All kernels use a standard 8-argument interface:
| Arg | Index | Size | Type | Mem |
|---|---|---|---|---|
opcode |
0 | 8 B | uint64_t | - |
instr |
1 | 8 B | char* | SRAM (index 1) |
ninstr |
2 | 4 B | uint32_t | - |
bo0 |
3 | 8 B | void* | HOST (index 0) |
bo1 |
4 | 8 B | void* | HOST (index 0) |
bo2 |
5 | 8 B | void* | HOST (index 0) |
bo3 |
6 | 8 B | void* | HOST (index 0) |
bo4 |
7 | 8 B | void* | HOST (index 0) |
Connectivity:
arg[1](instr) → mem[1] (SRAM) - instruction bufferarg[3-7](bo0-bo4) → mem[0] (HOST) - 5 buffer objects for weight/data/memory
Kernel Function Descriptions
1. attn.xclbin — Attention Layer
- Build: 2026-02-01 (most recent in the set)
- AIE partition: 314,408 B (~307 KB)
- Role: Self-attention computation (Q/K/V projection, attention score, output projection)
- AIE instructions: ~4,235 unique 4-byte instruction blocks
- Top instruction patterns:
00000000(49,098 occurrences) - zero/null operations000178a5(11,840 occurrences)0001205b(6,816 occurrences)000078e1(6,336 occurrences)
2. dequant.xclbin — Dequantization
- Build: 2026-01-29
- AIE partition: 313,304 B (~306 KB)
- Role: Dequantizes Q4_1 (4-bit) weights to BF16 for computation
- AIE instructions: Similar pattern density to attn
- Strings: Contains
IDPPandaie_imagemarkers
3. expert.xclbin — Mixture-of-Experts Router/Dispatch
- Build: 2025-11-08 (oldest, version 2.20.0)
- AIE partition: 139,992 B (~137 KB) - smallest
- Role: MoE expert selection and routing; dispatches tokens to different expert weights
- Notably smaller — likely handles routing logic with less compute per kernel
- Strings: Contains
i^uku(possibly expert index/name marker)
4. layer.xclbin — Full Transformer Layer
- Build: 2026-07-30 (newest, version 2.21.75 - latest version)
- AIE partition: 556,696 B (~544 KB) - largest
- Role: Complete transformer layer combining attention + FFN + layernorm
- Strings: Rich string content including alphabet sequences (
~\|zxvusqomljhgedb), character patterns, and various encoded identifiers - Contains:
KzL*M,XuY'Z,epf#g,w{x+y,z *!,223d(,9o:";markers
5. mm.xclbin — General Matrix Multiplication
- Build: 2026-01-29
- AIE partition: 574,280 B (~561 KB) - largest AIE partition
- Role: General GEMM operations (weight matrix × activation matrix)
- AIE instructions: ~4,235 unique 4-byte blocks (same as attn)
- Top patterns: Identical instruction pattern distribution to attn.xclbin
- Strings:
vx\7h,D&.!7=,@L?Jc,$\N8,f)$!,J"D"f,J)f#d,rEK!y,CLM9,CLM:`
6. short_seq_mm.xclbin — Short Sequence GEMM (Prefill Optimized)
- Build: 2026-01-29
- AIE partition: 541,512 B (~529 KB)
- Role: Optimized GEMM for short sequence lengths (prefill phase, where batch size=1 and sequence is short)
- Similar to mm.xclbin but tuned for short-sequence workloads
- Strings: Identical instruction pattern set to mm.xclbin (same base kernel family)
GPT-OSS Model Architecture (from C++ source)
Backend Class: gpt_oss_npu
- Extends
causal_lmbase class - Uses
Q4NXquantized weight format (Q4_1) - Supports preemption and KV cache checkpointing (
checkpoint()/restore()) - BF16 compute on AIE
High-Level Model Class: GPT_OSS
- Extends
AutoModel - Reasoning model with toggleable thinking (
enable_think = true) - Configurable
reasoning_effortparameter: "low", "medium", "high" - Uses Harmony chat template
- Supports tool grammar/state machine
Weight Loading
- Load GGUF/Q4NX model file
- Parse config.json for architecture parameters
- Dispatch to appropriate NPU kernels:
attn.xclbin→ attention kernelsdequant.xclbin→ dequantization kernelsmm.xclbin→ GEMM for large sequencesshort_seq_mm.xclbin→ GEMM for prefillexpert.xclbin→ MoE routinglayer.xclbin→ full layer computation
Model Config (from model_list.json)
- Tag:
gpt-oss:20b - Model name:
GPT-OSS-20B-NPU2 - Size: 20B parameters (~20 GB download)
- Quantization: Q4_1
- Default context: 8,192 tokens
- Max prefill: 4,096 tokens
- Reasoning: Yes (not toggleable)
- Label: reasoning
- HuggingFace: FastFlowLM/GPT-OSS-20B-NPU2
Safeguard Variant
- Tag:
gpt-oss-sg:20b - Name:
GPT-OSS-Safeguard-20b-NPU2 - Same kernels in
GPT-OSS-Safeguard-20b-NPU2/directory (identical structure)
Comparison with FastFlowLM Ecosystem
Positioning in the XCLBIN Directory
The GPT-OSS-20B-NPU2/ directory sits among ~30+ model families in src/xclbins/. Key observations:
- Unique to GPT-OSS: The
expert.xclbinMoE kernel is unique to this model family (most other models don't have it) - No
lm_head.xclbin: Unlike Gemma3/Qwen3 models, GPT-OSS does not ship a separate LM head kernel - No vision kernels: Pure text model, no
vision_attn.xclbinorvision_mm.xclbin - Two GEMM variants:
mm.xclbin+short_seq_mm.xclbinfor prefill vs decode optimization
Version Evolution
- expert.xclbin: v2.20.0 (Nov 2025) - oldest, stable
- attn/dequant/mm/short_seq: v2.19.0-2.20.0 (Jan-Feb 2026)
- layer.xclbin: v2.21.75 (Jul 2026) - newest, most iterations
File Size Hierarchy
mm.xclbin— 580 KB (largest, heavy GEMM)short_seq_mm.xclbin— 548 KBlayer.xclbin— 563 KBattn.xclbin— 320 KBdequant.xclbin— 319 KBexpert.xclbin— 146 KB (smallest, routing logic)
OpenFlowLM-Next Reimplementation Notes
Current Status (from AGENTS.md)
- GPT-OSS is NOT yet supported by open kernels
- Quote: "Vision, audio and the Gemma 4, GPT-OSS and Whisper families have no open design yet"
- GPT-OSS falls back to closed engine binaries from FastFlowLM
What Needs Open Implementation
To fully reimplement GPT-OSS in OpenFlowLM-Next, we need:
attn.xclbin→ Open AIE kernel for self-attention (QKV, attention score, output proj)dequant.xclbin→ Open dequant kernel for Q4_1 weightsmm.xclbin→ Open GEMM kernel (general dense matmul)short_seq_mm.xclbin→ Open short-sequence GEMM kernelexpert.xclbin→ Open MoE routing kernellayer.xclbin→ Open full transformer layer kernel
Open FlowLM Architecture Reference
The OpenFlowLM-Next project uses:
open_kernels/directory with MLIR source + compiled xclbinsspec.jsonfor kernel specificationsmanifest.jsonfor model-kernel mappingsharness/for testing- Recipes in
recipes/for different model families
Reimplementation Path
- Study the existing closed xclbins (this analysis)
- Create MLIR AIE designs matching the kernel interfaces:
- Same 8-argument ABI (opcode, instr, ninstr, bo0-bo4)
- Same memory topology (HOST + SRAM)
- Build via IRON + mlir-aie toolchain (Peano at
./ironvenv/lib/python3.12/site-packages/llvm-aie/bin) - Verify against FastFlowLM reference outputs
- Add to
spec.jsonfor the GPT-OSS model family
Key Differences from Existing Open Models
- GPT-OSS is a MoE model with routing (like Qwen3.6-MoE)
- Uses Q4_1 quantization (not Q4_K)
- No LM head kernel — handles it differently than Gemma/Qwen
- Thinking/reasoning mode — has special prompt formatting and tool grammar
- No vision/audio — simpler than multi-modal models
Estimated Implementation Complexity
- Dequant: Low (~307 KB AIE, standard pattern)
- Attention: Medium (~307 KB, standard attention pattern)
- GEMM (mm + short_seq): Medium-Large (~540-561 KB each, heavy compute)
- Layer: Medium-Large (~544 KB, combined attention+FFN)
- Expert (MoE routing): Low-Medium (~137 KB, routing logic)
Total open kernel set would be approximately 2.3 MB of AIE code (matching the closed set).
Timestamp Analysis
All binaries are from the future (relative to mid-2026), suggesting these are either:
- Built on a system with future date, or
- Using a build system that generates timestamps from future dates
| Kernel | Build Date | Age relative to set |
|---|---|---|
| expert.xclbin | 2025-11-08 | Reference/oldest |
| dequant.xclbin | 2026-01-29 | +2.5 months |
| mm.xclbin | 2026-01-29 | +2.5 months |
| short_seq_mm.xclbin | 2026-01-29 | +2.5 months |
| attn.xclbin | 2026-02-01 | +2.5 months |
| layer.xclbin | 2026-07-30 | +6.5 months (latest) |
The layer.xclbin version (2.21.75) is notably higher than the others (2.19.x/2.20.x), suggesting it went through more iterations.
AIE Instruction Analysis (mm.xclbin as representative)
The AIE partition contains compiled AIE core instructions. Analysis shows:
- Unique instructions: ~4,235 distinct 4-byte instruction blocks
- Total instruction space: ~574 KB of AIE code
- Dominant patterns:
- Zero operations (
00000000): ~49K occurrences - padding/null operations 000178a5: ~12K occurrences - likely common GEMM tile operations0001205b: ~7K occurrences000078e1: ~6K occurrences000078a5: ~6K occurrences000001a5: ~6K occurrences
- Zero operations (
The DPU marker appears at the end of the AIE partition data, indicating the DPU (Deep Learning Processor Unit) firmware metadata.
Analysis generated from FastFlowLM src/xclbins/GPT-OSS-20B-NPU2/ For use as reference when reimplementing in OpenFlowLM-Next