Skip to main content
The script below converts a BF16 GPT-OSS checkpoint (Hugging Face layout with .safetensors) into an MXFP4-quantized checkpoint.
  • Downcasts selected weights to MXFP4 using Triton kernels
  • Keeps specified layers in full precision (router, norms, embeddings, etc.)
  • Splits large weights into multiple .safetensors files
  • Writes a model.safetensors.index.json and updates config.json with quantization_config
  • Copies tokenizer files from the original checkpoint
This is a one-way conversion helper: it assumes your source checkpoint is already BF16 and on disk.

Prerequisites

  • Environment with at least 1 GPU (CUDA)
  • Python 3.10+ recommended
  • The following Python packages:

Usage

Assume you have the original BF16 checkpoint:
  • INPUT_CKPT_PATH=/path/to/gpt-oss-20b-BF16/ (directory containing .safetensors, config.json, tokenizer files)
Choose an output directory for the quantized checkpoint:
  • QUANT_CKPT_PATH=/path/to/gpt-oss-20b-BF16-mxfp4/
Run:
After this finishes, $QUANT_CKPT_PATH will contain:
  • MXFP4-quantized .safetensors shards
  • model.safetensors.index.json
  • config.json with quantization_config
  • Tokenizer files copied from the original checkpoint
You can then point your runtime / serving stack at QUANT_CKPT_PATH.

Script: to_mxfp4.py