import mmap import struct import sys if len(sys.argv) < 2: print("Usage: python3 mmap_patch.py ") sys.exit(1) filename = sys.argv[1] print(f"Memory-mapping {filename} (Uses almost 0 RAM)...") # Open the file in read/write binary mode with open(filename, "r+b") as f: # Memory map the file directly to disk mm = mmap.mmap(f.fileno(), 0) patches_applied = 0 # 1. Fix block_count target_key1 = b"qwen35moe.block_count" idx1 = mm.find(target_key1) if idx1 != -1: val_offset1 = idx1 + len(target_key1) val_type1 = struct.unpack(" 40") mm[data_offset1:data_offset1+4] = struct.pack(" 0") mm[data_offset2:data_offset2+4] = struct.pack("