okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3e0210663
main
1"""Header-only fixtures of Unsloth's Qwen3.8-Flash-Next sets at revision d9620119 (2026-11-04). 2 3tests/fixtures/unsloth_v31/headers.json.gz holds, for every set of the repository, each shard's pinned size and SHA-256 and, for 4the shards that carry tensors, the split keys and the real tensor directory (name, ggml type id, shape, offset) read from the 5first 4 MB of the file with an HTTP range request. No weights are in it. `materialize` writes a shard back as a GGUF that holds 6only the header (the file ends where the data would begin), which gguf_reader.GGUFFile and tools/iq_pack.py's layout code read. 7 8python tools/unsloth_v31_fixture.py build <folder of the 4 MB heads, named SET__file.gguf> <unsloth-head-pins.json> <out.json.gz> 9""" 10from __future__import annotations 11 12import gzip 13import json 14import pathlib 15import struct 16import sys 17 18HERE = pathlib .Path (__file__ ).resolve ().parent 19sys .path .insert (0 ,str (HERE )) 20import gguf_reader as G # noqa: E402 21 22FIXTURE = HERE .parent / "tests" / "fixtures" / "unsloth_v31" / "headers.json.gz" 23 24 25def load (path :pathlib .Path = FIXTURE )-> dict : 26with gzip .open (path ,"rt" ,encoding = "utf-8" )as f : 27return json .load (f ) 28 29 30def build (heads :pathlib .Path ,pins :pathlib .Path ,out :pathlib .Path )-> dict : 31p = json .loads (pathlib .Path (pins ).read_text (encoding = "utf-8" )) 32sets :dict = {} 33for key ,v in p ["files" ].items (): 34folder ,_ ,name = key .partition ("/" ) 35if not name or not name .endswith (".gguf" )or "-of-" not in name : 36continue 37shard = {"name" :name ,"bytes" :v ["bytes" ],"sha256" :v ["sha256" ],"header" :None } 38head = pathlib .Path (heads )/ key .replace ("/" ,"__" ) 39if head .exists (): 40try : 41g = G .GGUFFile (head ) 42except ValueError : 43g = None # shard 1: metadata only, longer than the 4 MB read 44if g is not None : 45shard ["header" ]= {"split" : [g .metadata .get ("split.no" ),g .metadata .get ("split.count" ), 46g .metadata .get ("split.tensors.count" )], 47"data_start" :g .data_start , 48"tensors" : [[t .name ,t .type_id ,t .shape ,t .offset ]for t in g .tensors ]} 49sets .setdefault (folder , {"revision" :p ["revision" ],"shards" : []})["shards" ].append (shard ) 50doc = {"repo" :p ["repo" ],"revision" :p ["revision" ],"sets" :sets } 51with gzip .open (out ,"wt" ,encoding = "utf-8" ,compresslevel = 9 )as f : 52json .dump (doc ,f ,separators = ("," ,":" ),sort_keys = True ) 53return doc 54 55 56def _str (s :str )-> bytes : 57b = s .encode () 58return struct .pack ("<Q" ,len (b ))+ b 59 60 61def materialize (shard :dict ,path :pathlib .Path ,arch :str = "qwen4exp" ,first :bool = False )-> pathlib .Path : 62"""A GGUF v3 file with the shard's tensor directory and no data: it ends at the aligned start of the data section.""" 63h = shard ["header" ] 64no ,count ,total = h ["split" ] 65kv = [] 66if first : 67kv .append (_str ("general.architecture" )+ struct .pack ("<I" ,8 )+ _str (arch )) 68for k ,v in (("split.no" ,no ), ("split.count" ,count )): 69kv .append (_str (k )+ struct .pack ("<IH" ,2 ,v )) 70kv .append (_str ("split.tensors.count" )+ struct .pack ("<Ii" ,5 ,total )) 71out = bytearray (struct .pack ("<IIQQ" ,G .GGUF_MAGIC ,3 ,len (h ["tensors" ]),len (kv ))) 72for e in kv : 73out += e 74for name ,type_id ,shape ,offset in h ["tensors" ]: 75out += _str (name )+ struct .pack ("<I" ,len (shape ))+ struct .pack (f"< { len ( shape ) } Q" ,* shape )+ struct .pack ("<IQ" ,type_id ,offset ) 76align = 32 77out += b"\0" * ((- len (out ))% align ) 78pathlib .Path (path ).write_bytes (bytes (out )) 79return pathlib .Path (path ) 80 81 82if __name__ == "__main__" : 83if len (sys .argv )== 5 and sys .argv [1 ]== "build" : 84d = build (pathlib .Path (sys .argv [2 ]),pathlib .Path (sys .argv [3 ]),pathlib .Path (sys .argv [4 ])) 85len (d ["sets" ]),"sets" ) 86else : 87sys .exit (__doc__ )