Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
54
docs/entwuerfe/modell-hub/gguf_kopf_lesen.py
Normal file
54
docs/entwuerfe/modell-hub/gguf_kopf_lesen.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Versuchsskript (kein Teil von Nexus): liest nur den Anfang einer GGUF-Datei per HTTP-Range und gibt die Architekturwerte aus.
|
||||
# Aufruf: python3 gguf_kopf_lesen.py <URL der .gguf-Datei> (nur lesend, anonym, lädt höchstens ein paar Hundert KiB).
|
||||
import struct, sys, urllib.request, json, time
|
||||
URL = sys.argv[1]
|
||||
fetched = {'bytes': 0, 'requests': 0}
|
||||
buf = bytearray()
|
||||
def holen(bis):
|
||||
"""Range-Anfrage: lädt nur die fehlenden Bytes bis `bis` (exklusiv)."""
|
||||
global buf
|
||||
if len(buf) >= bis: return
|
||||
start = len(buf)
|
||||
req = urllib.request.Request(URL, headers={"Range": f"bytes={start}-{bis-1}", "User-Agent": "nexus-recherche"})
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
if r.status != 206: raise SystemExit(f"Server ignoriert Range (Status {r.status})")
|
||||
daten = r.read()
|
||||
fetched['bytes'] += len(daten); fetched['requests'] += 1
|
||||
buf += daten
|
||||
class Ende(Exception): pass
|
||||
pos = 0
|
||||
def lies(n):
|
||||
global pos
|
||||
while len(buf) < pos + n:
|
||||
holen(max(pos + n, len(buf) * 2 if len(buf) else 65536))
|
||||
d = bytes(buf[pos:pos+n]); pos += n; return d
|
||||
def u32(): return struct.unpack('<I', lies(4))[0]
|
||||
def u64(): return struct.unpack('<Q', lies(8))[0]
|
||||
def string():
|
||||
n = u64(); return lies(n).decode('utf-8', 'replace')
|
||||
FMT = {0:'<B',1:'<b',2:'<H',3:'<h',4:'<I',5:'<i',6:'<f',7:'<?',10:'<Q',11:'<q',12:'<d'}
|
||||
def wert(t, behalte=True):
|
||||
if t in FMT:
|
||||
n = struct.calcsize(FMT[t]); return struct.unpack(FMT[t], lies(n))[0]
|
||||
if t == 8: return string()
|
||||
if t == 9:
|
||||
et = u32(); n = u64()
|
||||
if et in FMT:
|
||||
sz = struct.calcsize(FMT[et]); lies(sz*n); return f"[{n} Werte]"
|
||||
for _ in range(n): wert(et)
|
||||
return f"[{n} Werte]"
|
||||
raise SystemExit(f"unbekannter Typ {t}")
|
||||
|
||||
t0=time.time()
|
||||
assert lies(4)==b"GGUF"; version=u32(); tensoren=u64(); kvs=u64()
|
||||
kv={}
|
||||
for _ in range(kvs):
|
||||
k=string()
|
||||
if k.startswith("tokenizer."): break
|
||||
t=u32(); kv[k]=wert(t)
|
||||
arch=kv["general.architecture"]
|
||||
print(json.dumps({"Anfragen":fetched["requests"],"geladene_Bytes":fetched["bytes"],"Sekunden":round(time.time()-t0,2),
|
||||
"arch":arch,"block_count":kv.get(arch+".block_count"),"head_count_kv":kv.get(arch+".attention.head_count_kv"),
|
||||
"key_length":kv.get(arch+".attention.key_length"),"value_length":kv.get(arch+".attention.value_length"),
|
||||
"context_length":kv.get(arch+".context_length"),"embedding_length":kv.get(arch+".embedding_length"),
|
||||
"full_attention_interval":kv.get(arch+".full_attention_interval"),"sliding_window":kv.get(arch+".attention.sliding_window")}))
|
||||
Reference in New Issue
Block a user