qwen3.8-9b-cyber-exploit-agent / scripts /patch_gguf_nextn.py
Krypto-Whitehat's picture
add exact training data + labs + evidence + scripts (secrets scrubbed)
778e97e verified
Raw
History Blame Contribute Delete
1.46 kB
import numpy as np
from gguf import GGUFReader, GGUFWriter
SRC = "/home/corov/cyber/gguf/qwen38-cyber-f16.gguf"
DST = "/home/corov/cyber/gguf/qwen38-cyber-f16-patched.gguf"
r = GGUFReader(SRC)
def scalar(f):
vt = f.types[0] # GGUFMetadataType ordinal
arr = f.parts[f.data[0]]
if vt == 8: # STRING
return arr.tobytes().decode("utf-8", "replace")
if vt == 7: # BOOL (stored as uint8)
return bool(arr[0])
if vt in (6, 11): # FLOAT32/64
return float(arr[0])
return int(arr[0])
arch = None
patched = []
for k, f in r.fields.items():
if f.types[0] == 12 or len(f.data) > 1: # ARRAY: types[0]=12
# arrays: parts[data[0]] holds the raw data; parts[data[1]] holds lengths? in gguf-py arrays are
# stored as f.data list of (part_idx) for data; replicate via add_array with the numpy array
arr = f.parts[f.data[0]]
# element type ordinal kept in f.types[1]
if k == "tokenizer.chat_template" or "tokens" in k or "scores" in k or "merges" in k or "type" in k:
continue_compat = True
yield_later = (k, arr)
ARRAYS.append((k, arr))
continue
v = scalar(f)
if k == "general.architecture":
arch = v
continue
if "nextn_predict_layers" in k:
print(f"patch {k}: {v} -> 0")
v = 0
patched.append(k)
SCALARS.append((k, v))
ARRAYS, SCALARS = [], []