Text Generation
Transformers
Safetensors
GGUF
English
gpt_oss
Mixture of Experts
mixture-of-experts
causal-lm
tinystories
tiny-model
validation
debug-model
mxfp4
e2m1
e8m0
Instructions to use shibatch/tinygptossmoe3m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shibatch/tinygptossmoe3m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shibatch/tinygptossmoe3m")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shibatch/tinygptossmoe3m", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use shibatch/tinygptossmoe3m with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf shibatch/tinygptossmoe3m:MXFP4 # Run inference directly in the terminal: llama cli -hf shibatch/tinygptossmoe3m:MXFP4
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf shibatch/tinygptossmoe3m:MXFP4 # Run inference directly in the terminal: llama cli -hf shibatch/tinygptossmoe3m:MXFP4
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf shibatch/tinygptossmoe3m:MXFP4 # Run inference directly in the terminal: ./build/bin/llama cli -hf shibatch/tinygptossmoe3m:MXFP4
Use Docker
docker model run hf.co/shibatch/tinygptossmoe3m:MXFP4
- Llama new
- LM Studio
- Jan
- vLLM
How to use shibatch/tinygptossmoe3m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shibatch/tinygptossmoe3m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinygptossmoe3m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/shibatch/tinygptossmoe3m:MXFP4
- SGLang
How to use shibatch/tinygptossmoe3m with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "shibatch/tinygptossmoe3m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinygptossmoe3m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "shibatch/tinygptossmoe3m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinygptossmoe3m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Ollama
How to use shibatch/tinygptossmoe3m with Ollama:
ollama run hf.co/shibatch/tinygptossmoe3m:MXFP4
- Unsloth Desktop
- Docker Model Runner
How to use shibatch/tinygptossmoe3m with Docker Model Runner:
docker model run hf.co/shibatch/tinygptossmoe3m:MXFP4
- Lemonade
How to use shibatch/tinygptossmoe3m with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull shibatch/tinygptossmoe3m:MXFP4
Run and chat with the model
lemonade run user.tinygptossmoe3m-MXFP4
List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub
Browse filesFiles changed (21)
- .gitattributes+1-34
- LICENSEAdded+21
- MXFP4_VERSION_LOCK.jsonAdded+33
- README.md+153-7
- SHA256SUMSAdded+29
- mxfp4_packing_test_vector.jsonAdded+24
- mxfp4_reference_outputs/cached_logits.safetensorsAdded+3
- mxfp4_reference_outputs/expert_projection.safetensorsAdded+3
- mxfp4_reference_outputs/full_logits.safetensorsAdded+3
- mxfp4_reference_outputs/greedy_continuation.jsonAdded+82
- mxfp4_reference_outputs/reference_manifest.jsonAdded+70
- mxfp4_reference_outputs/routing.safetensorsAdded+3
- original/config.jsonAdded+18
- original/conversion_manifest.jsonAdded+53
- original/dtypes.jsonAdded+95
- original/model.safetensorsAdded+3
- original/tensor_inventory.jsonAdded+1121
- requirements-mxfp4.txtAdded+7
- tools/convert_tinygptoss_to_mxfp4.pyAdded+337
- tools/generate_gptoss_mxfp4_reference.pyAdded+335
- tools/verify_mxfp4.pyAdded+106
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text12*.safetensors filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text
123456789101112131415161718192021MIT License
Copyright (c) 2026 shibatch
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.123456789101112131415161718192021222324252627282930313233{ "python": "3.13.7", "packages": { "torch": "2.8.0+cu128", "triton": "3.4.0", "triton_kernels": "editable from pinned Triton revision", "safetensors": "0.8.0", "tokenizers": "0.22.2", "numpy": "2.5.1", "pytest": "9.1.1", "huggingface_hub": "1.26.0" }, "repositories": { "openai_gpt_oss": { "url": "https://github.com/openai/gpt-oss.git", "revision": "599476783c6f88508dab8577808b5ead5cbee8d2" }, "triton": { "url": "https://github.com/triton-lang/triton.git", "revision": "9e1e203f64752cf99abf0e44286231c5d5df7e76" }, "official_profile": { "repo_id": "openai/gpt-oss-20b", "revision": "6cee5e81ee83917806bbde320786a8fb61efebee", "subfolder": "original" }, "source_model": { "repo_id": "shibatch/tinygptossmoe3m", "subfolder": "hf", "model_sha256": "baf06470d796cf7cc3cbb74e0cc176940ca45b2889cc9080640243c563f810cb" } }}11 unmodified lines1213141516177 unmodified lines25262728293011 unmodified lines4243444546473 unmodified lines51525354555657199 unmodified lines25725825926026126226326 unmodified lines29029129229329429529649 unmodified lines34634734834935035110 unmodified lines36236336436536636736836929 unmodified lines39940040140240340440540640740840911 unmodified lines- validation- debug-model- transformerspipeline_tag: text-generation---7 unmodified linesThis is a synthetic tiny validation checkpoint. It is not an official OpenAI model and does not contain weights from the original gpt-oss checkpoints.## Model purposeThis model is designed for:11 unmodified lines* exercising MoE expert parameters* exercising top-4 expert routing* providing a compact gpt-oss-style MoE checkpoint for inference-engine validationIt is not designed for:3 unmodified lines* benchmark comparison against production language models* production deployment* reproducing the behavior of the original gpt-oss models* testing MXFP4 quantized weight loading## Model architecture199 unmodified linesThe model can generate TinyStories-like text fragments, but repetition, template collapse, and weak long-form coherence are expected. This is normal for this checkpoint and is not considered a failure for its intended purpose.## Usage```pythonimport torch26 unmodified lines## Loading requirementsThis checkpoint requires a Transformers version that supports gpt-oss models.The following imports should work:49 unmodified linesgenerate()save_pretrained()from_pretrained()```## Limitations10 unmodified lines* no instruction tuning* no chat formatting* no production use* no MXFP4 checkpoint coverage* no compatibility claim with original gpt-oss model qualityThe checkpoint is primarily intended to make gpt-oss-style MoE text-model code paths easy to test without downloading a large model.29 unmodified lines## Notes on MXFP4 and quantizationThe original large gpt-oss checkpoints use specialized quantization settings. This tiny validation checkpoint is trained and saved as a normal small floating-point Hugging Face model.It is intended for architecture, loader, routing, and generation validation. It is not intended to validate MXFP4 decoding or production quantized loading paths.A quantized tiny gpt-oss validation checkpoint can be produced as a separate artifact if needed.## Suggested repository name11 unmodified lines1213141516171819207 unmodified lines282930313233343536373839404142434445464711 unmodified lines59606162636465663 unmodified lines707172737475199 unmodified lines27527627727827928028126 unmodified lines30830931031131231331449 unmodified lines36436536636736836937037137237337437510 unmodified lines38638738838939039139239329 unmodified lines42342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455511 unmodified lines- validation- debug-model- transformers- mxfp4- e2m1- e8m0pipeline_tag: text-generation---7 unmodified linesThis is a synthetic tiny validation checkpoint. It is not an official OpenAI model and does not contain weights from the original gpt-oss checkpoints.## Repository weight profilesThis repository contains two representations of the same trained model:| Subfolder | Purpose | Precision ||---|---|---|| `hf/` | Hugging Face `GptOssForCausalLM` | FP32 || `original/` | OpenAI original-format loader | official-profile MXFP4 + BF16 |The `original/` checkpoint is not a blanket 4-bit conversion. Only expert`mlp1_weight` and `mlp2_weight` tensors use MXFP4 `.blocks` and `.scales`.Embedding, attention, router, bias, norm, sink, and unembedding tensors remainBF16, matching the official gpt-oss precision profile.## Model purposeThis model is designed for:11 unmodified lines* exercising MoE expert parameters* exercising top-4 expert routing* providing a compact gpt-oss-style MoE checkpoint for inference-engine validation* testing official-profile MXFP4 tensor loading and decoding* comparing full-sequence and KV-cached logitsIt is not designed for:3 unmodified lines* benchmark comparison against production language models* production deployment* reproducing the behavior of the original gpt-oss models## Model architecture199 unmodified linesThe model can generate TinyStories-like text fragments, but repetition, template collapse, and weak long-form coherence are expected. This is normal for this checkpoint and is not considered a failure for its intended purpose.## Hugging Face FP32 usage```pythonimport torch26 unmodified lines## Loading requirementsThe `hf/` checkpoint requires a Transformers version that supports gpt-oss models.The following imports should work:49 unmodified linesgenerate()save_pretrained()from_pretrained()official gpt-oss original-format loadingMXFP4 E2M1 expert blocksE8M0 expert scalesfull versus KV-cached logitstop-4 routing IDs and weightsselected expert projection outputs```## Limitations10 unmodified lines* no instruction tuning* no chat formatting* no production use* no compatibility claim with original gpt-oss model quality* the tiny attention dimensions require the documented reference-attention adapter for OpenAI's Triton implementationThe checkpoint is primarily intended to make gpt-oss-style MoE text-model code paths easy to test without downloading a large model.29 unmodified lines## Notes on MXFP4 and quantizationThe `original/model.safetensors` file follows the naming, shape, packing, andmixed-precision profile used by OpenAI's original-format gpt-oss checkpoints.There is no separate `.mxfp4` file extension: MXFP4 tensors are represented bypaired `.blocks` and `.scales` tensors inside SafeTensors.```textblock.N.mlp.mlp1_weight.blocks uint8 E2M1, two values per byteblock.N.mlp.mlp1_weight.scales uint8 E8M0block.N.mlp.mlp2_weight.blocks uint8 E2M1, two values per byteblock.N.mlp.mlp2_weight.scales uint8 E8M0```Packing and conversion rules:* 32 E2M1 values per scale block* first/even value in the low nibble* second/odd value in the high nibble* E8M0 exponent bias 127* OCP `ROUND_DOWN` scale selection* round-to-nearest, ties-to-even E2M1 conversion* block scaling along the final logical matrix dimensionThe model contains 93 physical tensors: 69 BF16, 12 FP4 block tensors, and 12UE8 scale tensors. Exact names, dtypes, shapes, byte sizes, and raw-tensorSHA-256 values are in `original/tensor_inventory.json`. A standalone packingexample is in `mxfp4_packing_test_vector.json`.The fixed model SHA-256 is:```text30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d```### Fixed revisions```textOpenAI gpt-oss:599476783c6f88508dab8577808b5ead5cbee8d2Triton kernels:9e1e203f64752cf99abf0e44286231c5d5df7e76Official profile reference openai/gpt-oss-20b:6cee5e81ee83917806bbde320786a8fb61efebee```Exact package versions are recorded in `MXFP4_VERSION_LOCK.json` and`requirements-mxfp4.txt`.```bashpython3 -m venv .venv-mxfp4source .venv-mxfp4/bin/activatepip install -r requirements-mxfp4.txtgit clone https://github.com/openai/gpt-oss.git third_party/openai-gpt-ossgit -C third_party/openai-gpt-oss checkout --detach \599476783c6f88508dab8577808b5ead5cbee8d2git clone https://github.com/triton-lang/triton.git third_party/tritongit -C third_party/triton checkout --detach \9e1e203f64752cf99abf0e44286231c5d5df7e76pip install --no-deps -e third_party/triton/python/triton_kernels```### Reproduce the conversionAfter cloning the pinned OpenAI and Triton repositories and installing`triton_kernels`, run from this repository's root:```bashPYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels \python tools/convert_tinygptoss_to_mxfp4.py \--source-dir hf \--output-dir rebuilt/original \--openai-repo third_party/openai-gpt-oss \--triton-repo third_party/triton```### Fixed reference outputs`mxfp4_reference_outputs/` contains:* full FP32 logits `[1, 5, 1024]`* token-by-token cached logits `[1, 5, 1024]`* top-4 routing IDs, weights, and router logits for all six layers* selected expert projection and routing-weighted output for all six layers* a 64-token greedy continuationFor the fixed prompt `Once upon a time,`, full and cached logits arebyte-identical:```textmax_abs_diff: 0.0mean_abs_diff: 0.0all_token_argmax_equal: true```Regenerate them with:```bashCUDA_VISIBLE_DEVICES=0 \PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels \python tools/generate_gptoss_mxfp4_reference.py \--checkpoint original \--tokenizer hf \--output-dir rebuilt/mxfp4_reference_outputs \--openai-repo third_party/openai-gpt-oss \--triton-repo third_party/triton \--prompt 'Once upon a time,' \--max-new-tokens 64 \--context 256 \--device cuda:0```OpenAI's Triton attention code assumes dimensions used by the 20B/120Bmodels. For this tiny model's one KV head, four GQA groups, and 32-wide head,the harness transposes the two grouping axes and calls the pinned official`attention_ref`. OpenAI's model source is not patched; its loader, KV cache,Transformer, routing, and Triton MXFP4 MoE paths remain in use. The adapter isfully recorded in `mxfp4_reference_outputs/reference_manifest.json`.Verify all repository payload hashes, all 93 tensor hashes, and MXFP4 shapes:```bashpython tools/verify_mxfp4.py```## Suggested repository name
1234567891011121314151617181920212223242526272829127386e47ae53f224aaf02383189e1b11e6d52289775b426655aa5d87d7e953c ./.gitattributescdf09a0b07d7cdb2ea535ac3127541ea55d6a996787a8e1b9266015d69f708a2 ./LICENSEe2bf6966c9e65266186eefe61609bbb0126bfbc9f4cdc62e29c8b4b8631d88d0 ./MXFP4_VERSION_LOCK.jsond9c48665fc34d115e88b6f7004ccf23733a6ffaf9b18fe62d52510c4152d3c15 ./README.mdc0c9b803fcf90373f3ffbff866bf2e318be867efcc0568fab799a1280654d3f4 ./artifact_metadata.json496bad1de60db3b5e5e3ab212a593ae108e932d32313c191452f96d9409e9c57 ./eval_text_generation.jsonf07d5eab89bab4a5d488e335f79e27626653abe5281006711ef27551d50a886a ./gpt_oss_config_dump.json7d68c391baabd2a64ccb6c381c0d7c98ad5f6389871d45491ad2c70ef4091637 ./hf/config.jsond620c9792670d1dc597f38e85d8e99692a6783434d497f991ceb20d5e6e200d4 ./hf/generation_config.jsonbaf06470d796cf7cc3cbb74e0cc176940ca45b2889cc9080640243c563f810cb ./hf/model.safetensorsaa81ff9823a3249d87ae978b31f1e72226d77d63f9488115eb9bd76462699c70 ./hf/tokenizer.jsonf7dfa5942f9e71bcc3c7a6f0494f7a100be8470184ed39a2be6cbf78ebae89fd ./hf/tokenizer_config.jsonf9192dad418925a3dc4f2177e53a7f70e968cab21af83dd69b8be604b64c7710 ./mxfp4_packing_test_vector.json5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f ./mxfp4_reference_outputs/cached_logits.safetensors33f73333341f7a86b6a44d273581a096bed789d927a90ce7411d43c0437748bb ./mxfp4_reference_outputs/expert_projection.safetensors5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f ./mxfp4_reference_outputs/full_logits.safetensors1478ed0112bf32f0444a5dd1bae9eeaebe2cc751396d1fe92513e6e208984b2d ./mxfp4_reference_outputs/greedy_continuation.json9dc39d874552ace0edf32ff7f7d7afcb8f901ff0c64b85d3e773dac9df1c7872 ./mxfp4_reference_outputs/reference_manifest.jsonf94ffb12b3da2c922fc7e95134603e155fd06046dbaba9610360e8aea2d58311 ./mxfp4_reference_outputs/routing.safetensorsf9be3908850cc3def17375cbbae101c1b6ee801b4db7315489dbe6f513d4affe ./original/config.json6ab2027a978cb64efc4841548384c6b4e19be4850421f1215b16ee2824e62aa6 ./original/conversion_manifest.jsonfa36ec5d12a062717c28c7bb53535e1e29d70ea1b41e32c8ec137888df2309c8 ./original/dtypes.json30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d ./original/model.safetensors99d24cda1c1441cc3ff04776a618e432b3e3f3ba6ddd33bc2b9342d2ca3b68a5 ./original/tensor_inventory.jsonc4edf49855cd72ef1818df1983aa4045ffd0187bf54d7ff762343876e4d6d227 ./requirements-mxfp4.txt3771257b3918a4ec233a2ed583601537537596552f54c9bec6ddae01042e98d1 ./tokenizer_train/tokenizer.json84c1c4d7abf70c9a81483e8b2c8885d51d468d5ea0d3db5200dc83bae20b6c36 ./tools/convert_tinygptoss_to_mxfp4.py323d3d38193f0b27987ea5377d8af290843051bfaa4bfce2ffecc5e6e349ddd6 ./tools/generate_gptoss_mxfp4_reference.pya06adce5d4be2249caa777f2a912833406f01dfa16773e3699c85b4ec7df7a74 ./tools/verify_mxfp4.py123456789101112131415161718192021222324{ "description": "Canonical low-nibble-first E2M1 and E8M0 packing vector", "quantizer": "triton_kernels.numerics_details.mxfp.downcast_to_mxfp_torch", "triton_revision": "9e1e203f64752cf99abf0e44286231c5d5df7e76", "rounding_mode": "DequantScaleRoundingMode.ROUND_DOWN", "block_size": 32, "input_float32": [ 0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, -0.0, -0.5, -1.0, -1.5, -2.0, -3.0, -4.0, -6.0, 0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, -0.0, -0.5, -1.0, -1.5, -2.0, -3.0, -4.0, -6.0 ], "packed_uint8_decimal": [ 16, 50, 84, 118, 152, 186, 220, 254, 16, 50, 84, 118, 152, 186, 220, 254 ], "packed_uint8_hex": [ "10", "32", "54", "76", "98", "ba", "dc", "fe", "10", "32", "54", "76", "98", "ba", "dc", "fe" ], "scale_uint8_decimal": [127], "scale_exponent_after_bias": [0], "nibble_rule": "input[2*i] is bits 0..3; input[2*i+1] is bits 4..7"}123version https://git-lfs.github.com/spec/v1oid sha256:5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018fsize 20560123version https://git-lfs.github.com/spec/v1oid sha256:33f73333341f7a86b6a44d273581a096bed789d927a90ce7411d43c0437748bbsize 77952123version https://git-lfs.github.com/spec/v1oid sha256:5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018fsize 2056012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182{ "prompt": "Once upon a time,", "prompt_token_ids": [ 430, 446, 258, 395, 11 ], "generated_token_ids": [ 399, 281, 258, 396, 445, 499, 363, 13, 312, 502, 265, 358, 677, 315, 262, 732, 13, 505, 355, 11, 337, 412, 258, 406, 11, 969, 304, 288, 315, 262, 861, 13, 408, 281, 258, 396, 969, 304, 288, 341, 258, 969, 935, 409, 83, 13, 198, 198, 342, 443, 265, 265, 84, 374, 262, 304, 288, 11, 409, 337, 662, 422, 694, 711 ], "generated_text": " there was a little girl named Lily. She loved to play outside in the sun. One day, she saw a big, shiny thing in the sky. It was a little shiny thing with a shiny red butt.\n\nLily wanted to touch the thing, but she didn't know how", "full_text": "Once upon a time, there was a little girl named Lily. She loved to play outside in the sun. One day, she saw a big, shiny thing in the sky. It was a little shiny thing with a shiny red butt.\n\nLily wanted to touch the thing, but she didn't know how", "greedy": true, "max_new_tokens": 64, "eos_token_id": 1001, "stopped_on_eos": false}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970{ "checkpoint_model_sha256": "30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d", "official_openai_revision": "599476783c6f88508dab8577808b5ead5cbee8d2", "triton_kernels_revision": "9e1e203f64752cf99abf0e44286231c5d5df7e76", "device": "NVIDIA GeForce RTX 5060 Ti", "device_capability": [ 12, 0 ], "torch_version": "2.8.0+cu128", "triton_version": "3.4.0", "reproduction_command": "CUDA_VISIBLE_DEVICES=<gpu> PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels python tools/generate_gptoss_mxfp4_reference.py --checkpoint original --tokenizer hf --output-dir rebuilt/mxfp4_reference_outputs --openai-repo third_party/openai-gpt-oss --triton-repo third_party/triton --prompt 'Once upon a time,' --max-new-tokens 64 --context 256 --device cuda:0", "prompt": "Once upon a time,", "prompt_token_ids": [ 430, 446, 258, 395, 11 ], "logits_shape": [ 1, 5, 1024 ], "output_provenance": { "full_logits": "gpt_oss.triton.model.Transformer full-sequence forward", "cached_logits": "gpt_oss.triton.model.Transformer with per-layer Cache", "greedy_continuation": "gpt_oss.triton.model.Transformer with per-layer Cache", "routing": "gpt_oss.torch.model.Transformer MoE equations", "expert_projection": "gpt_oss.torch.model.Transformer MoE equations" }, "full_vs_cached": { "max_abs_diff": 0.0, "mean_abs_diff": 0.0, "all_token_argmax_equal": true }, "triton_full_vs_torch_full": { "max_abs_diff": 0.4375, "mean_abs_diff": 0.0456787645816803, "all_token_argmax_equal": true }, "routing": { "layers": 6, "tokens": 5, "experts_per_token": 4, "includes_router_logits": true }, "expert_projection": { "selected_output_shape_per_layer": [ 5, 4, 128 ], "includes_weighted_sum": true }, "tiny_attention_adapter": { "gqa_axis_adapter": "transpose query dimensions 2 and 3", "attention_backend": "gpt_oss.triton.attention.attention_ref", "reason": "tiny config uses 1 KV head, 4 groups, and head_dim 32", "official_source_modified": false }, "files": { "full_logits.safetensors": "5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f", "cached_logits.safetensors": "5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f", "routing.safetensors": "f94ffb12b3da2c922fc7e95134603e155fd06046dbaba9610360e8aea2d58311", "expert_projection.safetensors": "33f73333341f7a86b6a44d273581a096bed789d927a90ce7411d43c0437748bb", "greedy_continuation.json": "1478ed0112bf32f0444a5dd1bae9eeaebe2cc751396d1fe92513e6e208984b2d" }}123version https://git-lfs.github.com/spec/v1oid sha256:f94ffb12b3da2c922fc7e95134603e155fd06046dbaba9610360e8aea2d58311size 3840123456789101112131415161718{ "num_hidden_layers": 6, "num_experts": 8, "experts_per_token": 4, "vocab_size": 1024, "hidden_size": 128, "intermediate_size": 128, "swiglu_limit": 7.0, "head_dim": 32, "num_attention_heads": 4, "num_key_value_heads": 1, "sliding_window": 128, "initial_context_length": 1024, "rope_theta": 150000.0, "rope_scaling_factor": 4.0, "rope_ntk_alpha": 1.0, "rope_ntk_beta": 32.0}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253{ "format": "openai-gpt-oss-original-mxfp4", "source": { "repository": "shibatch/tinygptossmoe3m", "subfolder": "hf", "model_sha256": "baf06470d796cf7cc3cbb74e0cc176940ca45b2889cc9080640243c563f810cb", "config_sha256": "7d68c391baabd2a64ccb6c381c0d7c98ad5f6389871d45491ad2c70ef4091637" }, "official_implementation": { "repository": "https://github.com/openai/gpt-oss.git", "revision": "599476783c6f88508dab8577808b5ead5cbee8d2" }, "official_quantizer_dependency": { "repository": "https://github.com/triton-lang/triton.git", "revision": "9e1e203f64752cf99abf0e44286231c5d5df7e76", "api": "triton_kernels.numerics_details.mxfp.downcast_to_mxfp_torch", "rounding_mode": "DequantScaleRoundingMode.ROUND_DOWN" }, "conversion_environment": { "python": "3.13.7", "torch": "2.8.0+cu128", "triton": "3.4.0", "safetensors": "0.8.0" }, "reproduction_command": "PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels python tools/convert_tinygptoss_to_mxfp4.py --source-dir hf --output-dir rebuilt/original --openai-repo third_party/openai-gpt-oss --triton-repo third_party/triton", "official_profile_reference": { "repository": "openai/gpt-oss-20b", "revision": "6cee5e81ee83917806bbde320786a8fb61efebee", "config_sha256": "317522155fc243327ee341857d0c752d0094a0817e0e9aee2890d5ad8e009e04", "dtypes_sha256": "566c9e6aded8957f41f1589cabaf73e39f2d1fcda3351d63efdfb7e9e78d376b" }, "profile": { "expert_weights": [ "mlp1_weight", "mlp2_weight" ], "expert_value_format": "E2M1", "expert_scale_format": "E8M0", "block_size": 32, "values_per_byte": 2, "nibble_order": "low-nibble-first", "scale_bias": 127, "non_expert_dtype": "BF16" }, "outputs": { "model_sha256": "30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d", "config_sha256": "f9be3908850cc3def17375cbbae101c1b6ee801b4db7315489dbe6f513d4affe", "dtypes_sha256": "fa36ec5d12a062717c28c7bb53535e1e29d70ea1b41e32c8ec137888df2309c8", "tensor_inventory_sha256": "99d24cda1c1441cc3ff04776a618e432b3e3f3ba6ddd33bc2b9342d2ca3b68a5", "tensor_count": 93, "total_tensor_bytes": 2325648 }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495{ "embedding.weight": "BF16", "block.0.attn.norm.scale": "BF16", "block.0.attn.qkv.weight": "BF16", "block.0.attn.qkv.bias": "BF16", "block.0.attn.sinks": "BF16", "block.0.attn.out.weight": "BF16", "block.0.attn.out.bias": "BF16", "block.0.mlp.norm.scale": "BF16", "block.0.mlp.gate.weight": "BF16", "block.0.mlp.gate.bias": "BF16", "block.0.mlp.mlp1_weight.blocks": "FP4", "block.0.mlp.mlp1_weight.scales": "UE8", "block.0.mlp.mlp1_bias": "BF16", "block.0.mlp.mlp2_weight.blocks": "FP4", "block.0.mlp.mlp2_weight.scales": "UE8", "block.0.mlp.mlp2_bias": "BF16", "block.1.attn.norm.scale": "BF16", "block.1.attn.qkv.weight": "BF16", "block.1.attn.qkv.bias": "BF16", "block.1.attn.sinks": "BF16", "block.1.attn.out.weight": "BF16", "block.1.attn.out.bias": "BF16", "block.1.mlp.norm.scale": "BF16", "block.1.mlp.gate.weight": "BF16", "block.1.mlp.gate.bias": "BF16", "block.1.mlp.mlp1_weight.blocks": "FP4", "block.1.mlp.mlp1_weight.scales": "UE8", "block.1.mlp.mlp1_bias": "BF16", "block.1.mlp.mlp2_weight.blocks": "FP4", "block.1.mlp.mlp2_weight.scales": "UE8", "block.1.mlp.mlp2_bias": "BF16", "block.2.attn.norm.scale": "BF16", "block.2.attn.qkv.weight": "BF16", "block.2.attn.qkv.bias": "BF16", "block.2.attn.sinks": "BF16", "block.2.attn.out.weight": "BF16", "block.2.attn.out.bias": "BF16", "block.2.mlp.norm.scale": "BF16", "block.2.mlp.gate.weight": "BF16", "block.2.mlp.gate.bias": "BF16", "block.2.mlp.mlp1_weight.blocks": "FP4", "block.2.mlp.mlp1_weight.scales": "UE8", "block.2.mlp.mlp1_bias": "BF16", "block.2.mlp.mlp2_weight.blocks": "FP4", "block.2.mlp.mlp2_weight.scales": "UE8", "block.2.mlp.mlp2_bias": "BF16", "block.3.attn.norm.scale": "BF16", "block.3.attn.qkv.weight": "BF16", "block.3.attn.qkv.bias": "BF16", "block.3.attn.sinks": "BF16", "block.3.attn.out.weight": "BF16", "block.3.attn.out.bias": "BF16", "block.3.mlp.norm.scale": "BF16", "block.3.mlp.gate.weight": "BF16", "block.3.mlp.gate.bias": "BF16", "block.3.mlp.mlp1_weight.blocks": "FP4", "block.3.mlp.mlp1_weight.scales": "UE8", "block.3.mlp.mlp1_bias": "BF16", "block.3.mlp.mlp2_weight.blocks": "FP4", "block.3.mlp.mlp2_weight.scales": "UE8", "block.3.mlp.mlp2_bias": "BF16", "block.4.attn.norm.scale": "BF16", "block.4.attn.qkv.weight": "BF16", "block.4.attn.qkv.bias": "BF16", "block.4.attn.sinks": "BF16", "block.4.attn.out.weight": "BF16", "block.4.attn.out.bias": "BF16", "block.4.mlp.norm.scale": "BF16", "block.4.mlp.gate.weight": "BF16", "block.4.mlp.gate.bias": "BF16", "block.4.mlp.mlp1_weight.blocks": "FP4", "block.4.mlp.mlp1_weight.scales": "UE8", "block.4.mlp.mlp1_bias": "BF16", "block.4.mlp.mlp2_weight.blocks": "FP4", "block.4.mlp.mlp2_weight.scales": "UE8", "block.4.mlp.mlp2_bias": "BF16", "block.5.attn.norm.scale": "BF16", "block.5.attn.qkv.weight": "BF16", "block.5.attn.qkv.bias": "BF16", "block.5.attn.sinks": "BF16", "block.5.attn.out.weight": "BF16", "block.5.attn.out.bias": "BF16", "block.5.mlp.norm.scale": "BF16", "block.5.mlp.gate.weight": "BF16", "block.5.mlp.gate.bias": "BF16", "block.5.mlp.mlp1_weight.blocks": "FP4", "block.5.mlp.mlp1_weight.scales": "UE8", "block.5.mlp.mlp1_bias": "BF16", "block.5.mlp.mlp2_weight.blocks": "FP4", "block.5.mlp.mlp2_weight.scales": "UE8", "block.5.mlp.mlp2_bias": "BF16", "norm.scale": "BF16", "unembedding.weight": "BF16"}123version https://git-lfs.github.com/spec/v1oid sha256:30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09dsize 233405612345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121{ "tensor_count": 93, "total_tensor_bytes": 2325648, "tensors": [ { "name": "block.0.attn.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "eccf6206b565034cbae911aefab9c5a7dc483288cafd3f454089bc37ea39334d" }, { "name": "block.0.attn.out.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "c3f9fca0599156bb298857bcb3085fda3f768064d702bd1b8014cf532bd9f715" }, { "name": "block.0.attn.out.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128, 128 ], "numel": 16384, "nbytes": 32768, "tensor_sha256": "d95bf0cad74e0854831f86981303760e10ec3c2f4ccf4b027b145b8d251a51c3" }, { "name": "block.0.attn.qkv.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192 ], "numel": 192, "nbytes": 384, "tensor_sha256": "87074fba354a69d4c62022329006b2013c49686bc497b126e20f3a8e71fd1e9b" }, { "name": "block.0.attn.qkv.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192, 128 ], "numel": 24576, "nbytes": 49152, "tensor_sha256": "e1944b4f33dafdf6f86d59a78aa6093a20c71c5ca044be20992bb9df146ba1cc" }, { "name": "block.0.attn.sinks", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 4 ], "numel": 4, "nbytes": 8, "tensor_sha256": "295ddf9b80c106900373a47e8bc3283c7d46496cb85a80ce9beecf919bffa36d" }, { "name": "block.0.mlp.gate.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8 ], "numel": 8, "nbytes": 16, "tensor_sha256": "a39a0ec9a48054ed024cf42fd0348cf417b140f67a2c35657fd4e927a0db0e72" }, { "name": "block.0.mlp.gate.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "4bd377300b228d0fdfec98a8d48fbb37e4f86cddfb20333dd063162d30b4d327" }, { "name": "block.0.mlp.mlp1_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 256 ], "numel": 2048, "nbytes": 4096, "tensor_sha256": "d9a0ab2d73984206682035017d3cd8fe5a775059df2d9ac1f595af5ec2bc9ebd" }, { "name": "block.0.mlp.mlp1_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 256, 4, 16 ], "numel": 131072, "nbytes": 131072, "tensor_sha256": "d0ac79ceb22dc812565c5ba380d391b03dc8ca5294827eadc479c880543aacee" }, { "name": "block.0.mlp.mlp1_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 256, 4 ], "numel": 8192, "nbytes": 8192, "tensor_sha256": "90262d9132d9834b218ab379ba3edf958c880ffc604f3b45cb8bbb0d90d33130" }, { "name": "block.0.mlp.mlp2_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "449d510ec646b8bcc3a79ed5f71a7161c3e56f6db720bc4accf91c93e91a41e3" }, { "name": "block.0.mlp.mlp2_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 128, 4, 16 ], "numel": 65536, "nbytes": 65536, "tensor_sha256": "5e5dc1deac2d388d49843cc7585b6ae14ad51bbe623102e4a225dfa3e38b6f8d" }, { "name": "block.0.mlp.mlp2_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 128, 4 ], "numel": 4096, "nbytes": 4096, "tensor_sha256": "ac8cb8c5ef0cf4d742f23d9b054fd08b6dd4b9f74838631d42c3090ef585cbdd" }, { "name": "block.0.mlp.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "b63ff56f26e563de022aab5369580eda5d74578a5f22cc9dd56bf6db0f1d7082" }, { "name": "block.1.attn.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "83cf4c38d54a727a4c7fb56ae3cc75ecff6bcf9ead14607ada8b0be293eec882" }, { "name": "block.1.attn.out.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "fbfa71e7dc3809307c8501fec973d7a1ab81ebedcbbb4b1b9b40cec5522f70d5" }, { "name": "block.1.attn.out.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128, 128 ], "numel": 16384, "nbytes": 32768, "tensor_sha256": "6dd7263990966265cb55a5e8ea08a72853c012a9e64248d907699d28a862fb51" }, { "name": "block.1.attn.qkv.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192 ], "numel": 192, "nbytes": 384, "tensor_sha256": "5e1e38393fa6ab1456475ae99c4f39dace4c2a2f6a60de0d66685fb633d00d8e" }, { "name": "block.1.attn.qkv.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192, 128 ], "numel": 24576, "nbytes": 49152, "tensor_sha256": "d10d95738b787c9f0f4e40c8889a734e91e010b94631aa4b0430d9f29d606d4d" }, { "name": "block.1.attn.sinks", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 4 ], "numel": 4, "nbytes": 8, "tensor_sha256": "a117079fbf84f8c53350f712ee5ec94f14ef7f60310448c1c52c08b481f44ba2" }, { "name": "block.1.mlp.gate.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8 ], "numel": 8, "nbytes": 16, "tensor_sha256": "e5af7ddf38f2ae2b2cb5afeaeac8ffd8ae4db992998f0e9bdd08471de8386f00" }, { "name": "block.1.mlp.gate.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "8e5c37e0f732ce2bb0810948716dc8efb24959cd60f3fc36bab8e5c0054000d4" }, { "name": "block.1.mlp.mlp1_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 256 ], "numel": 2048, "nbytes": 4096, "tensor_sha256": "ead631eded681e83c149d5ad987504ef57d4d852698b1e332f50e937bf61ce2b" }, { "name": "block.1.mlp.mlp1_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 256, 4, 16 ], "numel": 131072, "nbytes": 131072, "tensor_sha256": "e87b455f4612e44c79fc1a6af39899f6773beee29d2477ae4dbb8b5d514c3dcd" }, { "name": "block.1.mlp.mlp1_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 256, 4 ], "numel": 8192, "nbytes": 8192, "tensor_sha256": "7ec5077d46ca6072fc767e945f3de37522182e754732dc2230fa972dc416c5c8" }, { "name": "block.1.mlp.mlp2_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "61febd0af1c19417497e9d0db0cf6063fe5f581c4232197ac5d17d59685e32ff" }, { "name": "block.1.mlp.mlp2_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 128, 4, 16 ], "numel": 65536, "nbytes": 65536, "tensor_sha256": "66df91b2652cf14f96f2b1542ad45d3c6742b3d4986f347493d4b9cf52c5e8ac" }, { "name": "block.1.mlp.mlp2_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 128, 4 ], "numel": 4096, "nbytes": 4096, "tensor_sha256": "91d42170629b6c5ddd387ddd24cd59ea6b434ed567c081c54d858aa8e4558ba7" }, { "name": "block.1.mlp.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "68363b0cc5e0c20ff11f9b0107039584f3aa8bb166779428f6df0b6f3f562fee" }, { "name": "block.2.attn.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "6e2b8342c7466915587ff9d08464018674d63e0cec5bfdeae8b9268cf12b6de8" }, { "name": "block.2.attn.out.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "366efbc20599e24880cb6cb7104caf9b795a879d0b3a04486353b2ca402ef1b1" }, { "name": "block.2.attn.out.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128, 128 ], "numel": 16384, "nbytes": 32768, "tensor_sha256": "566031b008db7b923f19583f172c30ec6ba016cc542c696bb28d3f7fc5ab589e" }, { "name": "block.2.attn.qkv.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192 ], "numel": 192, "nbytes": 384, "tensor_sha256": "f1098142b9f8e484df961e76053c0e5185643d91808fc0b36eb6bc0f5b03175a" }, { "name": "block.2.attn.qkv.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192, 128 ], "numel": 24576, "nbytes": 49152, "tensor_sha256": "e4711d5191b1858069796141f4c39c384bf45f62f6d2386bb81d6af13ea4b53b" }, { "name": "block.2.attn.sinks", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 4 ], "numel": 4, "nbytes": 8, "tensor_sha256": "92dfb6f47e247ad094f13290f11fc41e788f4b9f9ace9dd69151bf77701da41e" }, { "name": "block.2.mlp.gate.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8 ], "numel": 8, "nbytes": 16, "tensor_sha256": "a25f01749a28dcb48c5b1bba82915073fc0725405167bc48e65a5f1c5168650a" }, { "name": "block.2.mlp.gate.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "d6a5332f558e60c6ab499182817dbb69be4d5ccc54f49c26ab0ac2e41688c9b3" }, { "name": "block.2.mlp.mlp1_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 256 ], "numel": 2048, "nbytes": 4096, "tensor_sha256": "62283e7f26a3806807c9ac37e2e3fdb0cce7775227db14c66a1414f6fed89c53" }, { "name": "block.2.mlp.mlp1_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 256, 4, 16 ], "numel": 131072, "nbytes": 131072, "tensor_sha256": "022584a26dd938b7659332af69b2047539911c800b08474ba9e5ab2bdc784300" }, { "name": "block.2.mlp.mlp1_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 256, 4 ], "numel": 8192, "nbytes": 8192, "tensor_sha256": "e380540cad368470ffabf8725de2d74d56d3fc05117a36218ba9a1df73e21788" }, { "name": "block.2.mlp.mlp2_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "ff9e10da6f5e16f91876ef5724e9825f6a59e057e063fbf51bd0850d0524d694" }, { "name": "block.2.mlp.mlp2_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 128, 4, 16 ], "numel": 65536, "nbytes": 65536, "tensor_sha256": "178904bea25592b069946c8cadd1301715ef0a5c8082ba0d9f817e039c991d63" }, { "name": "block.2.mlp.mlp2_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 128, 4 ], "numel": 4096, "nbytes": 4096, "tensor_sha256": "d84dcdd10ce6ee20c75b3a46cf29540dfc4c5f223d69321897f59bd681ba8515" }, { "name": "block.2.mlp.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "be8f537c77171cbcbefbd987ff1501ae5bed6fb883c16d6a34b698876f1ee3b4" }, { "name": "block.3.attn.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "a63a9daec9ce2d3eeac2fbbeae74b0138e6ba1ab9dda9ad4fa2554e0c2ca2de1" }, { "name": "block.3.attn.out.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "342ea41e39091ddea3dceb699eae5a3f06b2d925bbc4c67ad9886d9caa4d53da" }, { "name": "block.3.attn.out.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128, 128 ], "numel": 16384, "nbytes": 32768, "tensor_sha256": "057794a40c48b05ad393b17db48203dbcb28cb67f2060645f02a98a6c6829f1c" }, { "name": "block.3.attn.qkv.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192 ], "numel": 192, "nbytes": 384, "tensor_sha256": "856e44029cca502df4abbc3995a1470ee25fb33f39890136806af561beb9088e" }, { "name": "block.3.attn.qkv.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192, 128 ], "numel": 24576, "nbytes": 49152, "tensor_sha256": "e56cc7e6c0e132cea4fa41cf4815d742521974bc10d67154faea7a50f69dcad4" }, { "name": "block.3.attn.sinks", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 4 ], "numel": 4, "nbytes": 8, "tensor_sha256": "61cb27dc684d0a0547f12e76b164aa50ace8f3d63ba6c830da694c92fa5f097b" }, { "name": "block.3.mlp.gate.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8 ], "numel": 8, "nbytes": 16, "tensor_sha256": "2a05530d4e67ca5c305a49f2b4f3dfa35214d2d6bf2980b1d39deb62c4696b1c" }, { "name": "block.3.mlp.gate.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "0254ec6589ab9894a11d4b7fe11900dba9f5715aa7f1a29dfc5aad6c7fbdb01e" }, { "name": "block.3.mlp.mlp1_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 256 ], "numel": 2048, "nbytes": 4096, "tensor_sha256": "a4b8b349adfaf60be1e8f5dd89cb9dc236e596c6045f7d3bdd7573e0fdcca4e9" }, { "name": "block.3.mlp.mlp1_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 256, 4, 16 ], "numel": 131072, "nbytes": 131072, "tensor_sha256": "ad0f0d6726de843bf2c766a40b1fd3f3ea5f0844bce9238193455b3ada7357cc" }, { "name": "block.3.mlp.mlp1_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 256, 4 ], "numel": 8192, "nbytes": 8192, "tensor_sha256": "63973340238aceb7e6158b3b2a1b227bac28ab2924a07e16f25cfa4ea03e0e72" }, { "name": "block.3.mlp.mlp2_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "b4c9587a5885563ff92e98626e16e859bab5ca2a22061fb0eb4a478def07ed97" }, { "name": "block.3.mlp.mlp2_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 128, 4, 16 ], "numel": 65536, "nbytes": 65536, "tensor_sha256": "8c8ce501f6b10800c56f9053a71e3aadc4ea2cdbd1cdf711ac70f39e9b2493e5" }, { "name": "block.3.mlp.mlp2_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 128, 4 ], "numel": 4096, "nbytes": 4096, "tensor_sha256": "ced5ca3bc9bf9bf8060326484a79514cb17478b54a056b6bade9c936af146726" }, { "name": "block.3.mlp.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "e3f47dc61b2798a760d584319069246b56891571eadd2a51ee8fadc1fc83aac0" }, { "name": "block.4.attn.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "411109db41ab85e6668a07b60509aa321745699e7c2acbba38ed6b2cb77b99d9" }, { "name": "block.4.attn.out.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "1d145798ca557f230c7a5559243173723ac013b408dca1a5af37ae95f81fcd40" }, { "name": "block.4.attn.out.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128, 128 ], "numel": 16384, "nbytes": 32768, "tensor_sha256": "8af8f74e0b4a220b62680b3a26d429a531bd7db70b5a1d77cf7cb4895eb72484" }, { "name": "block.4.attn.qkv.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192 ], "numel": 192, "nbytes": 384, "tensor_sha256": "6dee9f3beeef2fe7699ad3d6297b97a86be3fb42761141c2301018fa95710a74" }, { "name": "block.4.attn.qkv.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192, 128 ], "numel": 24576, "nbytes": 49152, "tensor_sha256": "a7669d41f636b05f66d4e3ab3db8a7e8e1584cba7915dc930226760a63f9cf28" }, { "name": "block.4.attn.sinks", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 4 ], "numel": 4, "nbytes": 8, "tensor_sha256": "e4876b0316d2a8ef7f4e3fa6dcdfb7b04114d8a0f8aedc8605a3f8d1ef0e83cf" }, { "name": "block.4.mlp.gate.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8 ], "numel": 8, "nbytes": 16, "tensor_sha256": "a46518dc141801777ea50b8723d71cfebb64c4f0524b54e8d553b52f7439135c" }, { "name": "block.4.mlp.gate.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "c6b3682df23d9c07674962210066010f90755836d948c437561b933e1d168e8b" }, { "name": "block.4.mlp.mlp1_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 256 ], "numel": 2048, "nbytes": 4096, "tensor_sha256": "22ee8aaffbdb4421b6cd54a7ed58d6f439567c7e7c443a52e95bcc084b74edab" }, { "name": "block.4.mlp.mlp1_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 256, 4, 16 ], "numel": 131072, "nbytes": 131072, "tensor_sha256": "a50822355f9c1b4c625294f6f0ba162e09c6ca4b308dc9b52a5d5311682dde25" }, { "name": "block.4.mlp.mlp1_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 256, 4 ], "numel": 8192, "nbytes": 8192, "tensor_sha256": "b9d1b50f963382e1ed34355421c8091642183d0856482149cbef32f4f32627ef" }, { "name": "block.4.mlp.mlp2_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "c6bde1e2894a2a4ea5555faccdea0f1787ad56f39acb552e1097dfda3b91d1a6" }, { "name": "block.4.mlp.mlp2_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 128, 4, 16 ], "numel": 65536, "nbytes": 65536, "tensor_sha256": "2b9f453cac8c3bc740b552cfcdf5dac414d4ecf5594bf5cc7ba72bd5135f9595" }, { "name": "block.4.mlp.mlp2_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 128, 4 ], "numel": 4096, "nbytes": 4096, "tensor_sha256": "51f2aed84152cd33655ecc33bc1aaf895955ab01b90c28540d8fcaeaa4b2c75c" }, { "name": "block.4.mlp.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "c583f057e81a175b0f8faebba532f0b775138c3b29019fd8d28685d3ebfb9b6c" }, { "name": "block.5.attn.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "89676d9c580766cfd9172b5d7050cb43628e127102ab766a18ddcb7235093620" }, { "name": "block.5.attn.out.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "a9d2eea381c89d51d7c96374e9c0e2cb082b87783aee002e62d86065eecc0fb2" }, { "name": "block.5.attn.out.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128, 128 ], "numel": 16384, "nbytes": 32768, "tensor_sha256": "f2ca3c84225d7acf3386a7c3d4a9b07b2d717f379b645564a8a84137199b07e1" }, { "name": "block.5.attn.qkv.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192 ], "numel": 192, "nbytes": 384, "tensor_sha256": "e0ad88cc16c2daf0db1dfe0d6909fea440fa304d9b716cc1cc445276765d71d9" }, { "name": "block.5.attn.qkv.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 192, 128 ], "numel": 24576, "nbytes": 49152, "tensor_sha256": "81d4cfba44bab6d7914f27ab61896bcc84a2d814059ce000f5e12657d4a41866" }, { "name": "block.5.attn.sinks", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 4 ], "numel": 4, "nbytes": 8, "tensor_sha256": "16e389e81866d6ec7e85ad3e2dd70e714428f4d92f5be84fca0b5e518ee33325" }, { "name": "block.5.mlp.gate.bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8 ], "numel": 8, "nbytes": 16, "tensor_sha256": "e913d05270793f26e74da05493c26165a8ce46afb19f44031d109db53ac341a7" }, { "name": "block.5.mlp.gate.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "782d4ddcc67b12bda908b0a4355b468df94e87d576ceae9db61bf35e5fc11f0b" }, { "name": "block.5.mlp.mlp1_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 256 ], "numel": 2048, "nbytes": 4096, "tensor_sha256": "1280153cf4f5b8d1a248abb7a080f8770792f58e5374ff1a3d0a16f04e38f191" }, { "name": "block.5.mlp.mlp1_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 256, 4, 16 ], "numel": 131072, "nbytes": 131072, "tensor_sha256": "19c88563037e63e3d3ebb0fd9ba6edbba2b9b4ad1ae314fccfe44a396e8ab904" }, { "name": "block.5.mlp.mlp1_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 256, 4 ], "numel": 8192, "nbytes": 8192, "tensor_sha256": "f7ddf93e3c0ab64ef3224f8e3ea6047c9e37681302e2a0f256784839059fa422" }, { "name": "block.5.mlp.mlp2_bias", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 8, 128 ], "numel": 1024, "nbytes": 2048, "tensor_sha256": "368c68c9d3b6d499d1dc53ad5f1b730817a589554af94bf6bf6334636977634f" }, { "name": "block.5.mlp.mlp2_weight.blocks", "profile_dtype": "FP4", "storage_dtype": "uint8", "shape": [ 8, 128, 4, 16 ], "numel": 65536, "nbytes": 65536, "tensor_sha256": "896d96385e51bed7a0ccd2538525787564ad235f32d7ee389d02f6dd5dba7efe" }, { "name": "block.5.mlp.mlp2_weight.scales", "profile_dtype": "UE8", "storage_dtype": "uint8", "shape": [ 8, 128, 4 ], "numel": 4096, "nbytes": 4096, "tensor_sha256": "e6d33e18970c9a8ba0ab4862464ed1e88b61519b4d9637ff2acc405d7cd28aae" }, { "name": "block.5.mlp.norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "50323ecbb641619272668d71d2c2bdd0b2c59048bf4dba9913fa136faa6a0454" }, { "name": "embedding.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 1024, 128 ], "numel": 131072, "nbytes": 262144, "tensor_sha256": "175c0ba5dab18fbf041cdb19362eed8820aec016a83b7dd144e965d5c0869f07" }, { "name": "norm.scale", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 128 ], "numel": 128, "nbytes": 256, "tensor_sha256": "8740cb20ea1a531ef2f4cf3c5e3244d108727c24b48050f51a5ba63131082906" }, { "name": "unembedding.weight", "profile_dtype": "BF16", "storage_dtype": "bfloat16", "shape": [ 1024, 128 ], "numel": 131072, "nbytes": 262144, "tensor_sha256": "27061dff957ec99df5ccbc99fe4aa89c6645676611fbbf2bcdd80203c5fda931" } ]}1234567torch==2.8.0triton==3.4.0safetensors==0.8.0tokenizers==0.22.2numpy==2.5.1pytest==9.1.1huggingface_hub==1.26.0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337#!/usr/bin/env python3"""Convert the tiny HF gpt-oss checkpoint to the official MXFP4 profile."""
from __future__ import annotations
import argparseimport hashlibimport jsonimport platformimport subprocessimport sysfrom pathlib import Path
import torchfrom safetensors.torch import load_file, save_file
OPENAI_GPT_OSS_REVISION = "599476783c6f88508dab8577808b5ead5cbee8d2"TRITON_KERNELS_REVISION = "9e1e203f64752cf99abf0e44286231c5d5df7e76"OFFICIAL_PROFILE_REPO = "openai/gpt-oss-20b"OFFICIAL_PROFILE_REVISION = "6cee5e81ee83917806bbde320786a8fb61efebee"OFFICIAL_PROFILE_CONFIG_SHA256 = "317522155fc243327ee341857d0c752d0094a0817e0e9aee2890d5ad8e009e04"OFFICIAL_PROFILE_DTYPES_SHA256 = "566c9e6aded8957f41f1589cabaf73e39f2d1fcda3351d63efdfb7e9e78d376b"BLOCK_SIZE = 32PACKED_BYTES_PER_BLOCK = 16
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--source-dir", type=Path, required=True) parser.add_argument("--output-dir", type=Path, required=True) parser.add_argument("--openai-repo", type=Path, required=True) parser.add_argument("--triton-repo", type=Path, required=True) return parser.parse_args()
def sha256_file(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as handle: for chunk in iter(lambda: handle.read(1024 * 1024), b""): digest.update(chunk) return digest.hexdigest()
def git_revision(path: Path) -> str: return subprocess.check_output( ["git", "-C", str(path), "rev-parse", "HEAD"], text=True, ).strip()
def require_revision(path: Path, expected: str, label: str) -> None: actual = git_revision(path) if actual != expected: raise RuntimeError(f"{label} revision mismatch: expected {expected}, got {actual}")
def import_official_quantizer(openai_repo: Path, triton_repo: Path): sys.path.insert(0, str(openai_repo.resolve())) sys.path.insert(0, str((triton_repo / "python" / "triton_kernels").resolve())) from triton_kernels.numerics_details.mxfp import ( # noqa: PLC0415 DequantScaleRoundingMode, downcast_to_mxfp_torch, )
return downcast_to_mxfp_torch, DequantScaleRoundingMode
def validate_source_config(config: dict) -> None: layers = config["num_hidden_layers"] expected_layer_types = [ "sliding_attention" if i % 2 == 0 else "full_attention" for i in range(layers) ] checks = { "model_type": config.get("model_type") == "gpt_oss", "alternating layer types": config.get("layer_types") == expected_layer_types, "attention bias": config.get("attention_bias") is True, "untied embeddings": config.get("tie_word_embeddings") is False, "RMSNorm epsilon": config.get("rms_norm_eps") == 1e-5, "hidden size block alignment": config["hidden_size"] % BLOCK_SIZE == 0, "intermediate size block alignment": config["intermediate_size"] % BLOCK_SIZE == 0, } failures = [name for name, passed in checks.items() if not passed] if failures: raise ValueError("Source is incompatible with the official profile: " + ", ".join(failures))
def official_config(source: dict) -> dict: rope = source["rope_parameters"] return { "num_hidden_layers": source["num_hidden_layers"], "num_experts": source["num_local_experts"], "experts_per_token": source["num_experts_per_tok"], "vocab_size": source["vocab_size"], "hidden_size": source["hidden_size"], "intermediate_size": source["intermediate_size"], "swiglu_limit": source["swiglu_limit"], "head_dim": source["head_dim"], "num_attention_heads": source["num_attention_heads"], "num_key_value_heads": source["num_key_value_heads"], "sliding_window": source["sliding_window"], "initial_context_length": source["initial_context_length"], "rope_theta": rope["rope_theta"], "rope_scaling_factor": rope["factor"], "rope_ntk_alpha": rope["beta_slow"], "rope_ntk_beta": rope["beta_fast"], }
def to_bf16(tensor: torch.Tensor) -> torch.Tensor: if not torch.isfinite(tensor).all(): raise ValueError("Source tensor contains non-finite values") return tensor.to(torch.bfloat16).contiguous()
def quantize_expert_weight( tensor: torch.Tensor, downcast_to_mxfp_torch, rounding_mode,) -> tuple[torch.Tensor, torch.Tensor]: if tensor.shape[-1] % BLOCK_SIZE: raise ValueError(f"MXFP4 axis must be divisible by {BLOCK_SIZE}: {tuple(tensor.shape)}") if not torch.isfinite(tensor).all(): raise ValueError("Source expert tensor contains non-finite values")
flat_blocks, scales = downcast_to_mxfp_torch( tensor.contiguous(), torch.uint8, -1, rounding_mode.ROUND_DOWN, ) expected_flat = tensor.shape[-1] // 2 if flat_blocks.shape[-1] != expected_flat: raise RuntimeError(f"Unexpected packed shape: {tuple(flat_blocks.shape)}") blocks = flat_blocks.reshape( *tensor.shape[:-1], tensor.shape[-1] // BLOCK_SIZE, PACKED_BYTES_PER_BLOCK, ).contiguous() expected_scales = (*tensor.shape[:-1], tensor.shape[-1] // BLOCK_SIZE) if tuple(scales.shape) != expected_scales: raise RuntimeError(f"Unexpected scale shape: {tuple(scales.shape)} != {expected_scales}") return blocks, scales.contiguous()
def tensor_bytes(tensor: torch.Tensor) -> bytes: return tensor.detach().cpu().contiguous().view(torch.uint8).numpy().tobytes()
def make_inventory(tensors: dict[str, torch.Tensor], dtypes: dict[str, str]) -> dict: entries = [] total_bytes = 0 for name in sorted(tensors): tensor = tensors[name] raw = tensor_bytes(tensor) total_bytes += len(raw) entries.append( { "name": name, "profile_dtype": dtypes[name], "storage_dtype": str(tensor.dtype).removeprefix("torch."), "shape": list(tensor.shape), "numel": tensor.numel(), "nbytes": len(raw), "tensor_sha256": hashlib.sha256(raw).hexdigest(), } ) return { "tensor_count": len(entries), "total_tensor_bytes": total_bytes, "tensors": entries, }
def main() -> None: args = parse_args() source_dir = args.source_dir.resolve() output_dir = args.output_dir.resolve() openai_repo = args.openai_repo.resolve() triton_repo = args.triton_repo.resolve()
require_revision(openai_repo, OPENAI_GPT_OSS_REVISION, "OpenAI gpt-oss") require_revision(triton_repo, TRITON_KERNELS_REVISION, "Triton kernels") downcast_to_mxfp_torch, rounding_mode = import_official_quantizer(openai_repo, triton_repo)
source_config_path = source_dir / "config.json" source_model_path = source_dir / "model.safetensors" source_config = json.loads(source_config_path.read_text(encoding="utf-8")) validate_source_config(source_config) state = load_file(source_model_path, device="cpu")
tensors: dict[str, torch.Tensor] = {} dtypes: dict[str, str] = {}
def add_bf16(name: str, value: torch.Tensor) -> None: tensors[name] = to_bf16(value) dtypes[name] = "BF16"
def add_mxfp4(name: str, value: torch.Tensor) -> None: blocks, scales = quantize_expert_weight( value, downcast_to_mxfp_torch, rounding_mode, ) tensors[f"{name}.blocks"] = blocks tensors[f"{name}.scales"] = scales dtypes[f"{name}.blocks"] = "FP4" dtypes[f"{name}.scales"] = "UE8"
add_bf16("embedding.weight", state["model.embed_tokens.weight"]) for layer in range(source_config["num_hidden_layers"]): src = f"model.layers.{layer}" dst = f"block.{layer}" add_bf16(f"{dst}.attn.norm.scale", state[f"{src}.input_layernorm.weight"]) add_bf16( f"{dst}.attn.qkv.weight", torch.cat( [ state[f"{src}.self_attn.q_proj.weight"], state[f"{src}.self_attn.k_proj.weight"], state[f"{src}.self_attn.v_proj.weight"], ], dim=0, ), ) add_bf16( f"{dst}.attn.qkv.bias", torch.cat( [ state[f"{src}.self_attn.q_proj.bias"], state[f"{src}.self_attn.k_proj.bias"], state[f"{src}.self_attn.v_proj.bias"], ], dim=0, ), ) add_bf16(f"{dst}.attn.sinks", state[f"{src}.self_attn.sinks"]) add_bf16(f"{dst}.attn.out.weight", state[f"{src}.self_attn.o_proj.weight"]) add_bf16(f"{dst}.attn.out.bias", state[f"{src}.self_attn.o_proj.bias"])
add_bf16(f"{dst}.mlp.norm.scale", state[f"{src}.post_attention_layernorm.weight"]) add_bf16(f"{dst}.mlp.gate.weight", state[f"{src}.mlp.router.weight"]) add_bf16(f"{dst}.mlp.gate.bias", state[f"{src}.mlp.router.bias"])
mlp1 = state[f"{src}.mlp.experts.gate_up_proj"].transpose(1, 2).contiguous() add_mxfp4(f"{dst}.mlp.mlp1_weight", mlp1) add_bf16(f"{dst}.mlp.mlp1_bias", state[f"{src}.mlp.experts.gate_up_proj_bias"])
mlp2 = state[f"{src}.mlp.experts.down_proj"].transpose(1, 2).contiguous() add_mxfp4(f"{dst}.mlp.mlp2_weight", mlp2) add_bf16(f"{dst}.mlp.mlp2_bias", state[f"{src}.mlp.experts.down_proj_bias"])
add_bf16("norm.scale", state["model.norm.weight"]) add_bf16("unembedding.weight", state["lm_head.weight"])
output_dir.mkdir(parents=True, exist_ok=True) model_path = output_dir / "model.safetensors" config_path = output_dir / "config.json" dtypes_path = output_dir / "dtypes.json" inventory_path = output_dir / "tensor_inventory.json" manifest_path = output_dir / "conversion_manifest.json"
# Safetensors metadata maps are emitted through an unordered map and can # change byte order between processes. Keep the model file metadata-free # so its SHA-256 is reproducible; profile details live in the adjacent # dtypes.json and conversion_manifest.json files. save_file(tensors, model_path) config_path.write_text(json.dumps(official_config(source_config), indent=2) + "\n", encoding="utf-8") dtypes_path.write_text(json.dumps(dtypes, indent=2) + "\n", encoding="utf-8") inventory = make_inventory(tensors, dtypes) inventory_path.write_text(json.dumps(inventory, indent=2) + "\n", encoding="utf-8")
manifest = { "format": "openai-gpt-oss-original-mxfp4", "source": { "repository": "shibatch/tinygptossmoe3m", "subfolder": "hf", "model_sha256": sha256_file(source_model_path), "config_sha256": sha256_file(source_config_path), }, "official_implementation": { "repository": "https://github.com/openai/gpt-oss.git", "revision": OPENAI_GPT_OSS_REVISION, }, "official_quantizer_dependency": { "repository": "https://github.com/triton-lang/triton.git", "revision": TRITON_KERNELS_REVISION, "api": "triton_kernels.numerics_details.mxfp.downcast_to_mxfp_torch", "rounding_mode": "DequantScaleRoundingMode.ROUND_DOWN", }, "conversion_environment": { "python": platform.python_version(), "torch": torch.__version__, "triton": __import__("triton").__version__, "safetensors": __import__("safetensors").__version__, }, "reproduction_command": ( "PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels " "python tools/convert_tinygptoss_to_mxfp4.py " "--source-dir hf --output-dir rebuilt/original " "--openai-repo third_party/openai-gpt-oss --triton-repo third_party/triton" ), "official_profile_reference": { "repository": OFFICIAL_PROFILE_REPO, "revision": OFFICIAL_PROFILE_REVISION, "config_sha256": OFFICIAL_PROFILE_CONFIG_SHA256, "dtypes_sha256": OFFICIAL_PROFILE_DTYPES_SHA256, }, "profile": { "expert_weights": ["mlp1_weight", "mlp2_weight"], "expert_value_format": "E2M1", "expert_scale_format": "E8M0", "block_size": BLOCK_SIZE, "values_per_byte": 2, "nibble_order": "low-nibble-first", "scale_bias": 127, "non_expert_dtype": "BF16", }, "outputs": { "model_sha256": sha256_file(model_path), "config_sha256": sha256_file(config_path), "dtypes_sha256": sha256_file(dtypes_path), "tensor_inventory_sha256": sha256_file(inventory_path), "tensor_count": inventory["tensor_count"], "total_tensor_bytes": inventory["total_tensor_bytes"], }, } manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
print(f"Wrote {model_path}") print(f"Tensor count: {inventory['tensor_count']}") print(f"Model SHA-256: {manifest['outputs']['model_sha256']}")
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335#!/usr/bin/env python3"""Generate deterministic reference vectors with pinned OpenAI gpt-oss code."""
from __future__ import annotations
import argparseimport hashlibimport jsonimport subprocessimport sysfrom pathlib import Path
import torchfrom safetensors.torch import save_filefrom tokenizers import Tokenizer
OPENAI_GPT_OSS_REVISION = "599476783c6f88508dab8577808b5ead5cbee8d2"TRITON_KERNELS_REVISION = "9e1e203f64752cf99abf0e44286231c5d5df7e76"
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--checkpoint", type=Path, required=True) parser.add_argument("--tokenizer", type=Path, required=True) parser.add_argument("--output-dir", type=Path, required=True) parser.add_argument("--openai-repo", type=Path, required=True) parser.add_argument("--triton-repo", type=Path, required=True) parser.add_argument("--prompt", default="Once upon a time,") parser.add_argument("--max-new-tokens", type=int, default=64) parser.add_argument("--context", type=int, default=256) parser.add_argument("--device", default="cuda:0") return parser.parse_args()
def sha256_file(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as handle: for chunk in iter(lambda: handle.read(1024 * 1024), b""): digest.update(chunk) return digest.hexdigest()
def require_revision(path: Path, expected: str, label: str) -> None: actual = subprocess.check_output( ["git", "-C", str(path), "rev-parse", "HEAD"], text=True, ).strip() if actual != expected: raise RuntimeError(f"{label} revision mismatch: expected {expected}, got {actual}")
def install_import_paths(openai_repo: Path, triton_repo: Path) -> None: sys.path.insert(0, str(openai_repo.resolve())) sys.path.insert(0, str((triton_repo / "python" / "triton_kernels").resolve()))
def install_tiny_attention_adapter(triton_model) -> dict: """Adapt tiny GQA dimensions while retaining OpenAI's reference attention.""" official_attention_ref = triton_model.attention_ref
def adapted_attention_ref(q, *args, **kwargs): # OpenAI's model builds [B,T,groups,kv_heads,D], while the official # attention function consumes [B,T,kv_heads,groups,D]. The released # 20B/120B configs have equal middle dimensions, so this is invisible # there. It must be explicit for this 1-KV-head tiny checkpoint. return official_attention_ref(q.transpose(2, 3).contiguous(), *args, **kwargs)
# head_dim=32 is valid in attention_ref, but the fused kernel fixes # BLOCK_N=64. Use the official reference function for both paths. triton_model.attention = adapted_attention_ref triton_model.attention_ref = adapted_attention_ref return { "gqa_axis_adapter": "transpose query dimensions 2 and 3", "attention_backend": "gpt_oss.triton.attention.attention_ref", "reason": "tiny config uses 1 KV head, 4 groups, and head_dim 32", "official_source_modified": False, }
@torch.inference_mode()def full_and_cached_logits(model, triton_model, input_ids: torch.Tensor, context: int): full = model(input_ids) caches = [ triton_model.Cache( input_ids.shape[0], context, model.config.num_key_value_heads, d_head=model.config.head_dim, device=input_ids.device, ) for _ in model.block ] pieces = [model(input_ids[:, i : i + 1], caches=caches) for i in range(input_ids.shape[1])] cached = torch.cat(pieces, dim=1) return full.float(), cached.float()
@torch.inference_mode()def routing_and_projection(torch_model, input_ids: torch.Tensor): if input_ids.shape[0] != 1: raise ValueError("The routing reference currently requires batch size 1") x = torch_model.embedding(input_ids[0]) routing: dict[str, torch.Tensor] = {} projections: dict[str, torch.Tensor] = {}
for layer_index, block in enumerate(torch_model.block): x = block.attn(x) t = block.mlp.norm(x) router_logits = block.mlp.gate(t) experts = torch.topk( router_logits, k=block.mlp.experts_per_token, dim=-1, sorted=True, ) expert_weights = torch.softmax(experts.values, dim=1) expert_ids = experts.indices
mlp1_weight = block.mlp.mlp1_weight[expert_ids] mlp1_bias = block.mlp.mlp1_bias[expert_ids] hidden = torch.einsum("teoh,th->teo", mlp1_weight, t) + mlp1_bias
from gpt_oss.torch.model import swiglu
hidden = swiglu(hidden, limit=block.mlp.swiglu_limit) mlp2_weight = block.mlp.mlp2_weight[expert_ids] mlp2_bias = block.mlp.mlp2_bias[expert_ids] selected_output = torch.einsum("tehi,tei->teh", mlp2_weight, hidden) + mlp2_bias weighted_sum = torch.einsum("teh,te->th", selected_output, expert_weights)
prefix = f"block.{layer_index}" routing[f"{prefix}.expert_ids"] = expert_ids.cpu().contiguous() routing[f"{prefix}.expert_weights"] = expert_weights.float().cpu().contiguous() routing[f"{prefix}.router_logits"] = router_logits.float().cpu().contiguous() projections[f"{prefix}.selected_expert_output"] = selected_output.float().cpu().contiguous() projections[f"{prefix}.weighted_expert_output"] = weighted_sum.float().cpu().contiguous() x = x + weighted_sum
logits = torch_model.unembedding(torch_model.norm(x)).float().unsqueeze(0) return routing, projections, logits
@torch.inference_mode()def greedy_continuation( model, triton_model, prompt_ids: list[int], eos_token_id: int, max_new_tokens: int, context: int, device: torch.device,) -> list[int]: if len(prompt_ids) + max_new_tokens > context: raise ValueError("Prompt plus continuation exceeds cache context") caches = [ triton_model.Cache( 1, context, model.config.num_key_value_heads, d_head=model.config.head_dim, device=device, ) for _ in model.block ] if len(prompt_ids) > 1: prefix = torch.tensor([prompt_ids[:-1]], dtype=torch.int32, device=device) model(prefix, caches=caches)
current = prompt_ids[-1] generated: list[int] = [] for _ in range(max_new_tokens): token = torch.tensor([[current]], dtype=torch.int32, device=device) logits = model(token, caches=caches)[0, -1] current = int(torch.argmax(logits).item()) generated.append(current) if current == eos_token_id: break return generated
def main() -> None: args = parse_args() checkpoint = args.checkpoint.resolve() tokenizer_path = args.tokenizer.resolve() output_dir = args.output_dir.resolve() openai_repo = args.openai_repo.resolve() triton_repo = args.triton_repo.resolve()
require_revision(openai_repo, OPENAI_GPT_OSS_REVISION, "OpenAI gpt-oss") require_revision(triton_repo, TRITON_KERNELS_REVISION, "Triton kernels") install_import_paths(openai_repo, triton_repo)
import gpt_oss.triton.model as triton_model from gpt_oss.torch.model import Transformer as TorchTransformer
adapter = install_tiny_attention_adapter(triton_model) device = torch.device(args.device) if device.type != "cuda": raise ValueError("The official Triton cached path requires CUDA")
tokenizer = Tokenizer.from_file(str(tokenizer_path / "tokenizer.json")) prompt_ids = tokenizer.encode(args.prompt, add_special_tokens=False).ids if not prompt_ids: raise ValueError("Prompt tokenized to an empty sequence") eos_token_id = tokenizer.token_to_id("</s>") if eos_token_id is None: raise ValueError("Tokenizer does not define the </s> token") input_ids = torch.tensor([prompt_ids], dtype=torch.int32, device=device)
triton_checkpoint = triton_model.Transformer.from_checkpoint(checkpoint, device=device) full_logits, cached_logits = full_and_cached_logits( triton_checkpoint, triton_model, input_ids, args.context, )
torch_checkpoint = TorchTransformer.from_checkpoint(checkpoint, device=device) routing, projections, reconstructed_torch_logits = routing_and_projection( torch_checkpoint, input_ids, ) direct_torch_logits = torch_checkpoint(input_ids[0]).float().unsqueeze(0) torch.testing.assert_close(reconstructed_torch_logits, direct_torch_logits, rtol=0, atol=0)
generated_ids = greedy_continuation( triton_checkpoint, triton_model, prompt_ids, eos_token_id, args.max_new_tokens, args.context, device, )
output_dir.mkdir(parents=True, exist_ok=True) full_path = output_dir / "full_logits.safetensors" cached_path = output_dir / "cached_logits.safetensors" routing_path = output_dir / "routing.safetensors" projection_path = output_dir / "expert_projection.safetensors" continuation_path = output_dir / "greedy_continuation.json" manifest_path = output_dir / "reference_manifest.json"
save_file({"logits": full_logits.cpu().contiguous()}, full_path) save_file({"logits": cached_logits.cpu().contiguous()}, cached_path) save_file(routing, routing_path) save_file(projections, projection_path)
continuation = { "prompt": args.prompt, "prompt_token_ids": prompt_ids, "generated_token_ids": generated_ids, "generated_text": tokenizer.decode(generated_ids, skip_special_tokens=True), "full_text": tokenizer.decode(prompt_ids + generated_ids, skip_special_tokens=True), "greedy": True, "max_new_tokens": args.max_new_tokens, "eos_token_id": eos_token_id, "stopped_on_eos": bool(generated_ids and generated_ids[-1] == eos_token_id), } continuation_path.write_text(json.dumps(continuation, indent=2) + "\n", encoding="utf-8")
difference = (full_logits - cached_logits).abs() torch_difference = (full_logits - direct_torch_logits).abs() manifest = { "checkpoint_model_sha256": sha256_file(checkpoint / "model.safetensors"), "official_openai_revision": OPENAI_GPT_OSS_REVISION, "triton_kernels_revision": TRITON_KERNELS_REVISION, "device": torch.cuda.get_device_name(device), "device_capability": list(torch.cuda.get_device_capability(device)), "torch_version": torch.__version__, "triton_version": __import__("triton").__version__, "reproduction_command": ( "CUDA_VISIBLE_DEVICES=<gpu> " "PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels " "python tools/generate_gptoss_mxfp4_reference.py " "--checkpoint original --tokenizer hf --output-dir rebuilt/mxfp4_reference_outputs " "--openai-repo third_party/openai-gpt-oss --triton-repo third_party/triton " "--prompt 'Once upon a time,' --max-new-tokens 64 --context 256 --device cuda:0" ), "prompt": args.prompt, "prompt_token_ids": prompt_ids, "logits_shape": list(full_logits.shape), "output_provenance": { "full_logits": "gpt_oss.triton.model.Transformer full-sequence forward", "cached_logits": "gpt_oss.triton.model.Transformer with per-layer Cache", "greedy_continuation": "gpt_oss.triton.model.Transformer with per-layer Cache", "routing": "gpt_oss.torch.model.Transformer MoE equations", "expert_projection": "gpt_oss.torch.model.Transformer MoE equations", }, "full_vs_cached": { "max_abs_diff": float(difference.max().item()), "mean_abs_diff": float(difference.mean().item()), "all_token_argmax_equal": bool( torch.equal(full_logits.argmax(dim=-1), cached_logits.argmax(dim=-1)) ), }, "triton_full_vs_torch_full": { "max_abs_diff": float(torch_difference.max().item()), "mean_abs_diff": float(torch_difference.mean().item()), "all_token_argmax_equal": bool( torch.equal(full_logits.argmax(dim=-1), direct_torch_logits.argmax(dim=-1)) ), }, "routing": { "layers": len(torch_checkpoint.block), "tokens": len(prompt_ids), "experts_per_token": torch_checkpoint.block[0].mlp.experts_per_token, "includes_router_logits": True, }, "expert_projection": { "selected_output_shape_per_layer": [ len(prompt_ids), torch_checkpoint.block[0].mlp.experts_per_token, torch_checkpoint.unembedding.in_features, ], "includes_weighted_sum": True, }, "tiny_attention_adapter": adapter, "files": { full_path.name: sha256_file(full_path), cached_path.name: sha256_file(cached_path), routing_path.name: sha256_file(routing_path), projection_path.name: sha256_file(projection_path), continuation_path.name: sha256_file(continuation_path), }, } manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
print(json.dumps(manifest["full_vs_cached"], indent=2)) print(continuation["full_text"])
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106#!/usr/bin/env python3"""Verify package hashes, tensor inventory, dtypes, and MXFP4 shapes."""
from __future__ import annotations
import hashlibimport jsonimport structfrom pathlib import Path
import torchfrom safetensors import safe_open
ROOT = Path(__file__).resolve().parent.parent
def sha256(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as handle: for chunk in iter(lambda: handle.read(1024 * 1024), b""): digest.update(chunk) return digest.hexdigest()
def tensor_sha256(tensor: torch.Tensor) -> str: raw = tensor.contiguous().view(torch.uint8).numpy().tobytes() return hashlib.sha256(raw).hexdigest()
def verify_file_hashes() -> None: for line in (ROOT / "SHA256SUMS").read_text(encoding="utf-8").splitlines(): expected, relative = line.split(" ", 1) actual = sha256(ROOT / relative) if actual != expected: raise RuntimeError(f"SHA-256 mismatch for {relative}: {actual} != {expected}")
def verify_model() -> int: original = ROOT / "original" dtypes = json.loads((original / "dtypes.json").read_text(encoding="utf-8")) inventory = json.loads((original / "tensor_inventory.json").read_text(encoding="utf-8")) entries = {entry["name"]: entry for entry in inventory["tensors"]} model_path = original / "model.safetensors" manifest = json.loads((original / "conversion_manifest.json").read_text(encoding="utf-8")) if sha256(model_path) != manifest["outputs"]["model_sha256"]: raise RuntimeError("Model hash does not match conversion_manifest.json")
with safe_open(model_path, framework="pt", device="cpu") as handle: names = list(handle.keys()) if set(names) != set(dtypes) or set(names) != set(entries): raise RuntimeError("Model, dtypes, and inventory tensor-name sets differ") for name in names: tensor = handle.get_tensor(name) entry = entries[name] if list(tensor.shape) != entry["shape"]: raise RuntimeError(f"Shape mismatch for {name}") if tensor_sha256(tensor) != entry["tensor_sha256"]: raise RuntimeError(f"Tensor hash mismatch for {name}") if name.endswith((".blocks", ".scales")): if tensor.dtype != torch.uint8: raise RuntimeError(f"MXFP4 storage must be U8: {name}") elif tensor.dtype != torch.bfloat16: raise RuntimeError(f"Non-expert tensor must be BF16: {name}")
for name in names: if not name.endswith("_weight.blocks"): continue base = name.removesuffix(".blocks") blocks = handle.get_tensor(name) scales = handle.get_tensor(base + ".scales") if blocks.shape[:-1] != scales.shape or blocks.shape[-1] != 16: raise RuntimeError(f"Official MXFP4 block/scale shape mismatch: {base}") if dtypes[name] != "FP4" or dtypes[base + ".scales"] != "UE8": raise RuntimeError(f"Profile dtype mismatch: {base}")
return len(names)
def verify_packing_vector() -> None: vector = json.loads((ROOT / "mxfp4_packing_test_vector.json").read_text(encoding="utf-8")) fp4_values = [ 0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, -0.0, -0.5, -1.0, -1.5, -2.0, -3.0, -4.0, -6.0, ] decoded = [] for byte in vector["packed_uint8_decimal"]: decoded.append(fp4_values[byte & 0x0F]) decoded.append(fp4_values[byte >> 4]) expected_bits = b"".join(struct.pack("<f", value) for value in vector["input_float32"]) decoded_bits = b"".join(struct.pack("<f", value) for value in decoded) if decoded_bits != expected_bits: raise RuntimeError("Low-nibble-first E2M1 packing vector did not round-trip") if vector["scale_uint8_decimal"] != [127]: raise RuntimeError("E8M0 identity-scale test vector must use biased exponent 127")
def main() -> None: verify_file_hashes() tensor_count = verify_model() verify_packing_vector() print(f"OK: all payload hashes and {tensor_count} model tensors verified")
if __name__ == "__main__": main().gitattributes+1-34
LICENSEAdded+21
MXFP4_VERSION_LOCK.jsonAdded+33
README.md+153-7
SHA256SUMSAdded+29
mxfp4_packing_test_vector.jsonAdded+24
mxfp4_reference_outputs/cached_logits.safetensorsAdded+3
mxfp4_reference_outputs/expert_projection.safetensorsAdded+3
mxfp4_reference_outputs/full_logits.safetensorsAdded+3
mxfp4_reference_outputs/greedy_continuation.jsonAdded+82
mxfp4_reference_outputs/reference_manifest.jsonAdded+70
mxfp4_reference_outputs/routing.safetensorsAdded+3
original/config.jsonAdded+18
original/conversion_manifest.jsonAdded+53
original/dtypes.jsonAdded+95
original/model.safetensorsAdded+3
original/tensor_inventory.jsonAdded+1121
requirements-mxfp4.txtAdded+7
tools/convert_tinygptoss_to_mxfp4.pyAdded+337
tools/generate_gptoss_mxfp4_reference.pyAdded+335
tools/verify_mxfp4.pyAdded+106