shibatch commited on
Commit
2129f51
·
verified ·
1 Parent(s): ca0e5f6

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -1,35 +1,2 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  *.safetensors filter=lfs diff=lfs merge=lfs -text
2
+ *.bin filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 shibatch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
MXFP4_VERSION_LOCK.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "python": "3.13.7",
3
+ "packages": {
4
+ "torch": "2.8.0+cu128",
5
+ "triton": "3.4.0",
6
+ "triton_kernels": "editable from pinned Triton revision",
7
+ "safetensors": "0.8.0",
8
+ "tokenizers": "0.22.2",
9
+ "numpy": "2.5.1",
10
+ "pytest": "9.1.1",
11
+ "huggingface_hub": "1.26.0"
12
+ },
13
+ "repositories": {
14
+ "openai_gpt_oss": {
15
+ "url": "https://github.com/openai/gpt-oss.git",
16
+ "revision": "599476783c6f88508dab8577808b5ead5cbee8d2"
17
+ },
18
+ "triton": {
19
+ "url": "https://github.com/triton-lang/triton.git",
20
+ "revision": "9e1e203f64752cf99abf0e44286231c5d5df7e76"
21
+ },
22
+ "official_profile": {
23
+ "repo_id": "openai/gpt-oss-20b",
24
+ "revision": "6cee5e81ee83917806bbde320786a8fb61efebee",
25
+ "subfolder": "original"
26
+ },
27
+ "source_model": {
28
+ "repo_id": "shibatch/tinygptossmoe3m",
29
+ "subfolder": "hf",
30
+ "model_sha256": "baf06470d796cf7cc3cbb74e0cc176940ca45b2889cc9080640243c563f810cb"
31
+ }
32
+ }
33
+ }
README.md CHANGED
@@ -12,6 +12,9 @@ tags:
12
  - validation
13
  - debug-model
14
  - transformers
 
 
 
15
  pipeline_tag: text-generation
16
  ---
17
 
@@ -25,6 +28,20 @@ This checkpoint is useful for implementation testing because it includes sliding
25
 
26
  This is a synthetic tiny validation checkpoint. It is not an official OpenAI model and does not contain weights from the original gpt-oss checkpoints.
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  ## Model purpose
29
 
30
  This model is designed for:
@@ -42,6 +59,8 @@ This model is designed for:
42
  * exercising MoE expert parameters
43
  * exercising top-4 expert routing
44
  * providing a compact gpt-oss-style MoE checkpoint for inference-engine validation
 
 
45
 
46
  It is not designed for:
47
 
@@ -51,7 +70,6 @@ It is not designed for:
51
  * benchmark comparison against production language models
52
  * production deployment
53
  * reproducing the behavior of the original gpt-oss models
54
- * testing MXFP4 quantized weight loading
55
 
56
  ## Model architecture
57
 
@@ -257,7 +275,7 @@ Lily was so happy that she ran up the slide and started to slide down. She slid
257
 
258
  The 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.
259
 
260
- ## Usage
261
 
262
  ```python
263
  import torch
@@ -290,7 +308,7 @@ print(tokenizer.decode(output_ids[0], skip_special_tokens=True))
290
 
291
  ## Loading requirements
292
 
293
- This checkpoint requires a Transformers version that supports gpt-oss models.
294
 
295
  The following imports should work:
296
 
@@ -346,6 +364,12 @@ MoE expert output combination
346
  generate()
347
  save_pretrained()
348
  from_pretrained()
 
 
 
 
 
 
349
  ```
350
 
351
  ## Limitations
@@ -362,8 +386,8 @@ Known limitations:
362
  * no instruction tuning
363
  * no chat formatting
364
  * no production use
365
- * no MXFP4 checkpoint coverage
366
  * no compatibility claim with original gpt-oss model quality
 
367
 
368
  The checkpoint is primarily intended to make gpt-oss-style MoE text-model code paths easy to test without downloading a large model.
369
 
@@ -399,11 +423,133 @@ to cover both attention implementations.
399
 
400
  ## Notes on MXFP4 and quantization
401
 
402
- The 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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
 
404
- It is intended for architecture, loader, routing, and generation validation. It is not intended to validate MXFP4 decoding or production quantized loading paths.
 
 
 
405
 
406
- A quantized tiny gpt-oss validation checkpoint can be produced as a separate artifact if needed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
407
 
408
  ## Suggested repository name
409
 
 
12
  - validation
13
  - debug-model
14
  - transformers
15
+ - mxfp4
16
+ - e2m1
17
+ - e8m0
18
  pipeline_tag: text-generation
19
  ---
20
 
 
28
 
29
  This is a synthetic tiny validation checkpoint. It is not an official OpenAI model and does not contain weights from the original gpt-oss checkpoints.
30
 
31
+ ## Repository weight profiles
32
+
33
+ This repository contains two representations of the same trained model:
34
+
35
+ | Subfolder | Purpose | Precision |
36
+ |---|---|---|
37
+ | `hf/` | Hugging Face `GptOssForCausalLM` | FP32 |
38
+ | `original/` | OpenAI original-format loader | official-profile MXFP4 + BF16 |
39
+
40
+ The `original/` checkpoint is not a blanket 4-bit conversion. Only expert
41
+ `mlp1_weight` and `mlp2_weight` tensors use MXFP4 `.blocks` and `.scales`.
42
+ Embedding, attention, router, bias, norm, sink, and unembedding tensors remain
43
+ BF16, matching the official gpt-oss precision profile.
44
+
45
  ## Model purpose
46
 
47
  This model is designed for:
 
59
  * exercising MoE expert parameters
60
  * exercising top-4 expert routing
61
  * providing a compact gpt-oss-style MoE checkpoint for inference-engine validation
62
+ * testing official-profile MXFP4 tensor loading and decoding
63
+ * comparing full-sequence and KV-cached logits
64
 
65
  It is not designed for:
66
 
 
70
  * benchmark comparison against production language models
71
  * production deployment
72
  * reproducing the behavior of the original gpt-oss models
 
73
 
74
  ## Model architecture
75
 
 
275
 
276
  The 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.
277
 
278
+ ## Hugging Face FP32 usage
279
 
280
  ```python
281
  import torch
 
308
 
309
  ## Loading requirements
310
 
311
+ The `hf/` checkpoint requires a Transformers version that supports gpt-oss models.
312
 
313
  The following imports should work:
314
 
 
364
  generate()
365
  save_pretrained()
366
  from_pretrained()
367
+ official gpt-oss original-format loading
368
+ MXFP4 E2M1 expert blocks
369
+ E8M0 expert scales
370
+ full versus KV-cached logits
371
+ top-4 routing IDs and weights
372
+ selected expert projection outputs
373
  ```
374
 
375
  ## Limitations
 
386
  * no instruction tuning
387
  * no chat formatting
388
  * no production use
 
389
  * no compatibility claim with original gpt-oss model quality
390
+ * the tiny attention dimensions require the documented reference-attention adapter for OpenAI's Triton implementation
391
 
392
  The checkpoint is primarily intended to make gpt-oss-style MoE text-model code paths easy to test without downloading a large model.
393
 
 
423
 
424
  ## Notes on MXFP4 and quantization
425
 
426
+ The `original/model.safetensors` file follows the naming, shape, packing, and
427
+ mixed-precision profile used by OpenAI's original-format gpt-oss checkpoints.
428
+ There is no separate `.mxfp4` file extension: MXFP4 tensors are represented by
429
+ paired `.blocks` and `.scales` tensors inside SafeTensors.
430
+
431
+ ```text
432
+ block.N.mlp.mlp1_weight.blocks uint8 E2M1, two values per byte
433
+ block.N.mlp.mlp1_weight.scales uint8 E8M0
434
+ block.N.mlp.mlp2_weight.blocks uint8 E2M1, two values per byte
435
+ block.N.mlp.mlp2_weight.scales uint8 E8M0
436
+ ```
437
+
438
+ Packing and conversion rules:
439
+
440
+ * 32 E2M1 values per scale block
441
+ * first/even value in the low nibble
442
+ * second/odd value in the high nibble
443
+ * E8M0 exponent bias 127
444
+ * OCP `ROUND_DOWN` scale selection
445
+ * round-to-nearest, ties-to-even E2M1 conversion
446
+ * block scaling along the final logical matrix dimension
447
+
448
+ The model contains 93 physical tensors: 69 BF16, 12 FP4 block tensors, and 12
449
+ UE8 scale tensors. Exact names, dtypes, shapes, byte sizes, and raw-tensor
450
+ SHA-256 values are in `original/tensor_inventory.json`. A standalone packing
451
+ example is in `mxfp4_packing_test_vector.json`.
452
+
453
+ The fixed model SHA-256 is:
454
+
455
+ ```text
456
+ 30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d
457
+ ```
458
+
459
+ ### Fixed revisions
460
+
461
+ ```text
462
+ OpenAI gpt-oss:
463
+ 599476783c6f88508dab8577808b5ead5cbee8d2
464
+
465
+ Triton kernels:
466
+ 9e1e203f64752cf99abf0e44286231c5d5df7e76
467
+
468
+ Official profile reference openai/gpt-oss-20b:
469
+ 6cee5e81ee83917806bbde320786a8fb61efebee
470
+ ```
471
+
472
+ Exact package versions are recorded in `MXFP4_VERSION_LOCK.json` and
473
+ `requirements-mxfp4.txt`.
474
 
475
+ ```bash
476
+ python3 -m venv .venv-mxfp4
477
+ source .venv-mxfp4/bin/activate
478
+ pip install -r requirements-mxfp4.txt
479
 
480
+ git clone https://github.com/openai/gpt-oss.git third_party/openai-gpt-oss
481
+ git -C third_party/openai-gpt-oss checkout --detach \
482
+ 599476783c6f88508dab8577808b5ead5cbee8d2
483
+
484
+ git clone https://github.com/triton-lang/triton.git third_party/triton
485
+ git -C third_party/triton checkout --detach \
486
+ 9e1e203f64752cf99abf0e44286231c5d5df7e76
487
+
488
+ pip install --no-deps -e third_party/triton/python/triton_kernels
489
+ ```
490
+
491
+ ### Reproduce the conversion
492
+
493
+ After cloning the pinned OpenAI and Triton repositories and installing
494
+ `triton_kernels`, run from this repository's root:
495
+
496
+ ```bash
497
+ PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels \
498
+ python tools/convert_tinygptoss_to_mxfp4.py \
499
+ --source-dir hf \
500
+ --output-dir rebuilt/original \
501
+ --openai-repo third_party/openai-gpt-oss \
502
+ --triton-repo third_party/triton
503
+ ```
504
+
505
+ ### Fixed reference outputs
506
+
507
+ `mxfp4_reference_outputs/` contains:
508
+
509
+ * full FP32 logits `[1, 5, 1024]`
510
+ * token-by-token cached logits `[1, 5, 1024]`
511
+ * top-4 routing IDs, weights, and router logits for all six layers
512
+ * selected expert projection and routing-weighted output for all six layers
513
+ * a 64-token greedy continuation
514
+
515
+ For the fixed prompt `Once upon a time,`, full and cached logits are
516
+ byte-identical:
517
+
518
+ ```text
519
+ max_abs_diff: 0.0
520
+ mean_abs_diff: 0.0
521
+ all_token_argmax_equal: true
522
+ ```
523
+
524
+ Regenerate them with:
525
+
526
+ ```bash
527
+ CUDA_VISIBLE_DEVICES=0 \
528
+ PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels \
529
+ python tools/generate_gptoss_mxfp4_reference.py \
530
+ --checkpoint original \
531
+ --tokenizer hf \
532
+ --output-dir rebuilt/mxfp4_reference_outputs \
533
+ --openai-repo third_party/openai-gpt-oss \
534
+ --triton-repo third_party/triton \
535
+ --prompt 'Once upon a time,' \
536
+ --max-new-tokens 64 \
537
+ --context 256 \
538
+ --device cuda:0
539
+ ```
540
+
541
+ OpenAI's Triton attention code assumes dimensions used by the 20B/120B
542
+ models. For this tiny model's one KV head, four GQA groups, and 32-wide head,
543
+ the harness transposes the two grouping axes and calls the pinned official
544
+ `attention_ref`. OpenAI's model source is not patched; its loader, KV cache,
545
+ Transformer, routing, and Triton MXFP4 MoE paths remain in use. The adapter is
546
+ fully recorded in `mxfp4_reference_outputs/reference_manifest.json`.
547
+
548
+ Verify all repository payload hashes, all 93 tensor hashes, and MXFP4 shapes:
549
+
550
+ ```bash
551
+ python tools/verify_mxfp4.py
552
+ ```
553
 
554
  ## Suggested repository name
555
 
