"""tools/ple_fp8_pack.py - the PLE n-gram table exactly as Qwen shipped it (FP8 E4M3), as a GGUF the engine reads. python tools/ple_fp8_pack.py --model --out Qwen3.8-Flash-Next's checkpoint stores the table as 128 shards `...ngram_embedding.shard_{k}.weight` of [2500012, 160] F8_E4M3 with one BF16 `weight_scale`: 320,001,536 rows of 160 values, 51.2 GB. The engine used to take it from ISTA-DASLab's GGUF as IQ4_NL (90 B/row), which is 8% off these values per row; this keeps them bit for bit. The output is a one-tensor GGUF: `per_layer_token_embd.weight`, ne = [160, 320001536], type I8 holding the FP8 bytes (GGUF has no FP8 type), with `strata.ple.format` = "f8_e4m3" and `strata.ple.scale` (F32). The bytes are copied straight out of the safetensors files in shard order - nothing is decoded or rounded - so memory stays flat. """ import argparse import json import pathlib import struct import sys GGUF_TYPE_STRING, GGUF_TYPE_F32 = 8, 6 GGML_TYPE_I8 = 24 ALIGN = 32 CHUNK = 64 << 20 def safetensors_header(path): with open(path, "rb") as f: n = struct.unpack("