"""Attach modification notices and stage validated platform release directories.""" import argparse import json import os import shutil import struct from pathlib import Path from scripts.integrity import sha256, verify_files from scripts.provenance import model_identity, validate_model_structure NOTICE = ('Modified by ixim / iximbox: eligible linear weights converted from ' 'Qwen-Image-2.1 to bitsandbytes LLM.int8 INT8. Built with Qwen. ' 'Non-commercial research/evaluation under the accompanying Qwen Research License.') REVISION = 'b3179ad355be050328e483a9dfdd9e60cd62adfa' def add_safetensors_notice(path): path = Path(path) temp = path.with_name(path.name + '.notice-tmp') try: with path.open('rb') as source: prefix = source.read(8) if len(prefix) != 8: raise ValueError(f'Invalid safetensors prefix: {path}') length = struct.unpack(' 100_000_000: raise ValueError('Unexpected safetensors header size') header = json.loads(source.read(length)) metadata = header.setdefault('__metadata__', {}) if metadata.get('modification_notice') == NOTICE: return metadata.update(modification_notice=NOTICE, base_revision=REVISION) encoded = json.dumps(header, ensure_ascii=False, separators=(',', ':')).encode('utf-8') encoded += b' ' * ((8 - len(encoded) % 8) % 8) with temp.open('wb') as target: target.write(struct.pack('