SHA256SUMS ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 127386e47ae53f224aaf02383189e1b11e6d52289775b426655aa5d87d7e953c ./.gitattributes
2
+ cdf09a0b07d7cdb2ea535ac3127541ea55d6a996787a8e1b9266015d69f708a2 ./LICENSE
3
+ e2bf6966c9e65266186eefe61609bbb0126bfbc9f4cdc62e29c8b4b8631d88d0 ./MXFP4_VERSION_LOCK.json
4
+ d9c48665fc34d115e88b6f7004ccf23733a6ffaf9b18fe62d52510c4152d3c15 ./README.md
5
+ c0c9b803fcf90373f3ffbff866bf2e318be867efcc0568fab799a1280654d3f4 ./artifact_metadata.json
6
+ 496bad1de60db3b5e5e3ab212a593ae108e932d32313c191452f96d9409e9c57 ./eval_text_generation.json
7
+ f07d5eab89bab4a5d488e335f79e27626653abe5281006711ef27551d50a886a ./gpt_oss_config_dump.json
8
+ 7d68c391baabd2a64ccb6c381c0d7c98ad5f6389871d45491ad2c70ef4091637 ./hf/config.json
9
+ d620c9792670d1dc597f38e85d8e99692a6783434d497f991ceb20d5e6e200d4 ./hf/generation_config.json
10
+ baf06470d796cf7cc3cbb74e0cc176940ca45b2889cc9080640243c563f810cb ./hf/model.safetensors
11
+ aa81ff9823a3249d87ae978b31f1e72226d77d63f9488115eb9bd76462699c70 ./hf/tokenizer.json
12
+ f7dfa5942f9e71bcc3c7a6f0494f7a100be8470184ed39a2be6cbf78ebae89fd ./hf/tokenizer_config.json
13
+ f9192dad418925a3dc4f2177e53a7f70e968cab21af83dd69b8be604b64c7710 ./mxfp4_packing_test_vector.json
14
+ 5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f ./mxfp4_reference_outputs/cached_logits.safetensors
15
+ 33f73333341f7a86b6a44d273581a096bed789d927a90ce7411d43c0437748bb ./mxfp4_reference_outputs/expert_projection.safetensors
16
+ 5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f ./mxfp4_reference_outputs/full_logits.safetensors
17
+ 1478ed0112bf32f0444a5dd1bae9eeaebe2cc751396d1fe92513e6e208984b2d ./mxfp4_reference_outputs/greedy_continuation.json
18
+ 9dc39d874552ace0edf32ff7f7d7afcb8f901ff0c64b85d3e773dac9df1c7872 ./mxfp4_reference_outputs/reference_manifest.json
19
+ f94ffb12b3da2c922fc7e95134603e155fd06046dbaba9610360e8aea2d58311 ./mxfp4_reference_outputs/routing.safetensors
20
+ f9be3908850cc3def17375cbbae101c1b6ee801b4db7315489dbe6f513d4affe ./original/config.json
21
+ 6ab2027a978cb64efc4841548384c6b4e19be4850421f1215b16ee2824e62aa6 ./original/conversion_manifest.json
22
+ fa36ec5d12a062717c28c7bb53535e1e29d70ea1b41e32c8ec137888df2309c8 ./original/dtypes.json
23
+ 30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d ./original/model.safetensors
24
+ 99d24cda1c1441cc3ff04776a618e432b3e3f3ba6ddd33bc2b9342d2ca3b68a5 ./original/tensor_inventory.json
25
+ c4edf49855cd72ef1818df1983aa4045ffd0187bf54d7ff762343876e4d6d227 ./requirements-mxfp4.txt
26
+ 3771257b3918a4ec233a2ed583601537537596552f54c9bec6ddae01042e98d1 ./tokenizer_train/tokenizer.json
27
+ 84c1c4d7abf70c9a81483e8b2c8885d51d468d5ea0d3db5200dc83bae20b6c36 ./tools/convert_tinygptoss_to_mxfp4.py
28
+ 323d3d38193f0b27987ea5377d8af290843051bfaa4bfce2ffecc5e6e349ddd6 ./tools/generate_gptoss_mxfp4_reference.py
29
+ a06adce5d4be2249caa777f2a912833406f01dfa16773e3699c85b4ec7df7a74 ./tools/verify_mxfp4.py
mxfp4_packing_test_vector.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "description": "Canonical low-nibble-first E2M1 and E8M0 packing vector",
3
+ "quantizer": "triton_kernels.numerics_details.mxfp.downcast_to_mxfp_torch",
4
+ "triton_revision": "9e1e203f64752cf99abf0e44286231c5d5df7e76",
5
+ "rounding_mode": "DequantScaleRoundingMode.ROUND_DOWN",
6
+ "block_size": 32,
7
+ "input_float32": [
8
+ 0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0,
9
+ -0.0, -0.5, -1.0, -1.5, -2.0, -3.0, -4.0, -6.0,
10
+ 0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0,
11
+ -0.0, -0.5, -1.0, -1.5, -2.0, -3.0, -4.0, -6.0
12
+ ],
13
+ "packed_uint8_decimal": [
14
+ 16, 50, 84, 118, 152, 186, 220, 254,
15
+ 16, 50, 84, 118, 152, 186, 220, 254
16
+ ],
17
+ "packed_uint8_hex": [
18
+ "10", "32", "54", "76", "98", "ba", "dc", "fe",
19
+ "10", "32", "54", "76", "98", "ba", "dc", "fe"
20
+ ],
21
+ "scale_uint8_decimal": [127],
22
+ "scale_exponent_after_bias": [0],
23
+ "nibble_rule": "input[2*i] is bits 0..3; input[2*i+1] is bits 4..7"
24
+ }
mxfp4_reference_outputs/cached_logits.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f
3
+ size 20560
mxfp4_reference_outputs/expert_projection.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33f73333341f7a86b6a44d273581a096bed789d927a90ce7411d43c0437748bb
3
+ size 77952
mxfp4_reference_outputs/full_logits.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f
3
+ size 20560
mxfp4_reference_outputs/greedy_continuation.json ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "prompt": "Once upon a time,",
3
+ "prompt_token_ids": [
4
+ 430,
5
+ 446,
6
+ 258,
7
+ 395,
8
+ 11
9
+ ],
10
+ "generated_token_ids": [
11
+ 399,
12
+ 281,
13
+ 258,
14
+ 396,
15
+ 445,
16
+ 499,
17
+ 363,
18
+ 13,
19
+ 312,
20
+ 502,
21
+ 265,
22
+ 358,
23
+ 677,
24
+ 315,
25
+ 262,
26
+ 732,
27
+ 13,
28
+ 505,
29
+ 355,
30
+ 11,
31
+ 337,
32
+ 412,
33
+ 258,
34
+ 406,
35
+ 11,
36
+ 969,
37
+ 304,
38
+ 288,
39
+ 315,
40
+ 262,
41
+ 861,
42
+ 13,
43
+ 408,
44
+ 281,
45
+ 258,
46
+ 396,
47
+ 969,
48
+ 304,
49
+ 288,
50
+ 341,
51
+ 258,
52
+ 969,
53
+ 935,
54
+ 409,
55
+ 83,
56
+ 13,
57
+ 198,
58
+ 198,
59
+ 342,
60
+ 443,
61
+ 265,
62
+ 265,
63
+ 84,
64
+ 374,
65
+ 262,
66
+ 304,
67
+ 288,
68
+ 11,
69
+ 409,
70
+ 337,
71
+ 662,
72
+ 422,
73
+ 694,
74
+ 711
75
+ ],
76
+ "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",
77
+ "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",
78
+ "greedy": true,
79
+ "max_new_tokens": 64,
80
+ "eos_token_id": 1001,
81
+ "stopped_on_eos": false
82
+ }
mxfp4_reference_outputs/reference_manifest.json ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "checkpoint_model_sha256": "30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d",
3
+ "official_openai_revision": "599476783c6f88508dab8577808b5ead5cbee8d2",
4
+ "triton_kernels_revision": "9e1e203f64752cf99abf0e44286231c5d5df7e76",
5
+ "device": "NVIDIA GeForce RTX 5060 Ti",
6
+ "device_capability": [
7
+ 12,
8
+ 0
9
+ ],
10
+ "torch_version": "2.8.0+cu128",
11
+ "triton_version": "3.4.0",
12
+ "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",
13
+ "prompt": "Once upon a time,",
14
+ "prompt_token_ids": [
15
+ 430,
16
+ 446,
17
+ 258,
18
+ 395,
19
+ 11
20
+ ],
21
+ "logits_shape": [
22
+ 1,
23
+ 5,
24
+ 1024
25
+ ],
26
+ "output_provenance": {
27
+ "full_logits": "gpt_oss.triton.model.Transformer full-sequence forward",
28
+ "cached_logits": "gpt_oss.triton.model.Transformer with per-layer Cache",
29
+ "greedy_continuation": "gpt_oss.triton.model.Transformer with per-layer Cache",
30
+ "routing": "gpt_oss.torch.model.Transformer MoE equations",
31
+ "expert_projection": "gpt_oss.torch.model.Transformer MoE equations"
32
+ },
33
+ "full_vs_cached": {
34
+ "max_abs_diff": 0.0,
35
+ "mean_abs_diff": 0.0,
36
+ "all_token_argmax_equal": true
37
+ },
38
+ "triton_full_vs_torch_full": {
39
+ "max_abs_diff": 0.4375,
40
+ "mean_abs_diff": 0.0456787645816803,
41
+ "all_token_argmax_equal": true
42
+ },
43
+ "routing": {
44
+ "layers": 6,
45
+ "tokens": 5,
46
+ "experts_per_token": 4,
47
+ "includes_router_logits": true
48
+ },
49
+ "expert_projection": {
50
+ "selected_output_shape_per_layer": [
51
+ 5,
52
+ 4,
53
+ 128
54
+ ],
55
+ "includes_weighted_sum": true
56
+ },
57
+ "tiny_attention_adapter": {
58
+ "gqa_axis_adapter": "transpose query dimensions 2 and 3",
59
+ "attention_backend": "gpt_oss.triton.attention.attention_ref",
60
+ "reason": "tiny config uses 1 KV head, 4 groups, and head_dim 32",
61
+ "official_source_modified": false
62
+ },
63
+ "files": {
64
+ "full_logits.safetensors": "5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f",
65
+ "cached_logits.safetensors": "5dc16765dd175ff95e7a923e1569dcca83880b044bb4de53cadb419c4535018f",
66
+ "routing.safetensors": "f94ffb12b3da2c922fc7e95134603e155fd06046dbaba9610360e8aea2d58311",
67
+ "expert_projection.safetensors": "33f73333341f7a86b6a44d273581a096bed789d927a90ce7411d43c0437748bb",
68
+ "greedy_continuation.json": "1478ed0112bf32f0444a5dd1bae9eeaebe2cc751396d1fe92513e6e208984b2d"
69
+ }
70
+ }
mxfp4_reference_outputs/routing.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f94ffb12b3da2c922fc7e95134603e155fd06046dbaba9610360e8aea2d58311
3
+ size 3840
original/config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "num_hidden_layers": 6,
3
+ "num_experts": 8,
4
+ "experts_per_token": 4,
5
+ "vocab_size": 1024,
6
+ "hidden_size": 128,
7
+ "intermediate_size": 128,
8
+ "swiglu_limit": 7.0,
9
+ "head_dim": 32,
10
+ "num_attention_heads": 4,
11
+ "num_key_value_heads": 1,
12
+ "sliding_window": 128,
13
+ "initial_context_length": 1024,
14
+ "rope_theta": 150000.0,
15
+ "rope_scaling_factor": 4.0,
16
+ "rope_ntk_alpha": 1.0,
17
+ "rope_ntk_beta": 32.0
18
+ }
original/conversion_manifest.json ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "format": "openai-gpt-oss-original-mxfp4",
3
+ "source": {
4
+ "repository": "shibatch/tinygptossmoe3m",
5
+ "subfolder": "hf",
6
+ "model_sha256": "baf06470d796cf7cc3cbb74e0cc176940ca45b2889cc9080640243c563f810cb",
7
+ "config_sha256": "7d68c391baabd2a64ccb6c381c0d7c98ad5f6389871d45491ad2c70ef4091637"
8
+ },
9
+ "official_implementation": {
10
+ "repository": "https://github.com/openai/gpt-oss.git",
11
+ "revision": "599476783c6f88508dab8577808b5ead5cbee8d2"
12
+ },
13
+ "official_quantizer_dependency": {
14
+ "repository": "https://github.com/triton-lang/triton.git",
15
+ "revision": "9e1e203f64752cf99abf0e44286231c5d5df7e76",
16
+ "api": "triton_kernels.numerics_details.mxfp.downcast_to_mxfp_torch",
17
+ "rounding_mode": "DequantScaleRoundingMode.ROUND_DOWN"
18
+ },
19
+ "conversion_environment": {
20
+ "python": "3.13.7",
21
+ "torch": "2.8.0+cu128",
22
+ "triton": "3.4.0",
23
+ "safetensors": "0.8.0"
24
+ },
25
+ "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",
26
+ "official_profile_reference": {
27
+ "repository": "openai/gpt-oss-20b",
28
+ "revision": "6cee5e81ee83917806bbde320786a8fb61efebee",
29
+ "config_sha256": "317522155fc243327ee341857d0c752d0094a0817e0e9aee2890d5ad8e009e04",
30
+ "dtypes_sha256": "566c9e6aded8957f41f1589cabaf73e39f2d1fcda3351d63efdfb7e9e78d376b"
31
+ },
32
+ "profile": {
33
+ "expert_weights": [
34
+ "mlp1_weight",
35
+ "mlp2_weight"
36
+ ],
37
+ "expert_value_format": "E2M1",
38
+ "expert_scale_format": "E8M0",
39
+ "block_size": 32,
40
+ "values_per_byte": 2,
41
+ "nibble_order": "low-nibble-first",
42
+ "scale_bias": 127,
43
+ "non_expert_dtype": "BF16"
44
+ },
45
+ "outputs": {
46
+ "model_sha256": "30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d",
47
+ "config_sha256": "f9be3908850cc3def17375cbbae101c1b6ee801b4db7315489dbe6f513d4affe",
48
+ "dtypes_sha256": "fa36ec5d12a062717c28c7bb53535e1e29d70ea1b41e32c8ec137888df2309c8",
49
+ "tensor_inventory_sha256": "99d24cda1c1441cc3ff04776a618e432b3e3f3ba6ddd33bc2b9342d2ca3b68a5",
50
+ "tensor_count": 93,
51
+ "total_tensor_bytes": 2325648
52
+ }
53
+ }
original/dtypes.json ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "embedding.weight": "BF16",
3
+ "block.0.attn.norm.scale": "BF16",
4
+ "block.0.attn.qkv.weight": "BF16",
5
+ "block.0.attn.qkv.bias": "BF16",
6
+ "block.0.attn.sinks": "BF16",
7
+ "block.0.attn.out.weight": "BF16",
8
+ "block.0.attn.out.bias": "BF16",
9
+ "block.0.mlp.norm.scale": "BF16",
10
+ "block.0.mlp.gate.weight": "BF16",
11
+ "block.0.mlp.gate.bias": "BF16",
12
+ "block.0.mlp.mlp1_weight.blocks": "FP4",
13
+ "block.0.mlp.mlp1_weight.scales": "UE8",
14
+ "block.0.mlp.mlp1_bias": "BF16",
15
+ "block.0.mlp.mlp2_weight.blocks": "FP4",
16
+ "block.0.mlp.mlp2_weight.scales": "UE8",
17
+ "block.0.mlp.mlp2_bias": "BF16",
18
+ "block.1.attn.norm.scale": "BF16",
19
+ "block.1.attn.qkv.weight": "BF16",
20
+ "block.1.attn.qkv.bias": "BF16",
21
+ "block.1.attn.sinks": "BF16",
22
+ "block.1.attn.out.weight": "BF16",
23
+ "block.1.attn.out.bias": "BF16",
24
+ "block.1.mlp.norm.scale": "BF16",
25
+ "block.1.mlp.gate.weight": "BF16",
26
+ "block.1.mlp.gate.bias": "BF16",
27
+ "block.1.mlp.mlp1_weight.blocks": "FP4",
28
+ "block.1.mlp.mlp1_weight.scales": "UE8",
29
+ "block.1.mlp.mlp1_bias": "BF16",
30
+ "block.1.mlp.mlp2_weight.blocks": "FP4",
31
+ "block.1.mlp.mlp2_weight.scales": "UE8",
32
+ "block.1.mlp.mlp2_bias": "BF16",
33
+ "block.2.attn.norm.scale": "BF16",
34
+ "block.2.attn.qkv.weight": "BF16",
35
+ "block.2.attn.qkv.bias": "BF16",
36
+ "block.2.attn.sinks": "BF16",
37
+ "block.2.attn.out.weight": "BF16",
38
+ "block.2.attn.out.bias": "BF16",
39
+ "block.2.mlp.norm.scale": "BF16",
40
+ "block.2.mlp.gate.weight": "BF16",
41
+ "block.2.mlp.gate.bias": "BF16",
42
+ "block.2.mlp.mlp1_weight.blocks": "FP4",
43
+ "block.2.mlp.mlp1_weight.scales": "UE8",
44
+ "block.2.mlp.mlp1_bias": "BF16",
45
+ "block.2.mlp.mlp2_weight.blocks": "FP4",
46
+ "block.2.mlp.mlp2_weight.scales": "UE8",
47
+ "block.2.mlp.mlp2_bias": "BF16",
48
+ "block.3.attn.norm.scale": "BF16",
49
+ "block.3.attn.qkv.weight": "BF16",
50
+ "block.3.attn.qkv.bias": "BF16",
51
+ "block.3.attn.sinks": "BF16",
52
+ "block.3.attn.out.weight": "BF16",
53
+ "block.3.attn.out.bias": "BF16",
54
+ "block.3.mlp.norm.scale": "BF16",
55
+ "block.3.mlp.gate.weight": "BF16",
56
+ "block.3.mlp.gate.bias": "BF16",
57
+ "block.3.mlp.mlp1_weight.blocks": "FP4",
58
+ "block.3.mlp.mlp1_weight.scales": "UE8",
59
+ "block.3.mlp.mlp1_bias": "BF16",
60
+ "block.3.mlp.mlp2_weight.blocks": "FP4",
61
+ "block.3.mlp.mlp2_weight.scales": "UE8",
62
+ "block.3.mlp.mlp2_bias": "BF16",
63
+ "block.4.attn.norm.scale": "BF16",
64
+ "block.4.attn.qkv.weight": "BF16",
65
+ "block.4.attn.qkv.bias": "BF16",
66
+ "block.4.attn.sinks": "BF16",
67
+ "block.4.attn.out.weight": "BF16",
68
+ "block.4.attn.out.bias": "BF16",
69
+ "block.4.mlp.norm.scale": "BF16",
70
+ "block.4.mlp.gate.weight": "BF16",
71
+ "block.4.mlp.gate.bias": "BF16",
72
+ "block.4.mlp.mlp1_weight.blocks": "FP4",
73
+ "block.4.mlp.mlp1_weight.scales": "UE8",
74
+ "block.4.mlp.mlp1_bias": "BF16",
75
+ "block.4.mlp.mlp2_weight.blocks": "FP4",
76
+ "block.4.mlp.mlp2_weight.scales": "UE8",
77
+ "block.4.mlp.mlp2_bias": "BF16",
78
+ "block.5.attn.norm.scale": "BF16",
79
+ "block.5.attn.qkv.weight": "BF16",
80
+ "block.5.attn.qkv.bias": "BF16",
81
+ "block.5.attn.sinks": "BF16",
82
+ "block.5.attn.out.weight": "BF16",
83
+ "block.5.attn.out.bias": "BF16",
84
+ "block.5.mlp.norm.scale": "BF16",
85
+ "block.5.mlp.gate.weight": "BF16",
86
+ "block.5.mlp.gate.bias": "BF16",
87
+ "block.5.mlp.mlp1_weight.blocks": "FP4",
88
+ "block.5.mlp.mlp1_weight.scales": "UE8",
89
+ "block.5.mlp.mlp1_bias": "BF16",
90
+ "block.5.mlp.mlp2_weight.blocks": "FP4",
91
+ "block.5.mlp.mlp2_weight.scales": "UE8",
92
+ "block.5.mlp.mlp2_bias": "BF16",
93
+ "norm.scale": "BF16",
94
+ "unembedding.weight": "BF16"
95
+ }
original/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:30dac8e68ccf869d872beb382cebd0be8b168de761dfb38f1358d260d4b8d09d
3
+ size 2334056
original/tensor_inventory.json ADDED
@@ -0,0 +1,1121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "tensor_count": 93,
3
+ "total_tensor_bytes": 2325648,
4
+ "tensors": [
5
+ {
6
+ "name": "block.0.attn.norm.scale",
7
+ "profile_dtype": "BF16",
8
+ "storage_dtype": "bfloat16",
9
+ "shape": [
10
+ 128
11
+ ],
12
+ "numel": 128,
13
+ "nbytes": 256,
14
+ "tensor_sha256": "eccf6206b565034cbae911aefab9c5a7dc483288cafd3f454089bc37ea39334d"
15
+ },
16
+ {
17
+ "name": "block.0.attn.out.bias",
18
+ "profile_dtype": "BF16",
19
+ "storage_dtype": "bfloat16",
20
+ "shape": [
21
+ 128
22
+ ],
23
+ "numel": 128,
24
+ "nbytes": 256,
25
+ "tensor_sha256": "c3f9fca0599156bb298857bcb3085fda3f768064d702bd1b8014cf532bd9f715"
26
+ },
27
+ {
28
+ "name": "block.0.attn.out.weight",
29
+ "profile_dtype": "BF16",
30
+ "storage_dtype": "bfloat16",
31
+ "shape": [
32
+ 128,
33
+ 128
34
+ ],
35
+ "numel": 16384,
36
+ "nbytes": 32768,
37
+ "tensor_sha256": "d95bf0cad74e0854831f86981303760e10ec3c2f4ccf4b027b145b8d251a51c3"
38
+ },
39
+ {
40
+ "name": "block.0.attn.qkv.bias",
41
+ "profile_dtype": "BF16",
42
+ "storage_dtype": "bfloat16",
43
+ "shape": [
44
+ 192
45
+ ],
46
+ "numel": 192,
47
+ "nbytes": 384,
48
+ "tensor_sha256": "87074fba354a69d4c62022329006b2013c49686bc497b126e20f3a8e71fd1e9b"
49
+ },
50
+ {
51
+ "name": "block.0.attn.qkv.weight",
52
+ "profile_dtype": "BF16",
53
+ "storage_dtype": "bfloat16",
54
+ "shape": [
55
+ 192,
56
+ 128
57
+ ],
58
+ "numel": 24576,
59
+ "nbytes": 49152,
60
+ "tensor_sha256": "e1944b4f33dafdf6f86d59a78aa6093a20c71c5ca044be20992bb9df146ba1cc"
61
+ },
62
+ {
63
+ "name": "block.0.attn.sinks",
64
+ "profile_dtype": "BF16",
65
+ "storage_dtype": "bfloat16",
66
+ "shape": [
67
+ 4
68
+ ],
69
+ "numel": 4,
70
+ "nbytes": 8,
71
+ "tensor_sha256": "295ddf9b80c106900373a47e8bc3283c7d46496cb85a80ce9beecf919bffa36d"
72
+ },
73
+ {
74
+ "name": "block.0.mlp.gate.bias",
75
+ "profile_dtype": "BF16",
76
+ "storage_dtype": "bfloat16",
77
+ "shape": [
78
+ 8
79
+ ],
80
+ "numel": 8,
81
+ "nbytes": 16,
82
+ "tensor_sha256": "a39a0ec9a48054ed024cf42fd0348cf417b140f67a2c35657fd4e927a0db0e72"
83
+ },
84
+ {
85
+ "name": "block.0.mlp.gate.weight",
86
+ "profile_dtype": "BF16",
87
+ "storage_dtype": "bfloat16",
88
+ "shape": [
89
+ 8,
90
+ 128
91
+ ],
92
+ "numel": 1024,
93
+ "nbytes": 2048,
94
+ "tensor_sha256": "4bd377300b228d0fdfec98a8d48fbb37e4f86cddfb20333dd063162d30b4d327"
95
+ },
96
+ {
97
+ "name": "block.0.mlp.mlp1_bias",
98
+ "profile_dtype": "BF16",
99
+ "storage_dtype": "bfloat16",
100
+ "shape": [
101
+ 8,
102
+ 256
103
+ ],
104
+ "numel": 2048,
105
+ "nbytes": 4096,
106
+ "tensor_sha256": "d9a0ab2d73984206682035017d3cd8fe5a775059df2d9ac1f595af5ec2bc9ebd"
107
+ },
108
+ {
109
+ "name": "block.0.mlp.mlp1_weight.blocks",
110
+ "profile_dtype": "FP4",
111
+ "storage_dtype": "uint8",
112
+ "shape": [
113
+ 8,
114
+ 256,
115
+ 4,
116
+ 16
117
+ ],
118
+ "numel": 131072,
119
+ "nbytes": 131072,
120
+ "tensor_sha256": "d0ac79ceb22dc812565c5ba380d391b03dc8ca5294827eadc479c880543aacee"
121
+ },
122
+ {
123
+ "name": "block.0.mlp.mlp1_weight.scales",
124
+ "profile_dtype": "UE8",
125
+ "storage_dtype": "uint8",
126
+ "shape": [
127
+ 8,
128
+ 256,
129
+ 4
130
+ ],
131
+ "numel": 8192,
132
+ "nbytes": 8192,
133
+ "tensor_sha256": "90262d9132d9834b218ab379ba3edf958c880ffc604f3b45cb8bbb0d90d33130"
134
+ },
135
+ {
136
+ "name": "block.0.mlp.mlp2_bias",
137
+ "profile_dtype": "BF16",
138
+ "storage_dtype": "bfloat16",
139
+ "shape": [
140
+ 8,
141
+ 128
142
+ ],
143
+ "numel": 1024,
144
+ "nbytes": 2048,
145
+ "tensor_sha256": "449d510ec646b8bcc3a79ed5f71a7161c3e56f6db720bc4accf91c93e91a41e3"
146
+ },
147
+ {
148
+ "name": "block.0.mlp.mlp2_weight.blocks",
149
+ "profile_dtype": "FP4",
150
+ "storage_dtype": "uint8",
151
+ "shape": [
152
+ 8,
153
+ 128,
154
+ 4,
155
+ 16
156
+ ],
157
+ "numel": 65536,
158
+ "nbytes": 65536,
159
+ "tensor_sha256": "5e5dc1deac2d388d49843cc7585b6ae14ad51bbe623102e4a225dfa3e38b6f8d"
160
+ },
161
+ {
162
+ "name": "block.0.mlp.mlp2_weight.scales",
163
+ "profile_dtype": "UE8",
164
+ "storage_dtype": "uint8",
165
+ "shape": [
166
+ 8,
167
+ 128,
168
+ 4
169
+ ],
170
+ "numel": 4096,
171
+ "nbytes": 4096,
172
+ "tensor_sha256": "ac8cb8c5ef0cf4d742f23d9b054fd08b6dd4b9f74838631d42c3090ef585cbdd"
173
+ },
174
+ {
175
+ "name": "block.0.mlp.norm.scale",
176
+ "profile_dtype": "BF16",
177
+ "storage_dtype": "bfloat16",
178
+ "shape": [
179
+ 128
180
+ ],
181
+ "numel": 128,
182
+ "nbytes": 256,
183
+ "tensor_sha256": "b63ff56f26e563de022aab5369580eda5d74578a5f22cc9dd56bf6db0f1d7082"
184
+ },
185
+ {
186
+ "name": "block.1.attn.norm.scale",
187
+ "profile_dtype": "BF16",
188
+ "storage_dtype": "bfloat16",
189
+ "shape": [
190
+ 128
191
+ ],
192
+ "numel": 128,
193
+ "nbytes": 256,
194
+ "tensor_sha256": "83cf4c38d54a727a4c7fb56ae3cc75ecff6bcf9ead14607ada8b0be293eec882"
195
+ },
196
+ {
197
+ "name": "block.1.attn.out.bias",
198
+ "profile_dtype": "BF16",
199
+ "storage_dtype": "bfloat16",
200
+ "shape": [
201
+ 128
202
+ ],
203
+ "numel": 128,
204
+ "nbytes": 256,
205
+ "tensor_sha256": "fbfa71e7dc3809307c8501fec973d7a1ab81ebedcbbb4b1b9b40cec5522f70d5"
206
+ },
207
+ {
208
+ "name": "block.1.attn.out.weight",
209
+ "profile_dtype": "BF16",
210
+ "storage_dtype": "bfloat16",
211
+ "shape": [
212
+ 128,
213
+ 128
214
+ ],
215
+ "numel": 16384,
216
+ "nbytes": 32768,
217
+ "tensor_sha256": "6dd7263990966265cb55a5e8ea08a72853c012a9e64248d907699d28a862fb51"
218
+ },
219
+ {
220
+ "name": "block.1.attn.qkv.bias",
221
+ "profile_dtype": "BF16",
222
+ "storage_dtype": "bfloat16",
223
+ "shape": [
224
+ 192
225
+ ],
226
+ "numel": 192,
227
+ "nbytes": 384,
228
+ "tensor_sha256": "5e1e38393fa6ab1456475ae99c4f39dace4c2a2f6a60de0d66685fb633d00d8e"
229
+ },
230
+ {
231
+ "name": "block.1.attn.qkv.weight",
232
+ "profile_dtype": "BF16",
233
+ "storage_dtype": "bfloat16",
234
+ "shape": [
235
+ 192,
236
+ 128
237
+ ],
238
+ "numel": 24576,
239
+ "nbytes": 49152,
240
+ "tensor_sha256": "d10d95738b787c9f0f4e40c8889a734e91e010b94631aa4b0430d9f29d606d4d"
241
+ },
242
+ {
243
+ "name": "block.1.attn.sinks",
244
+ "profile_dtype": "BF16",
245
+ "storage_dtype": "bfloat16",
246
+ "shape": [
247
+ 4
248
+ ],
249
+ "numel": 4,
250
+ "nbytes": 8,
251
+ "tensor_sha256": "a117079fbf84f8c53350f712ee5ec94f14ef7f60310448c1c52c08b481f44ba2"
252
+ },
253
+ {
254
+ "name": "block.1.mlp.gate.bias",
255
+ "profile_dtype": "BF16",
256
+ "storage_dtype": "bfloat16",
257
+ "shape": [
258
+ 8
259
+ ],
260
+ "numel": 8,
261
+ "nbytes": 16,
262
+ "tensor_sha256": "e5af7ddf38f2ae2b2cb5afeaeac8ffd8ae4db992998f0e9bdd08471de8386f00"
263
+ },
264
+ {
265
+ "name": "block.1.mlp.gate.weight",
266
+ "profile_dtype": "BF16",
267
+ "storage_dtype": "bfloat16",
268
+ "shape": [
269
+ 8,
270
+ 128
271
+ ],
272
+ "numel": 1024,
273
+ "nbytes": 2048,
274
+ "tensor_sha256": "8e5c37e0f732ce2bb0810948716dc8efb24959cd60f3fc36bab8e5c0054000d4"
275
+ },
276
+ {
277
+ "name": "block.1.mlp.mlp1_bias",
278
+ "profile_dtype": "BF16",
279
+ "storage_dtype": "bfloat16",
280
+ "shape": [
281
+ 8,
282
+ 256
283
+ ],
284
+ "numel": 2048,
285
+ "nbytes": 4096,
286
+ "tensor_sha256": "ead631eded681e83c149d5ad987504ef57d4d852698b1e332f50e937bf61ce2b"
287
+ },
288
+ {
289
+ "name": "block.1.mlp.mlp1_weight.blocks",
290
+ "profile_dtype": "FP4",
291
+ "storage_dtype": "uint8",
292
+ "shape": [
293
+ 8,
294
+ 256,
295
+ 4,
296
+ 16
297
+ ],
298
+ "numel": 131072,
299
+ "nbytes": 131072,
300
+ "tensor_sha256": "e87b455f4612e44c79fc1a6af39899f6773beee29d2477ae4dbb8b5d514c3dcd"
301
+ },
302
+ {
303
+ "name": "block.1.mlp.mlp1_weight.scales",
304
+ "profile_dtype": "UE8",
305
+ "storage_dtype": "uint8",
306
+ "shape": [
307
+ 8,
308
+ 256,
309
+ 4
310
+ ],
311
+ "numel": 8192,
312
+ "nbytes": 8192,
313
+ "tensor_sha256": "7ec5077d46ca6072fc767e945f3de37522182e754732dc2230fa972dc416c5c8"
314
+ },
315
+ {
316
+ "name": "block.1.mlp.mlp2_bias",
317
+ "profile_dtype": "BF16",
318
+ "storage_dtype": "bfloat16",
319
+ "shape": [
320
+ 8,
321
+ 128
322
+ ],
323
+ "numel": 1024,
324
+ "nbytes": 2048,
325
+ "tensor_sha256": "61febd0af1c19417497e9d0db0cf6063fe5f581c4232197ac5d17d59685e32ff"
326
+ },
327
+ {
328
+ "name": "block.1.mlp.mlp2_weight.blocks",
329
+ "profile_dtype": "FP4",
330
+ "storage_dtype": "uint8",
331
+ "shape": [
332
+ 8,
333
+ 128,
334
+ 4,
335
+ 16
336
+ ],
337
+ "numel": 65536,
338
+ "nbytes": 65536,
339
+ "tensor_sha256": "66df91b2652cf14f96f2b1542ad45d3c6742b3d4986f347493d4b9cf52c5e8ac"
340
+ },
341
+ {
342
+ "name": "block.1.mlp.mlp2_weight.scales",
343
+ "profile_dtype": "UE8",
344
+ "storage_dtype": "uint8",
345
+ "shape": [
346
+ 8,
347
+ 128,
348
+ 4
349
+ ],
350
+ "numel": 4096,
351
+ "nbytes": 4096,
352
+ "tensor_sha256": "91d42170629b6c5ddd387ddd24cd59ea6b434ed567c081c54d858aa8e4558ba7"
353
+ },
354
+ {
355
+ "name": "block.1.mlp.norm.scale",
356
+ "profile_dtype": "BF16",
357
+ "storage_dtype": "bfloat16",
358
+ "shape": [
359
+ 128
360
+ ],
361
+ "numel": 128,
362
+ "nbytes": 256,
363
+ "tensor_sha256": "68363b0cc5e0c20ff11f9b0107039584f3aa8bb166779428f6df0b6f3f562fee"
364
+ },
365
+ {
366
+ "name": "block.2.attn.norm.scale",
367
+ "profile_dtype": "BF16",
368
+ "storage_dtype": "bfloat16",
369
+ "shape": [
370
+ 128
371
+ ],
372
+ "numel": 128,
373
+ "nbytes": 256,
374
+ "tensor_sha256": "6e2b8342c7466915587ff9d08464018674d63e0cec5bfdeae8b9268cf12b6de8"
375
+ },
376
+ {
377
+ "name": "block.2.attn.out.bias",
378
+ "profile_dtype": "BF16",
379
+ "storage_dtype": "bfloat16",
380
+ "shape": [
381
+ 128
382
+ ],
383
+ "numel": 128,
384
+ "nbytes": 256,
385
+ "tensor_sha256": "366efbc20599e24880cb6cb7104caf9b795a879d0b3a04486353b2ca402ef1b1"
386
+ },
387
+ {
388
+ "name": "block.2.attn.out.weight",
389
+ "profile_dtype": "BF16",
390
+ "storage_dtype": "bfloat16",
391
+ "shape": [
392
+ 128,
393
+ 128
394
+ ],
395
+ "numel": 16384,
396
+ "nbytes": 32768,
397
+ "tensor_sha256": "566031b008db7b923f19583f172c30ec6ba016cc542c696bb28d3f7fc5ab589e"
398
+ },
399
+ {
400
+ "name": "block.2.attn.qkv.bias",
401
+ "profile_dtype": "BF16",
402
+ "storage_dtype": "bfloat16",
403
+ "shape": [
404
+ 192
405
+ ],
406
+ "numel": 192,
407
+ "nbytes": 384,
408
+ "tensor_sha256": "f1098142b9f8e484df961e76053c0e5185643d91808fc0b36eb6bc0f5b03175a"
409
+ },
410
+ {
411
+ "name": "block.2.attn.qkv.weight",
412
+ "profile_dtype": "BF16",
413
+ "storage_dtype": "bfloat16",
414
+ "shape": [
415
+ 192,
416
+ 128
417
+ ],
418
+ "numel": 24576,
419
+ "nbytes": 49152,
420
+ "tensor_sha256": "e4711d5191b1858069796141f4c39c384bf45f62f6d2386bb81d6af13ea4b53b"
421
+ },
422
+ {
423
+ "name": "block.2.attn.sinks",
424
+ "profile_dtype": "BF16",
425
+ "storage_dtype": "bfloat16",
426
+ "shape": [
427
+ 4
428
+ ],
429
+ "numel": 4,
430
+ "nbytes": 8,
431
+ "tensor_sha256": "92dfb6f47e247ad094f13290f11fc41e788f4b9f9ace9dd69151bf77701da41e"
432
+ },
433
+ {
434
+ "name": "block.2.mlp.gate.bias",
435
+ "profile_dtype": "BF16",
436
+ "storage_dtype": "bfloat16",
437
+ "shape": [
438
+ 8
439
+ ],
440
+ "numel": 8,
441
+ "nbytes": 16,
442
+ "tensor_sha256": "a25f01749a28dcb48c5b1bba82915073fc0725405167bc48e65a5f1c5168650a"
443
+ },
444
+ {
445
+ "name": "block.2.mlp.gate.weight",
446
+ "profile_dtype": "BF16",
447
+ "storage_dtype": "bfloat16",
448
+ "shape": [
449
+ 8,
450
+ 128
451
+ ],
452
+ "numel": 1024,
453
+ "nbytes": 2048,
454
+ "tensor_sha256": "d6a5332f558e60c6ab499182817dbb69be4d5ccc54f49c26ab0ac2e41688c9b3"
455
+ },
456
+ {
457
+ "name": "block.2.mlp.mlp1_bias",
458
+ "profile_dtype": "BF16",
459
+ "storage_dtype": "bfloat16",
460
+ "shape": [
461
+ 8,
462
+ 256
463
+ ],
464
+ "numel": 2048,
465
+ "nbytes": 4096,
466
+ "tensor_sha256": "62283e7f26a3806807c9ac37e2e3fdb0cce7775227db14c66a1414f6fed89c53"
467
+ },
468
+ {
469
+ "name": "block.2.mlp.mlp1_weight.blocks",
470
+ "profile_dtype": "FP4",
471
+ "storage_dtype": "uint8",
472
+ "shape": [
473
+ 8,
474
+ 256,
475
+ 4,
476
+ 16
477
+ ],
478
+ "numel": 131072,
479
+ "nbytes": 131072,
480
+ "tensor_sha256": "022584a26dd938b7659332af69b2047539911c800b08474ba9e5ab2bdc784300"
481
+ },
482
+ {
483
+ "name": "block.2.mlp.mlp1_weight.scales",
484
+ "profile_dtype": "UE8",
485
+ "storage_dtype": "uint8",
486
+ "shape": [
487
+ 8,
488
+ 256,
489
+ 4
490
+ ],
491
+ "numel": 8192,
492
+ "nbytes": 8192,
493
+ "tensor_sha256": "e380540cad368470ffabf8725de2d74d56d3fc05117a36218ba9a1df73e21788"
494
+ },
495
+ {
496
+ "name": "block.2.mlp.mlp2_bias",
497
+ "profile_dtype": "BF16",
498
+ "storage_dtype": "bfloat16",
499
+ "shape": [
500
+ 8,
501
+ 128
502
+ ],
503
+ "numel": 1024,
504
+ "nbytes": 2048,
505
+ "tensor_sha256": "ff9e10da6f5e16f91876ef5724e9825f6a59e057e063fbf51bd0850d0524d694"
506
+ },
507
+ {
508
+ "name": "block.2.mlp.mlp2_weight.blocks",
509
+ "profile_dtype": "FP4",
510
+ "storage_dtype": "uint8",
511
+ "shape": [
512
+ 8,
513
+ 128,
514
+ 4,
515
+ 16
516
+ ],
517
+ "numel": 65536,
518
+ "nbytes": 65536,
519
+ "tensor_sha256": "178904bea25592b069946c8cadd1301715ef0a5c8082ba0d9f817e039c991d63"
520
+ },
521
+ {
522
+ "name": "block.2.mlp.mlp2_weight.scales",
523
+ "profile_dtype": "UE8",
524
+ "storage_dtype": "uint8",
525
+ "shape": [
526
+ 8,
527
+ 128,
528
+ 4
529
+ ],
530
+ "numel": 4096,
531
+ "nbytes": 4096,
532
+ "tensor_sha256": "d84dcdd10ce6ee20c75b3a46cf29540dfc4c5f223d69321897f59bd681ba8515"
533
+ },
534
+ {
535
+ "name": "block.2.mlp.norm.scale",
536
+ "profile_dtype": "BF16",
537
+ "storage_dtype": "bfloat16",
538
+ "shape": [
539
+ 128
540
+ ],
541
+ "numel": 128,
542
+ "nbytes": 256,
543
+ "tensor_sha256": "be8f537c77171cbcbefbd987ff1501ae5bed6fb883c16d6a34b698876f1ee3b4"
544
+ },
545
+ {
546
+ "name": "block.3.attn.norm.scale",
547
+ "profile_dtype": "BF16",
548
+ "storage_dtype": "bfloat16",
549
+ "shape": [
550
+ 128
551
+ ],
552
+ "numel": 128,
553
+ "nbytes": 256,
554
+ "tensor_sha256": "a63a9daec9ce2d3eeac2fbbeae74b0138e6ba1ab9dda9ad4fa2554e0c2ca2de1"
555
+ },
556
+ {
557
+ "name": "block.3.attn.out.bias",
558
+ "profile_dtype": "BF16",
559
+ "storage_dtype": "bfloat16",
560
+ "shape": [
561
+ 128
562
+ ],
563
+ "numel": 128,
564
+ "nbytes": 256,
565
+ "tensor_sha256": "342ea41e39091ddea3dceb699eae5a3f06b2d925bbc4c67ad9886d9caa4d53da"
566
+ },
567
+ {
568
+ "name": "block.3.attn.out.weight",
569
+ "profile_dtype": "BF16",
570
+ "storage_dtype": "bfloat16",
571
+ "shape": [
572
+ 128,
573
+ 128
574
+ ],
575
+ "numel": 16384,
576
+ "nbytes": 32768,
577
+ "tensor_sha256": "057794a40c48b05ad393b17db48203dbcb28cb67f2060645f02a98a6c6829f1c"
578
+ },
579
+ {
580
+ "name": "block.3.attn.qkv.bias",
581
+ "profile_dtype": "BF16",
582
+ "storage_dtype": "bfloat16",
583
+ "shape": [
584
+ 192
585
+ ],
586
+ "numel": 192,
587
+ "nbytes": 384,
588
+ "tensor_sha256": "856e44029cca502df4abbc3995a1470ee25fb33f39890136806af561beb9088e"
589
+ },
590
+ {
591
+ "name": "block.3.attn.qkv.weight",
592
+ "profile_dtype": "BF16",
593
+ "storage_dtype": "bfloat16",
594
+ "shape": [
595
+ 192,
596
+ 128
597
+ ],
598
+ "numel": 24576,
599
+ "nbytes": 49152,
600
+ "tensor_sha256": "e56cc7e6c0e132cea4fa41cf4815d742521974bc10d67154faea7a50f69dcad4"
601
+ },
602
+ {
603
+ "name": "block.3.attn.sinks",
604
+ "profile_dtype": "BF16",
605
+ "storage_dtype": "bfloat16",
606
+ "shape": [
607
+ 4
608
+ ],
609
+ "numel": 4,
610
+ "nbytes": 8,
611
+ "tensor_sha256": "61cb27dc684d0a0547f12e76b164aa50ace8f3d63ba6c830da694c92fa5f097b"
612
+ },
613
+ {
614
+ "name": "block.3.mlp.gate.bias",
615
+ "profile_dtype": "BF16",
616
+ "storage_dtype": "bfloat16",
617
+ "shape": [
618
+ 8
619
+ ],
620
+ "numel": 8,
621
+ "nbytes": 16,
622
+ "tensor_sha256": "2a05530d4e67ca5c305a49f2b4f3dfa35214d2d6bf2980b1d39deb62c4696b1c"
623
+ },
624
+ {
625
+ "name": "block.3.mlp.gate.weight",
626
+ "profile_dtype": "BF16",
627
+ "storage_dtype": "bfloat16",
628
+ "shape": [
629
+ 8,
630
+ 128
631
+ ],
632
+ "numel": 1024,
633
+ "nbytes": 2048,
634
+ "tensor_sha256": "0254ec6589ab9894a11d4b7fe11900dba9f5715aa7f1a29dfc5aad6c7fbdb01e"
635
+ },
636
+ {
637
+ "name": "block.3.mlp.mlp1_bias",
638
+ "profile_dtype": "BF16",
639
+ "storage_dtype": "bfloat16",
640
+ "shape": [
641
+ 8,
642
+ 256
643
+ ],
644
+ "numel": 2048,
645
+ "nbytes": 4096,
646
+ "tensor_sha256": "a4b8b349adfaf60be1e8f5dd89cb9dc236e596c6045f7d3bdd7573e0fdcca4e9"
647
+ },
648
+ {
649
+ "name": "block.3.mlp.mlp1_weight.blocks",
650
+ "profile_dtype": "FP4",
651
+ "storage_dtype": "uint8",
652
+ "shape": [
653
+ 8,
654
+ 256,
655
+ 4,
656
+ 16
657
+ ],
658
+ "numel": 131072,
659
+ "nbytes": 131072,
660
+ "tensor_sha256": "ad0f0d6726de843bf2c766a40b1fd3f3ea5f0844bce9238193455b3ada7357cc"
661
+ },
662
+ {
663
+ "name": "block.3.mlp.mlp1_weight.scales",
664
+ "profile_dtype": "UE8",
665
+ "storage_dtype": "uint8",
666
+ "shape": [
667
+ 8,
668
+ 256,
669
+ 4
670
+ ],
671
+ "numel": 8192,
672
+ "nbytes": 8192,
673
+ "tensor_sha256": "63973340238aceb7e6158b3b2a1b227bac28ab2924a07e16f25cfa4ea03e0e72"
674
+ },
675
+ {
676
+ "name": "block.3.mlp.mlp2_bias",
677
+ "profile_dtype": "BF16",
678
+ "storage_dtype": "bfloat16",
679
+ "shape": [
680
+ 8,
681
+ 128
682
+ ],
683
+ "numel": 1024,
684
+ "nbytes": 2048,
685
+ "tensor_sha256": "b4c9587a5885563ff92e98626e16e859bab5ca2a22061fb0eb4a478def07ed97"
686
+ },
687
+ {
688
+ "name": "block.3.mlp.mlp2_weight.blocks",
689
+ "profile_dtype": "FP4",
690
+ "storage_dtype": "uint8",
691
+ "shape": [
692
+ 8,
693
+ 128,
694
+ 4,
695
+ 16
696
+ ],
697
+ "numel": 65536,
698
+ "nbytes": 65536,
699
+ "tensor_sha256": "8c8ce501f6b10800c56f9053a71e3aadc4ea2cdbd1cdf711ac70f39e9b2493e5"
700
+ },
701
+ {
702
+ "name": "block.3.mlp.mlp2_weight.scales",
703
+ "profile_dtype": "UE8",
704
+ "storage_dtype": "uint8",
705
+ "shape": [
706
+ 8,
707
+ 128,
708
+ 4
709
+ ],
710
+ "numel": 4096,
711
+ "nbytes": 4096,
712
+ "tensor_sha256": "ced5ca3bc9bf9bf8060326484a79514cb17478b54a056b6bade9c936af146726"
713
+ },
714
+ {
715
+ "name": "block.3.mlp.norm.scale",
716
+ "profile_dtype": "BF16",
717
+ "storage_dtype": "bfloat16",
718
+ "shape": [
719
+ 128
720
+ ],
721
+ "numel": 128,
722
+ "nbytes": 256,
723
+ "tensor_sha256": "e3f47dc61b2798a760d584319069246b56891571eadd2a51ee8fadc1fc83aac0"
724
+ },
725
+ {
726
+ "name": "block.4.attn.norm.scale",
727
+ "profile_dtype": "BF16",
728
+ "storage_dtype": "bfloat16",
729
+ "shape": [
730
+ 128
731
+ ],
732
+ "numel": 128,
733
+ "nbytes": 256,
734
+ "tensor_sha256": "411109db41ab85e6668a07b60509aa321745699e7c2acbba38ed6b2cb77b99d9"
735
+ },
736
+ {
737
+ "name": "block.4.attn.out.bias",
738
+ "profile_dtype": "BF16",
739
+ "storage_dtype": "bfloat16",
740
+ "shape": [
741
+ 128
742
+ ],
743
+ "numel": 128,
744
+ "nbytes": 256,
745
+ "tensor_sha256": "1d145798ca557f230c7a5559243173723ac013b408dca1a5af37ae95f81fcd40"
746
+ },
747
+ {
748
+ "name": "block.4.attn.out.weight",
749
+ "profile_dtype": "BF16",
750
+ "storage_dtype": "bfloat16",
751
+ "shape": [
752
+ 128,
753
+ 128
754
+ ],
755
+ "numel": 16384,
756
+ "nbytes": 32768,
757
+ "tensor_sha256": "8af8f74e0b4a220b62680b3a26d429a531bd7db70b5a1d77cf7cb4895eb72484"
758
+ },
759
+ {
760
+ "name": "block.4.attn.qkv.bias",
761
+ "profile_dtype": "BF16",
762
+ "storage_dtype": "bfloat16",
763
+ "shape": [
764
+ 192
765
+ ],
766
+ "numel": 192,
767
+ "nbytes": 384,
768
+ "tensor_sha256": "6dee9f3beeef2fe7699ad3d6297b97a86be3fb42761141c2301018fa95710a74"
769
+ },
770
+ {
771
+ "name": "block.4.attn.qkv.weight",
772
+ "profile_dtype": "BF16",
773
+ "storage_dtype": "bfloat16",
774
+ "shape": [
775
+ 192,
776
+ 128
777
+ ],
778
+ "numel": 24576,
779
+ "nbytes": 49152,
780
+ "tensor_sha256": "a7669d41f636b05f66d4e3ab3db8a7e8e1584cba7915dc930226760a63f9cf28"
781
+ },
782
+ {
783
+ "name": "block.4.attn.sinks",
784
+ "profile_dtype": "BF16",
785
+ "storage_dtype": "bfloat16",
786
+ "shape": [
787
+ 4
788
+ ],
789
+ "numel": 4,
790
+ "nbytes": 8,
791
+ "tensor_sha256": "e4876b0316d2a8ef7f4e3fa6dcdfb7b04114d8a0f8aedc8605a3f8d1ef0e83cf"
792
+ },
793
+ {
794
+ "name": "block.4.mlp.gate.bias",
795
+ "profile_dtype": "BF16",
796
+ "storage_dtype": "bfloat16",
797
+ "shape": [
798
+ 8
799
+ ],
800
+ "numel": 8,
801
+ "nbytes": 16,
802
+ "tensor_sha256": "a46518dc141801777ea50b8723d71cfebb64c4f0524b54e8d553b52f7439135c"
803
+ },
804
+ {
805
+ "name": "block.4.mlp.gate.weight",
806
+ "profile_dtype": "BF16",
807
+ "storage_dtype": "bfloat16",
808
+ "shape": [
809
+ 8,
810
+ 128
811
+ ],
812
+ "numel": 1024,
813
+ "nbytes": 2048,
814
+ "tensor_sha256": "c6b3682df23d9c07674962210066010f90755836d948c437561b933e1d168e8b"
815
+ },
816
+ {
817
+ "name": "block.4.mlp.mlp1_bias",
818
+ "profile_dtype": "BF16",
819
+ "storage_dtype": "bfloat16",
820
+ "shape": [
821
+ 8,
822
+ 256
823
+ ],
824
+ "numel": 2048,
825
+ "nbytes": 4096,
826
+ "tensor_sha256": "22ee8aaffbdb4421b6cd54a7ed58d6f439567c7e7c443a52e95bcc084b74edab"
827
+ },
828
+ {
829
+ "name": "block.4.mlp.mlp1_weight.blocks",
830
+ "profile_dtype": "FP4",
831
+ "storage_dtype": "uint8",
832
+ "shape": [
833
+ 8,
834
+ 256,
835
+ 4,
836
+ 16
837
+ ],
838
+ "numel": 131072,
839
+ "nbytes": 131072,
840
+ "tensor_sha256": "a50822355f9c1b4c625294f6f0ba162e09c6ca4b308dc9b52a5d5311682dde25"
841
+ },
842
+ {
843
+ "name": "block.4.mlp.mlp1_weight.scales",
844
+ "profile_dtype": "UE8",
845
+ "storage_dtype": "uint8",
846
+ "shape": [
847
+ 8,
848
+ 256,
849
+ 4
850
+ ],
851
+ "numel": 8192,
852
+ "nbytes": 8192,
853
+ "tensor_sha256": "b9d1b50f963382e1ed34355421c8091642183d0856482149cbef32f4f32627ef"
854
+ },
855
+ {
856
+ "name": "block.4.mlp.mlp2_bias",
857
+ "profile_dtype": "BF16",
858
+ "storage_dtype": "bfloat16",
859
+ "shape": [
860
+ 8,
861
+ 128
862
+ ],
863
+ "numel": 1024,
864
+ "nbytes": 2048,
865
+ "tensor_sha256": "c6bde1e2894a2a4ea5555faccdea0f1787ad56f39acb552e1097dfda3b91d1a6"
866
+ },
867
+ {
868
+ "name": "block.4.mlp.mlp2_weight.blocks",
869
+ "profile_dtype": "FP4",
870
+ "storage_dtype": "uint8",
871
+ "shape": [
872
+ 8,
873
+ 128,
874
+ 4,
875
+ 16
876
+ ],
877
+ "numel": 65536,
878
+ "nbytes": 65536,
879
+ "tensor_sha256": "2b9f453cac8c3bc740b552cfcdf5dac414d4ecf5594bf5cc7ba72bd5135f9595"
880
+ },
881
+ {
882
+ "name": "block.4.mlp.mlp2_weight.scales",
883
+ "profile_dtype": "UE8",
884
+ "storage_dtype": "uint8",
885
+ "shape": [
886
+ 8,
887
+ 128,
888
+ 4
889
+ ],
890
+ "numel": 4096,
891
+ "nbytes": 4096,
892
+ "tensor_sha256": "51f2aed84152cd33655ecc33bc1aaf895955ab01b90c28540d8fcaeaa4b2c75c"
893
+ },
894
+ {
895
+ "name": "block.4.mlp.norm.scale",
896
+ "profile_dtype": "BF16",
897
+ "storage_dtype": "bfloat16",
898
+ "shape": [
899
+ 128
900
+ ],
901
+ "numel": 128,
902
+ "nbytes": 256,
903
+ "tensor_sha256": "c583f057e81a175b0f8faebba532f0b775138c3b29019fd8d28685d3ebfb9b6c"
904
+ },
905
+ {
906
+ "name": "block.5.attn.norm.scale",
907
+ "profile_dtype": "BF16",
908
+ "storage_dtype": "bfloat16",
909
+ "shape": [
910
+ 128
911
+ ],
912
+ "numel": 128,
913
+ "nbytes": 256,
914
+ "tensor_sha256": "89676d9c580766cfd9172b5d7050cb43628e127102ab766a18ddcb7235093620"
915
+ },
916
+ {
917
+ "name": "block.5.attn.out.bias",
918
+ "profile_dtype": "BF16",
919
+ "storage_dtype": "bfloat16",
920
+ "shape": [
921
+ 128
922
+ ],
923
+ "numel": 128,
924
+ "nbytes": 256,
925
+ "tensor_sha256": "a9d2eea381c89d51d7c96374e9c0e2cb082b87783aee002e62d86065eecc0fb2"
926
+ },
927
+ {
928
+ "name": "block.5.attn.out.weight",
929
+ "profile_dtype": "BF16",
930
+ "storage_dtype": "bfloat16",
931
+ "shape": [
932
+ 128,
933
+ 128
934
+ ],
935
+ "numel": 16384,
936
+ "nbytes": 32768,
937
+ "tensor_sha256": "f2ca3c84225d7acf3386a7c3d4a9b07b2d717f379b645564a8a84137199b07e1"
938
+ },
939
+ {
940
+ "name": "block.5.attn.qkv.bias",
941
+ "profile_dtype": "BF16",
942
+ "storage_dtype": "bfloat16",
943
+ "shape": [
944
+ 192
945
+ ],
946
+ "numel": 192,
947
+ "nbytes": 384,
948
+ "tensor_sha256": "e0ad88cc16c2daf0db1dfe0d6909fea440fa304d9b716cc1cc445276765d71d9"
949
+ },
950
+ {
951
+ "name": "block.5.attn.qkv.weight",
952
+ "profile_dtype": "BF16",
953
+ "storage_dtype": "bfloat16",
954
+ "shape": [
955
+ 192,
956
+ 128
957
+ ],
958
+ "numel": 24576,
959
+ "nbytes": 49152,
960
+ "tensor_sha256": "81d4cfba44bab6d7914f27ab61896bcc84a2d814059ce000f5e12657d4a41866"
961
+ },
962
+ {
963
+ "name": "block.5.attn.sinks",
964
+ "profile_dtype": "BF16",
965
+ "storage_dtype": "bfloat16",
966
+ "shape": [
967
+ 4
968
+ ],
969
+ "numel": 4,
970
+ "nbytes": 8,
971
+ "tensor_sha256": "16e389e81866d6ec7e85ad3e2dd70e714428f4d92f5be84fca0b5e518ee33325"
972
+ },
973
+ {
974
+ "name": "block.5.mlp.gate.bias",
975
+ "profile_dtype": "BF16",
976
+ "storage_dtype": "bfloat16",
977
+ "shape": [
978
+ 8
979
+ ],
980
+ "numel": 8,
981
+ "nbytes": 16,
982
+ "tensor_sha256": "e913d05270793f26e74da05493c26165a8ce46afb19f44031d109db53ac341a7"
983
+ },
984
+ {
985
+ "name": "block.5.mlp.gate.weight",
986
+ "profile_dtype": "BF16",
987
+ "storage_dtype": "bfloat16",
988
+ "shape": [
989
+ 8,
990
+ 128
991
+ ],
992
+ "numel": 1024,
993
+ "nbytes": 2048,
994
+ "tensor_sha256": "782d4ddcc67b12bda908b0a4355b468df94e87d576ceae9db61bf35e5fc11f0b"
995
+ },
996
+ {
997
+ "name": "block.5.mlp.mlp1_bias",
998
+ "profile_dtype": "BF16",
999
+ "storage_dtype": "bfloat16",
1000
+ "shape": [
1001
+ 8,
1002
+ 256
1003
+ ],
1004
+ "numel": 2048,
1005
+ "nbytes": 4096,
1006
+ "tensor_sha256": "1280153cf4f5b8d1a248abb7a080f8770792f58e5374ff1a3d0a16f04e38f191"
1007
+ },
1008
+ {
1009
+ "name": "block.5.mlp.mlp1_weight.blocks",
1010
+ "profile_dtype": "FP4",
1011
+ "storage_dtype": "uint8",
1012
+ "shape": [
1013
+ 8,
1014
+ 256,
1015
+ 4,
1016
+ 16
1017
+ ],
1018
+ "numel": 131072,
1019
+ "nbytes": 131072,
1020
+ "tensor_sha256": "19c88563037e63e3d3ebb0fd9ba6edbba2b9b4ad1ae314fccfe44a396e8ab904"
1021
+ },
1022
+ {
1023
+ "name": "block.5.mlp.mlp1_weight.scales",
1024
+ "profile_dtype": "UE8",
1025
+ "storage_dtype": "uint8",
1026
+ "shape": [
1027
+ 8,
1028
+ 256,
1029
+ 4
1030
+ ],
1031
+ "numel": 8192,
1032
+ "nbytes": 8192,
1033
+ "tensor_sha256": "f7ddf93e3c0ab64ef3224f8e3ea6047c9e37681302e2a0f256784839059fa422"
1034
+ },
1035
+ {
1036
+ "name": "block.5.mlp.mlp2_bias",
1037
+ "profile_dtype": "BF16",
1038
+ "storage_dtype": "bfloat16",
1039
+ "shape": [
1040
+ 8,
1041
+ 128
1042
+ ],
1043
+ "numel": 1024,
1044
+ "nbytes": 2048,
1045
+ "tensor_sha256": "368c68c9d3b6d499d1dc53ad5f1b730817a589554af94bf6bf6334636977634f"
1046
+ },
1047
+ {
1048
+ "name": "block.5.mlp.mlp2_weight.blocks",
1049
+ "profile_dtype": "FP4",
1050
+ "storage_dtype": "uint8",
1051
+ "shape": [
1052
+ 8,
1053
+ 128,
1054
+ 4,
1055
+ 16
1056
+ ],
1057
+ "numel": 65536,
1058
+ "nbytes": 65536,
1059
+ "tensor_sha256": "896d96385e51bed7a0ccd2538525787564ad235f32d7ee389d02f6dd5dba7efe"
1060
+ },
1061
+ {
1062
+ "name": "block.5.mlp.mlp2_weight.scales",
1063
+ "profile_dtype": "UE8",
1064
+ "storage_dtype": "uint8",
1065
+ "shape": [
1066
+ 8,
1067
+ 128,
1068
+ 4
1069
+ ],
1070
+ "numel": 4096,
1071
+ "nbytes": 4096,
1072
+ "tensor_sha256": "e6d33e18970c9a8ba0ab4862464ed1e88b61519b4d9637ff2acc405d7cd28aae"
1073
+ },
1074
+ {
1075
+ "name": "block.5.mlp.norm.scale",
1076
+ "profile_dtype": "BF16",
1077
+ "storage_dtype": "bfloat16",
1078
+ "shape": [
1079
+ 128
1080
+ ],
1081
+ "numel": 128,
1082
+ "nbytes": 256,
1083
+ "tensor_sha256": "50323ecbb641619272668d71d2c2bdd0b2c59048bf4dba9913fa136faa6a0454"
1084
+ },
1085
+ {
1086
+ "name": "embedding.weight",
1087
+ "profile_dtype": "BF16",
1088
+ "storage_dtype": "bfloat16",
1089
+ "shape": [
1090
+ 1024,
1091
+ 128
1092
+ ],
1093
+ "numel": 131072,
1094
+ "nbytes": 262144,
1095
+ "tensor_sha256": "175c0ba5dab18fbf041cdb19362eed8820aec016a83b7dd144e965d5c0869f07"
1096
+ },
1097
+ {
1098
+ "name": "norm.scale",
1099
+ "profile_dtype": "BF16",
1100
+ "storage_dtype": "bfloat16",
1101
+ "shape": [
1102
+ 128
1103
+ ],
1104
+ "numel": 128,
1105
+ "nbytes": 256,
1106
+ "tensor_sha256": "8740cb20ea1a531ef2f4cf3c5e3244d108727c24b48050f51a5ba63131082906"
1107
+ },
1108
+ {
1109
+ "name": "unembedding.weight",
1110
+ "profile_dtype": "BF16",
1111
+ "storage_dtype": "bfloat16",
1112
+ "shape": [
1113
+ 1024,
1114
+ 128
1115
+ ],
1116
+ "numel": 131072,
1117
+ "nbytes": 262144,
1118
+ "tensor_sha256": "27061dff957ec99df5ccbc99fe4aa89c6645676611fbbf2bcdd80203c5fda931"
1119
+ }
1120
+ ]
1121
+ }
requirements-mxfp4.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch==2.8.0
2
+ triton==3.4.0
3
+ safetensors==0.8.0
4
+ tokenizers==0.22.2
5
+ numpy==2.5.1
6
+ pytest==9.1.1
7
+ huggingface_hub==1.26.0
tools/convert_tinygptoss_to_mxfp4.py ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Convert the tiny HF gpt-oss checkpoint to the official MXFP4 profile."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import hashlib
8
+ import json
9
+ import platform
10
+ import subprocess
11
+ import sys
12
+ from pathlib import Path
13
+
14
+ import torch
15
+ from safetensors.torch import load_file, save_file
16
+
17
+
18
+ OPENAI_GPT_OSS_REVISION = "599476783c6f88508dab8577808b5ead5cbee8d2"
19
+ TRITON_KERNELS_REVISION = "9e1e203f64752cf99abf0e44286231c5d5df7e76"
20
+ OFFICIAL_PROFILE_REPO = "openai/gpt-oss-20b"
21
+ OFFICIAL_PROFILE_REVISION = "6cee5e81ee83917806bbde320786a8fb61efebee"
22
+ OFFICIAL_PROFILE_CONFIG_SHA256 = "317522155fc243327ee341857d0c752d0094a0817e0e9aee2890d5ad8e009e04"
23
+ OFFICIAL_PROFILE_DTYPES_SHA256 = "566c9e6aded8957f41f1589cabaf73e39f2d1fcda3351d63efdfb7e9e78d376b"
24
+ BLOCK_SIZE = 32
25
+ PACKED_BYTES_PER_BLOCK = 16
26
+
27
+
28
+ def parse_args() -> argparse.Namespace:
29
+ parser = argparse.ArgumentParser(description=__doc__)
30
+ parser.add_argument("--source-dir", type=Path, required=True)
31
+ parser.add_argument("--output-dir", type=Path, required=True)
32
+ parser.add_argument("--openai-repo", type=Path, required=True)
33
+ parser.add_argument("--triton-repo", type=Path, required=True)
34
+ return parser.parse_args()
35
+
36
+
37
+ def sha256_file(path: Path) -> str:
38
+ digest = hashlib.sha256()
39
+ with path.open("rb") as handle:
40
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
41
+ digest.update(chunk)
42
+ return digest.hexdigest()
43
+
44
+
45
+ def git_revision(path: Path) -> str:
46
+ return subprocess.check_output(
47
+ ["git", "-C", str(path), "rev-parse", "HEAD"],
48
+ text=True,
49
+ ).strip()
50
+
51
+
52
+ def require_revision(path: Path, expected: str, label: str) -> None:
53
+ actual = git_revision(path)
54
+ if actual != expected:
55
+ raise RuntimeError(f"{label} revision mismatch: expected {expected}, got {actual}")
56
+
57
+
58
+ def import_official_quantizer(openai_repo: Path, triton_repo: Path):
59
+ sys.path.insert(0, str(openai_repo.resolve()))
60
+ sys.path.insert(0, str((triton_repo / "python" / "triton_kernels").resolve()))
61
+ from triton_kernels.numerics_details.mxfp import ( # noqa: PLC0415
62
+ DequantScaleRoundingMode,
63
+ downcast_to_mxfp_torch,
64
+ )
65
+
66
+ return downcast_to_mxfp_torch, DequantScaleRoundingMode
67
+
68
+
69
+ def validate_source_config(config: dict) -> None:
70
+ layers = config["num_hidden_layers"]
71
+ expected_layer_types = [
72
+ "sliding_attention" if i % 2 == 0 else "full_attention"
73
+ for i in range(layers)
74
+ ]
75
+ checks = {
76
+ "model_type": config.get("model_type") == "gpt_oss",
77
+ "alternating layer types": config.get("layer_types") == expected_layer_types,
78
+ "attention bias": config.get("attention_bias") is True,
79
+ "untied embeddings": config.get("tie_word_embeddings") is False,
80
+ "RMSNorm epsilon": config.get("rms_norm_eps") == 1e-5,
81
+ "hidden size block alignment": config["hidden_size"] % BLOCK_SIZE == 0,
82
+ "intermediate size block alignment": config["intermediate_size"] % BLOCK_SIZE == 0,
83
+ }
84
+ failures = [name for name, passed in checks.items() if not passed]
85
+ if failures:
86
+ raise ValueError("Source is incompatible with the official profile: " + ", ".join(failures))
87
+
88
+
89
+ def official_config(source: dict) -> dict:
90
+ rope = source["rope_parameters"]
91
+ return {
92
+ "num_hidden_layers": source["num_hidden_layers"],
93
+ "num_experts": source["num_local_experts"],
94
+ "experts_per_token": source["num_experts_per_tok"],
95
+ "vocab_size": source["vocab_size"],
96
+ "hidden_size": source["hidden_size"],
97
+ "intermediate_size": source["intermediate_size"],
98
+ "swiglu_limit": source["swiglu_limit"],
99
+ "head_dim": source["head_dim"],
100
+ "num_attention_heads": source["num_attention_heads"],
101
+ "num_key_value_heads": source["num_key_value_heads"],
102
+ "sliding_window": source["sliding_window"],
103
+ "initial_context_length": source["initial_context_length"],
104
+ "rope_theta": rope["rope_theta"],
105
+ "rope_scaling_factor": rope["factor"],
106
+ "rope_ntk_alpha": rope["beta_slow"],
107
+ "rope_ntk_beta": rope["beta_fast"],
108
+ }
109
+
110
+
111
+ def to_bf16(tensor: torch.Tensor) -> torch.Tensor:
112
+ if not torch.isfinite(tensor).all():
113
+ raise ValueError("Source tensor contains non-finite values")
114
+ return tensor.to(torch.bfloat16).contiguous()
115
+
116
+
117
+ def quantize_expert_weight(
118
+ tensor: torch.Tensor,
119
+ downcast_to_mxfp_torch,
120
+ rounding_mode,
121
+ ) -> tuple[torch.Tensor, torch.Tensor]:
122
+ if tensor.shape[-1] % BLOCK_SIZE:
123
+ raise ValueError(f"MXFP4 axis must be divisible by {BLOCK_SIZE}: {tuple(tensor.shape)}")
124
+ if not torch.isfinite(tensor).all():
125
+ raise ValueError("Source expert tensor contains non-finite values")
126
+
127
+ flat_blocks, scales = downcast_to_mxfp_torch(
128
+ tensor.contiguous(),
129
+ torch.uint8,
130
+ -1,
131
+ rounding_mode.ROUND_DOWN,
132
+ )
133
+ expected_flat = tensor.shape[-1] // 2
134
+ if flat_blocks.shape[-1] != expected_flat:
135
+ raise RuntimeError(f"Unexpected packed shape: {tuple(flat_blocks.shape)}")
136
+ blocks = flat_blocks.reshape(
137
+ *tensor.shape[:-1],
138
+ tensor.shape[-1] // BLOCK_SIZE,
139
+ PACKED_BYTES_PER_BLOCK,
140
+ ).contiguous()
141
+ expected_scales = (*tensor.shape[:-1], tensor.shape[-1] // BLOCK_SIZE)
142
+ if tuple(scales.shape) != expected_scales:
143
+ raise RuntimeError(f"Unexpected scale shape: {tuple(scales.shape)} != {expected_scales}")
144
+ return blocks, scales.contiguous()
145
+
146
+
147
+ def tensor_bytes(tensor: torch.Tensor) -> bytes:
148
+ return tensor.detach().cpu().contiguous().view(torch.uint8).numpy().tobytes()
149
+
150
+
151
+ def make_inventory(tensors: dict[str, torch.Tensor], dtypes: dict[str, str]) -> dict:
152
+ entries = []
153
+ total_bytes = 0
154
+ for name in sorted(tensors):
155
+ tensor = tensors[name]
156
+ raw = tensor_bytes(tensor)
157
+ total_bytes += len(raw)
158
+ entries.append(
159
+ {
160
+ "name": name,
161
+ "profile_dtype": dtypes[name],
162
+ "storage_dtype": str(tensor.dtype).removeprefix("torch."),
163
+ "shape": list(tensor.shape),
164
+ "numel": tensor.numel(),
165
+ "nbytes": len(raw),
166
+ "tensor_sha256": hashlib.sha256(raw).hexdigest(),
167
+ }
168
+ )
169
+ return {
170
+ "tensor_count": len(entries),
171
+ "total_tensor_bytes": total_bytes,
172
+ "tensors": entries,
173
+ }
174
+
175
+
176
+ def main() -> None:
177
+ args = parse_args()
178
+ source_dir = args.source_dir.resolve()
179
+ output_dir = args.output_dir.resolve()
180
+ openai_repo = args.openai_repo.resolve()
181
+ triton_repo = args.triton_repo.resolve()
182
+
183
+ require_revision(openai_repo, OPENAI_GPT_OSS_REVISION, "OpenAI gpt-oss")
184
+ require_revision(triton_repo, TRITON_KERNELS_REVISION, "Triton kernels")
185
+ downcast_to_mxfp_torch, rounding_mode = import_official_quantizer(openai_repo, triton_repo)
186
+
187
+ source_config_path = source_dir / "config.json"
188
+ source_model_path = source_dir / "model.safetensors"
189
+ source_config = json.loads(source_config_path.read_text(encoding="utf-8"))
190
+ validate_source_config(source_config)
191
+ state = load_file(source_model_path, device="cpu")
192
+
193
+ tensors: dict[str, torch.Tensor] = {}
194
+ dtypes: dict[str, str] = {}
195
+
196
+ def add_bf16(name: str, value: torch.Tensor) -> None:
197
+ tensors[name] = to_bf16(value)
198
+ dtypes[name] = "BF16"
199
+
200
+ def add_mxfp4(name: str, value: torch.Tensor) -> None:
201
+ blocks, scales = quantize_expert_weight(
202
+ value,
203
+ downcast_to_mxfp_torch,
204
+ rounding_mode,
205
+ )
206
+ tensors[f"{name}.blocks"] = blocks
207
+ tensors[f"{name}.scales"] = scales
208
+ dtypes[f"{name}.blocks"] = "FP4"
209
+ dtypes[f"{name}.scales"] = "UE8"
210
+
211
+ add_bf16("embedding.weight", state["model.embed_tokens.weight"])
212
+ for layer in range(source_config["num_hidden_layers"]):
213
+ src = f"model.layers.{layer}"
214
+ dst = f"block.{layer}"
215
+ add_bf16(f"{dst}.attn.norm.scale", state[f"{src}.input_layernorm.weight"])
216
+ add_bf16(
217
+ f"{dst}.attn.qkv.weight",
218
+ torch.cat(
219
+ [
220
+ state[f"{src}.self_attn.q_proj.weight"],
221
+ state[f"{src}.self_attn.k_proj.weight"],
222
+ state[f"{src}.self_attn.v_proj.weight"],
223
+ ],
224
+ dim=0,
225
+ ),
226
+ )
227
+ add_bf16(
228
+ f"{dst}.attn.qkv.bias",
229
+ torch.cat(
230
+ [
231
+ state[f"{src}.self_attn.q_proj.bias"],
232
+ state[f"{src}.self_attn.k_proj.bias"],
233
+ state[f"{src}.self_attn.v_proj.bias"],
234
+ ],
235
+ dim=0,
236
+ ),
237
+ )
238
+ add_bf16(f"{dst}.attn.sinks", state[f"{src}.self_attn.sinks"])
239
+ add_bf16(f"{dst}.attn.out.weight", state[f"{src}.self_attn.o_proj.weight"])
240
+ add_bf16(f"{dst}.attn.out.bias", state[f"{src}.self_attn.o_proj.bias"])
241
+
242
+ add_bf16(f"{dst}.mlp.norm.scale", state[f"{src}.post_attention_layernorm.weight"])
243
+ add_bf16(f"{dst}.mlp.gate.weight", state[f"{src}.mlp.router.weight"])
244
+ add_bf16(f"{dst}.mlp.gate.bias", state[f"{src}.mlp.router.bias"])
245
+
246
+ mlp1 = state[f"{src}.mlp.experts.gate_up_proj"].transpose(1, 2).contiguous()
247
+ add_mxfp4(f"{dst}.mlp.mlp1_weight", mlp1)
248
+ add_bf16(f"{dst}.mlp.mlp1_bias", state[f"{src}.mlp.experts.gate_up_proj_bias"])
249
+
250
+ mlp2 = state[f"{src}.mlp.experts.down_proj"].transpose(1, 2).contiguous()
251
+ add_mxfp4(f"{dst}.mlp.mlp2_weight", mlp2)
252
+ add_bf16(f"{dst}.mlp.mlp2_bias", state[f"{src}.mlp.experts.down_proj_bias"])
253
+
254
+ add_bf16("norm.scale", state["model.norm.weight"])
255
+ add_bf16("unembedding.weight", state["lm_head.weight"])
256
+
257
+ output_dir.mkdir(parents=True, exist_ok=True)
258
+ model_path = output_dir / "model.safetensors"
259
+ config_path = output_dir / "config.json"
260
+ dtypes_path = output_dir / "dtypes.json"
261
+ inventory_path = output_dir / "tensor_inventory.json"
262
+ manifest_path = output_dir / "conversion_manifest.json"
263
+
264
+ # Safetensors metadata maps are emitted through an unordered map and can
265
+ # change byte order between processes. Keep the model file metadata-free
266
+ # so its SHA-256 is reproducible; profile details live in the adjacent
267
+ # dtypes.json and conversion_manifest.json files.
268
+ save_file(tensors, model_path)
269
+ config_path.write_text(json.dumps(official_config(source_config), indent=2) + "\n", encoding="utf-8")
270
+ dtypes_path.write_text(json.dumps(dtypes, indent=2) + "\n", encoding="utf-8")
271
+ inventory = make_inventory(tensors, dtypes)
272
+ inventory_path.write_text(json.dumps(inventory, indent=2) + "\n", encoding="utf-8")
273
+
274
+ manifest = {
275
+ "format": "openai-gpt-oss-original-mxfp4",
276
+ "source": {
277
+ "repository": "shibatch/tinygptossmoe3m",
278
+ "subfolder": "hf",
279
+ "model_sha256": sha256_file(source_model_path),
280
+ "config_sha256": sha256_file(source_config_path),
281
+ },
282
+ "official_implementation": {
283
+ "repository": "https://github.com/openai/gpt-oss.git",
284
+ "revision": OPENAI_GPT_OSS_REVISION,
285
+ },
286
+ "official_quantizer_dependency": {
287
+ "repository": "https://github.com/triton-lang/triton.git",
288
+ "revision": TRITON_KERNELS_REVISION,
289
+ "api": "triton_kernels.numerics_details.mxfp.downcast_to_mxfp_torch",
290
+ "rounding_mode": "DequantScaleRoundingMode.ROUND_DOWN",
291
+ },
292
+ "conversion_environment": {
293
+ "python": platform.python_version(),
294
+ "torch": torch.__version__,
295
+ "triton": __import__("triton").__version__,
296
+ "safetensors": __import__("safetensors").__version__,
297
+ },
298
+ "reproduction_command": (
299
+ "PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels "
300
+ "python tools/convert_tinygptoss_to_mxfp4.py "
301
+ "--source-dir hf --output-dir rebuilt/original "
302
+ "--openai-repo third_party/openai-gpt-oss --triton-repo third_party/triton"
303
+ ),
304
+ "official_profile_reference": {
305
+ "repository": OFFICIAL_PROFILE_REPO,
306
+ "revision": OFFICIAL_PROFILE_REVISION,
307
+ "config_sha256": OFFICIAL_PROFILE_CONFIG_SHA256,
308
+ "dtypes_sha256": OFFICIAL_PROFILE_DTYPES_SHA256,
309
+ },
310
+ "profile": {
311
+ "expert_weights": ["mlp1_weight", "mlp2_weight"],
312
+ "expert_value_format": "E2M1",
313
+ "expert_scale_format": "E8M0",
314
+ "block_size": BLOCK_SIZE,
315
+ "values_per_byte": 2,
316
+ "nibble_order": "low-nibble-first",
317
+ "scale_bias": 127,
318
+ "non_expert_dtype": "BF16",
319
+ },
320
+ "outputs": {
321
+ "model_sha256": sha256_file(model_path),
322
+ "config_sha256": sha256_file(config_path),
323
+ "dtypes_sha256": sha256_file(dtypes_path),
324
+ "tensor_inventory_sha256": sha256_file(inventory_path),
325
+ "tensor_count": inventory["tensor_count"],
326
+ "total_tensor_bytes": inventory["total_tensor_bytes"],
327
+ },
328
+ }
329
+ manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
330
+
331
+ print(f"Wrote {model_path}")
332
+ print(f"Tensor count: {inventory['tensor_count']}")
333
+ print(f"Model SHA-256: {manifest['outputs']['model_sha256']}")
334
+
335
+
336
+ if __name__ == "__main__":
337
+ main()
tools/generate_gptoss_mxfp4_reference.py ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Generate deterministic reference vectors with pinned OpenAI gpt-oss code."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import hashlib
8
+ import json
9
+ import subprocess
10
+ import sys
11
+ from pathlib import Path
12
+
13
+ import torch
14
+ from safetensors.torch import save_file
15
+ from tokenizers import Tokenizer
16
+
17
+
18
+ OPENAI_GPT_OSS_REVISION = "599476783c6f88508dab8577808b5ead5cbee8d2"
19
+ TRITON_KERNELS_REVISION = "9e1e203f64752cf99abf0e44286231c5d5df7e76"
20
+
21
+
22
+ def parse_args() -> argparse.Namespace:
23
+ parser = argparse.ArgumentParser(description=__doc__)
24
+ parser.add_argument("--checkpoint", type=Path, required=True)
25
+ parser.add_argument("--tokenizer", type=Path, required=True)
26
+ parser.add_argument("--output-dir", type=Path, required=True)
27
+ parser.add_argument("--openai-repo", type=Path, required=True)
28
+ parser.add_argument("--triton-repo", type=Path, required=True)
29
+ parser.add_argument("--prompt", default="Once upon a time,")
30
+ parser.add_argument("--max-new-tokens", type=int, default=64)
31
+ parser.add_argument("--context", type=int, default=256)
32
+ parser.add_argument("--device", default="cuda:0")
33
+ return parser.parse_args()
34
+
35
+
36
+ def sha256_file(path: Path) -> str:
37
+ digest = hashlib.sha256()
38
+ with path.open("rb") as handle:
39
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
40
+ digest.update(chunk)
41
+ return digest.hexdigest()
42
+
43
+
44
+ def require_revision(path: Path, expected: str, label: str) -> None:
45
+ actual = subprocess.check_output(
46
+ ["git", "-C", str(path), "rev-parse", "HEAD"],
47
+ text=True,
48
+ ).strip()
49
+ if actual != expected:
50
+ raise RuntimeError(f"{label} revision mismatch: expected {expected}, got {actual}")
51
+
52
+
53
+ def install_import_paths(openai_repo: Path, triton_repo: Path) -> None:
54
+ sys.path.insert(0, str(openai_repo.resolve()))
55
+ sys.path.insert(0, str((triton_repo / "python" / "triton_kernels").resolve()))
56
+
57
+
58
+ def install_tiny_attention_adapter(triton_model) -> dict:
59
+ """Adapt tiny GQA dimensions while retaining OpenAI's reference attention."""
60
+ official_attention_ref = triton_model.attention_ref
61
+
62
+ def adapted_attention_ref(q, *args, **kwargs):
63
+ # OpenAI's model builds [B,T,groups,kv_heads,D], while the official
64
+ # attention function consumes [B,T,kv_heads,groups,D]. The released
65
+ # 20B/120B configs have equal middle dimensions, so this is invisible
66
+ # there. It must be explicit for this 1-KV-head tiny checkpoint.
67
+ return official_attention_ref(q.transpose(2, 3).contiguous(), *args, **kwargs)
68
+
69
+ # head_dim=32 is valid in attention_ref, but the fused kernel fixes
70
+ # BLOCK_N=64. Use the official reference function for both paths.
71
+ triton_model.attention = adapted_attention_ref
72
+ triton_model.attention_ref = adapted_attention_ref
73
+ return {
74
+ "gqa_axis_adapter": "transpose query dimensions 2 and 3",
75
+ "attention_backend": "gpt_oss.triton.attention.attention_ref",
76
+ "reason": "tiny config uses 1 KV head, 4 groups, and head_dim 32",
77
+ "official_source_modified": False,
78
+ }
79
+
80
+
81
+ @torch.inference_mode()
82
+ def full_and_cached_logits(model, triton_model, input_ids: torch.Tensor, context: int):
83
+ full = model(input_ids)
84
+ caches = [
85
+ triton_model.Cache(
86
+ input_ids.shape[0],
87
+ context,
88
+ model.config.num_key_value_heads,
89
+ d_head=model.config.head_dim,
90
+ device=input_ids.device,
91
+ )
92
+ for _ in model.block
93
+ ]
94
+ pieces = [model(input_ids[:, i : i + 1], caches=caches) for i in range(input_ids.shape[1])]
95
+ cached = torch.cat(pieces, dim=1)
96
+ return full.float(), cached.float()
97
+
98
+
99
+ @torch.inference_mode()
100
+ def routing_and_projection(torch_model, input_ids: torch.Tensor):
101
+ if input_ids.shape[0] != 1:
102
+ raise ValueError("The routing reference currently requires batch size 1")
103
+ x = torch_model.embedding(input_ids[0])
104
+ routing: dict[str, torch.Tensor] = {}
105
+ projections: dict[str, torch.Tensor] = {}
106
+
107
+ for layer_index, block in enumerate(torch_model.block):
108
+ x = block.attn(x)
109
+ t = block.mlp.norm(x)
110
+ router_logits = block.mlp.gate(t)
111
+ experts = torch.topk(
112
+ router_logits,
113
+ k=block.mlp.experts_per_token,
114
+ dim=-1,
115
+ sorted=True,
116
+ )
117
+ expert_weights = torch.softmax(experts.values, dim=1)
118
+ expert_ids = experts.indices
119
+
120
+ mlp1_weight = block.mlp.mlp1_weight[expert_ids]
121
+ mlp1_bias = block.mlp.mlp1_bias[expert_ids]
122
+ hidden = torch.einsum("teoh,th->teo", mlp1_weight, t) + mlp1_bias
123
+
124
+ from gpt_oss.torch.model import swiglu
125
+
126
+ hidden = swiglu(hidden, limit=block.mlp.swiglu_limit)
127
+ mlp2_weight = block.mlp.mlp2_weight[expert_ids]
128
+ mlp2_bias = block.mlp.mlp2_bias[expert_ids]
129
+ selected_output = torch.einsum("tehi,tei->teh", mlp2_weight, hidden) + mlp2_bias
130
+ weighted_sum = torch.einsum("teh,te->th", selected_output, expert_weights)
131
+
132
+ prefix = f"block.{layer_index}"
133
+ routing[f"{prefix}.expert_ids"] = expert_ids.cpu().contiguous()
134
+ routing[f"{prefix}.expert_weights"] = expert_weights.float().cpu().contiguous()
135
+ routing[f"{prefix}.router_logits"] = router_logits.float().cpu().contiguous()
136
+ projections[f"{prefix}.selected_expert_output"] = selected_output.float().cpu().contiguous()
137
+ projections[f"{prefix}.weighted_expert_output"] = weighted_sum.float().cpu().contiguous()
138
+ x = x + weighted_sum
139
+
140
+ logits = torch_model.unembedding(torch_model.norm(x)).float().unsqueeze(0)
141
+ return routing, projections, logits
142
+
143
+
144
+ @torch.inference_mode()
145
+ def greedy_continuation(
146
+ model,
147
+ triton_model,
148
+ prompt_ids: list[int],
149
+ eos_token_id: int,
150
+ max_new_tokens: int,
151
+ context: int,
152
+ device: torch.device,
153
+ ) -> list[int]:
154
+ if len(prompt_ids) + max_new_tokens > context:
155
+ raise ValueError("Prompt plus continuation exceeds cache context")
156
+ caches = [
157
+ triton_model.Cache(
158
+ 1,
159
+ context,
160
+ model.config.num_key_value_heads,
161
+ d_head=model.config.head_dim,
162
+ device=device,
163
+ )
164
+ for _ in model.block
165
+ ]
166
+ if len(prompt_ids) > 1:
167
+ prefix = torch.tensor([prompt_ids[:-1]], dtype=torch.int32, device=device)
168
+ model(prefix, caches=caches)
169
+
170
+ current = prompt_ids[-1]
171
+ generated: list[int] = []
172
+ for _ in range(max_new_tokens):
173
+ token = torch.tensor([[current]], dtype=torch.int32, device=device)
174
+ logits = model(token, caches=caches)[0, -1]
175
+ current = int(torch.argmax(logits).item())
176
+ generated.append(current)
177
+ if current == eos_token_id:
178
+ break
179
+ return generated
180
+
181
+
182
+ def main() -> None:
183
+ args = parse_args()
184
+ checkpoint = args.checkpoint.resolve()
185
+ tokenizer_path = args.tokenizer.resolve()
186
+ output_dir = args.output_dir.resolve()
187
+ openai_repo = args.openai_repo.resolve()
188
+ triton_repo = args.triton_repo.resolve()
189
+
190
+ require_revision(openai_repo, OPENAI_GPT_OSS_REVISION, "OpenAI gpt-oss")
191
+ require_revision(triton_repo, TRITON_KERNELS_REVISION, "Triton kernels")
192
+ install_import_paths(openai_repo, triton_repo)
193
+
194
+ import gpt_oss.triton.model as triton_model
195
+ from gpt_oss.torch.model import Transformer as TorchTransformer
196
+
197
+ adapter = install_tiny_attention_adapter(triton_model)
198
+ device = torch.device(args.device)
199
+ if device.type != "cuda":
200
+ raise ValueError("The official Triton cached path requires CUDA")
201
+
202
+ tokenizer = Tokenizer.from_file(str(tokenizer_path / "tokenizer.json"))
203
+ prompt_ids = tokenizer.encode(args.prompt, add_special_tokens=False).ids
204
+ if not prompt_ids:
205
+ raise ValueError("Prompt tokenized to an empty sequence")
206
+ eos_token_id = tokenizer.token_to_id("</s>")
207
+ if eos_token_id is None:
208
+ raise ValueError("Tokenizer does not define the </s> token")
209
+ input_ids = torch.tensor([prompt_ids], dtype=torch.int32, device=device)
210
+
211
+ triton_checkpoint = triton_model.Transformer.from_checkpoint(checkpoint, device=device)
212
+ full_logits, cached_logits = full_and_cached_logits(
213
+ triton_checkpoint,
214
+ triton_model,
215
+ input_ids,
216
+ args.context,
217
+ )
218
+
219
+ torch_checkpoint = TorchTransformer.from_checkpoint(checkpoint, device=device)
220
+ routing, projections, reconstructed_torch_logits = routing_and_projection(
221
+ torch_checkpoint,
222
+ input_ids,
223
+ )
224
+ direct_torch_logits = torch_checkpoint(input_ids[0]).float().unsqueeze(0)
225
+ torch.testing.assert_close(reconstructed_torch_logits, direct_torch_logits, rtol=0, atol=0)
226
+
227
+ generated_ids = greedy_continuation(
228
+ triton_checkpoint,
229
+ triton_model,
230
+ prompt_ids,
231
+ eos_token_id,
232
+ args.max_new_tokens,
233
+ args.context,
234
+ device,
235
+ )
236
+
237
+ output_dir.mkdir(parents=True, exist_ok=True)
238
+ full_path = output_dir / "full_logits.safetensors"
239
+ cached_path = output_dir / "cached_logits.safetensors"
240
+ routing_path = output_dir / "routing.safetensors"
241
+ projection_path = output_dir / "expert_projection.safetensors"
242
+ continuation_path = output_dir / "greedy_continuation.json"
243
+ manifest_path = output_dir / "reference_manifest.json"
244
+
245
+ save_file({"logits": full_logits.cpu().contiguous()}, full_path)
246
+ save_file({"logits": cached_logits.cpu().contiguous()}, cached_path)
247
+ save_file(routing, routing_path)
248
+ save_file(projections, projection_path)
249
+
250
+ continuation = {
251
+ "prompt": args.prompt,
252
+ "prompt_token_ids": prompt_ids,
253
+ "generated_token_ids": generated_ids,
254
+ "generated_text": tokenizer.decode(generated_ids, skip_special_tokens=True),
255
+ "full_text": tokenizer.decode(prompt_ids + generated_ids, skip_special_tokens=True),
256
+ "greedy": True,
257
+ "max_new_tokens": args.max_new_tokens,
258
+ "eos_token_id": eos_token_id,
259
+ "stopped_on_eos": bool(generated_ids and generated_ids[-1] == eos_token_id),
260
+ }
261
+ continuation_path.write_text(json.dumps(continuation, indent=2) + "\n", encoding="utf-8")
262
+
263
+ difference = (full_logits - cached_logits).abs()
264
+ torch_difference = (full_logits - direct_torch_logits).abs()
265
+ manifest = {
266
+ "checkpoint_model_sha256": sha256_file(checkpoint / "model.safetensors"),
267
+ "official_openai_revision": OPENAI_GPT_OSS_REVISION,
268
+ "triton_kernels_revision": TRITON_KERNELS_REVISION,
269
+ "device": torch.cuda.get_device_name(device),
270
+ "device_capability": list(torch.cuda.get_device_capability(device)),
271
+ "torch_version": torch.__version__,
272
+ "triton_version": __import__("triton").__version__,
273
+ "reproduction_command": (
274
+ "CUDA_VISIBLE_DEVICES=<gpu> "
275
+ "PYTHONPATH=third_party/openai-gpt-oss:third_party/triton/python/triton_kernels "
276
+ "python tools/generate_gptoss_mxfp4_reference.py "
277
+ "--checkpoint original --tokenizer hf --output-dir rebuilt/mxfp4_reference_outputs "
278
+ "--openai-repo third_party/openai-gpt-oss --triton-repo third_party/triton "
279
+ "--prompt 'Once upon a time,' --max-new-tokens 64 --context 256 --device cuda:0"
280
+ ),
281
+ "prompt": args.prompt,
282
+ "prompt_token_ids": prompt_ids,
283
+ "logits_shape": list(full_logits.shape),
284
+ "output_provenance": {
285
+ "full_logits": "gpt_oss.triton.model.Transformer full-sequence forward",
286
+ "cached_logits": "gpt_oss.triton.model.Transformer with per-layer Cache",
287
+ "greedy_continuation": "gpt_oss.triton.model.Transformer with per-layer Cache",
288
+ "routing": "gpt_oss.torch.model.Transformer MoE equations",
289
+ "expert_projection": "gpt_oss.torch.model.Transformer MoE equations",
290
+ },
291
+ "full_vs_cached": {
292
+ "max_abs_diff": float(difference.max().item()),
293
+ "mean_abs_diff": float(difference.mean().item()),
294
+ "all_token_argmax_equal": bool(
295
+ torch.equal(full_logits.argmax(dim=-1), cached_logits.argmax(dim=-1))
296
+ ),
297
+ },
298
+ "triton_full_vs_torch_full": {
299
+ "max_abs_diff": float(torch_difference.max().item()),
300
+ "mean_abs_diff": float(torch_difference.mean().item()),
301
+ "all_token_argmax_equal": bool(
302
+ torch.equal(full_logits.argmax(dim=-1), direct_torch_logits.argmax(dim=-1))
303
+ ),
304
+ },
305
+ "routing": {
306
+ "layers": len(torch_checkpoint.block),
307
+ "tokens": len(prompt_ids),
308
+ "experts_per_token": torch_checkpoint.block[0].mlp.experts_per_token,
309
+ "includes_router_logits": True,
310
+ },
311
+ "expert_projection": {
312
+ "selected_output_shape_per_layer": [
313
+ len(prompt_ids),
314
+ torch_checkpoint.block[0].mlp.experts_per_token,
315
+ torch_checkpoint.unembedding.in_features,
316
+ ],
317
+ "includes_weighted_sum": True,
318
+ },
319
+ "tiny_attention_adapter": adapter,
320
+ "files": {
321
+ full_path.name: sha256_file(full_path),
322
+ cached_path.name: sha256_file(cached_path),
323
+ routing_path.name: sha256_file(routing_path),
324
+ projection_path.name: sha256_file(projection_path),
325
+ continuation_path.name: sha256_file(continuation_path),
326
+ },
327
+ }
328
+ manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
329
+
330
+ print(json.dumps(manifest["full_vs_cached"], indent=2))
331
+ print(continuation["full_text"])
332
+
333
+
334
+ if __name__ == "__main__":
335
+ main()
tools/verify_mxfp4.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verify package hashes, tensor inventory, dtypes, and MXFP4 shapes."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import hashlib
7
+ import json
8
+ import struct
9
+ from pathlib import Path
10
+
11
+ import torch
12
+ from safetensors import safe_open
13
+
14
+
15
+ ROOT = Path(__file__).resolve().parent.parent
16
+
17
+
18
+ def sha256(path: Path) -> str:
19
+ digest = hashlib.sha256()
20
+ with path.open("rb") as handle:
21
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
22
+ digest.update(chunk)
23
+ return digest.hexdigest()
24
+
25
+
26
+ def tensor_sha256(tensor: torch.Tensor) -> str:
27
+ raw = tensor.contiguous().view(torch.uint8).numpy().tobytes()
28
+ return hashlib.sha256(raw).hexdigest()
29
+
30
+
31
+ def verify_file_hashes() -> None:
32
+ for line in (ROOT / "SHA256SUMS").read_text(encoding="utf-8").splitlines():
33
+ expected, relative = line.split(" ", 1)
34
+ actual = sha256(ROOT / relative)
35
+ if actual != expected:
36
+ raise RuntimeError(f"SHA-256 mismatch for {relative}: {actual} != {expected}")
37
+
38
+
39
+ def verify_model() -> int:
40
+ original = ROOT / "original"
41
+ dtypes = json.loads((original / "dtypes.json").read_text(encoding="utf-8"))
42
+ inventory = json.loads((original / "tensor_inventory.json").read_text(encoding="utf-8"))
43
+ entries = {entry["name"]: entry for entry in inventory["tensors"]}
44
+ model_path = original / "model.safetensors"
45
+ manifest = json.loads((original / "conversion_manifest.json").read_text(encoding="utf-8"))
46
+ if sha256(model_path) != manifest["outputs"]["model_sha256"]:
47
+ raise RuntimeError("Model hash does not match conversion_manifest.json")
48
+
49
+ with safe_open(model_path, framework="pt", device="cpu") as handle:
50
+ names = list(handle.keys())
51
+ if set(names) != set(dtypes) or set(names) != set(entries):
52
+ raise RuntimeError("Model, dtypes, and inventory tensor-name sets differ")
53
+ for name in names:
54
+ tensor = handle.get_tensor(name)
55
+ entry = entries[name]
56
+ if list(tensor.shape) != entry["shape"]:
57
+ raise RuntimeError(f"Shape mismatch for {name}")
58
+ if tensor_sha256(tensor) != entry["tensor_sha256"]:
59
+ raise RuntimeError(f"Tensor hash mismatch for {name}")
60
+ if name.endswith((".blocks", ".scales")):
61
+ if tensor.dtype != torch.uint8:
62
+ raise RuntimeError(f"MXFP4 storage must be U8: {name}")
63
+ elif tensor.dtype != torch.bfloat16:
64
+ raise RuntimeError(f"Non-expert tensor must be BF16: {name}")
65
+
66
+ for name in names:
67
+ if not name.endswith("_weight.blocks"):
68
+ continue
69
+ base = name.removesuffix(".blocks")
70
+ blocks = handle.get_tensor(name)
71
+ scales = handle.get_tensor(base + ".scales")
72
+ if blocks.shape[:-1] != scales.shape or blocks.shape[-1] != 16:
73
+ raise RuntimeError(f"Official MXFP4 block/scale shape mismatch: {base}")
74
+ if dtypes[name] != "FP4" or dtypes[base + ".scales"] != "UE8":
75
+ raise RuntimeError(f"Profile dtype mismatch: {base}")
76
+
77
+ return len(names)
78
+
79
+
80
+ def verify_packing_vector() -> None:
81
+ vector = json.loads((ROOT / "mxfp4_packing_test_vector.json").read_text(encoding="utf-8"))
82
+ fp4_values = [
83
+ 0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0,
84
+ -0.0, -0.5, -1.0, -1.5, -2.0, -3.0, -4.0, -6.0,
85
+ ]
86
+ decoded = []
87
+ for byte in vector["packed_uint8_decimal"]:
88
+ decoded.append(fp4_values[byte & 0x0F])
89
+ decoded.append(fp4_values[byte >> 4])
90
+ expected_bits = b"".join(struct.pack("<f", value) for value in vector["input_float32"])
91
+ decoded_bits = b"".join(struct.pack("<f", value) for value in decoded)
92
+ if decoded_bits != expected_bits:
93
+ raise RuntimeError("Low-nibble-first E2M1 packing vector did not round-trip")
94
+ if vector["scale_uint8_decimal"] != [127]:
95
+ raise RuntimeError("E8M0 identity-scale test vector must use biased exponent 127")
96
+
97
+
98
+ def main() -> None:
99
+ verify_file_hashes()
100
+ tensor_count = verify_model()
101
+ verify_packing_vector()
102
+ print(f"OK: all payload hashes and {tensor_count} model tensors verified")
103
+
104
+
105
+ if __name__ == "__main__":
106
+ main()