Skip to content

Instantly share code, notes, and snippets.

@nazeshinjite
nazeshinjite / repack-ple-shard.py
Created August 26, 2026 19:18
Repack a split GGUF so the qwen4exp PLE/engram table sits alone in the final shard (llama.cpp PR 27742)
#!/usr/bin/env python3
# Repack a split GGUF so one tensor (default: the qwen4exp engram table
# per_layer_token_embd.weight) sits ALONE in the final shard, with no other tensors
# sharing that file. Motivation: on Metal, llama.cpp wires the mmap'd regions that
# back GPU tensors; a tensor interleaved with them in the same file gets wired along
# for the ride (measured +24 GiB on Qwen3.8-Flash-Next). A file containing only
# CPU-side tensors keeps its own mapping and stays pageable.
#
# Tensor bytes are copied verbatim (no requantization). Output layout for an N-file
# input: shard 1 = byte-for-byte copy of input shard 1 (metadata-only; split.count and