From cec344950733b9a04dcd1fd67aaf51562e070f22 Mon Sep 17 00:00:00 2001 From: Francis Couture-Harpin Date: Thu, 4 Sep 2025 19:08:09 -0400 Subject: [PATCH] convert : allow sharding reflinked models --- gguf-py/gguf/gguf_writer.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gguf-py/gguf/gguf_writer.py b/gguf-py/gguf/gguf_writer.py index 5258fa868c..5fda08a671 100644 --- a/gguf-py/gguf/gguf_writer.py +++ b/gguf-py/gguf/gguf_writer.py @@ -184,11 +184,15 @@ class GGUFWriter: if self.use_reflinks: # reflinks require alignment to the filesystem blocks block_size = os.stat(self.path.parent).st_blksize - # necessary to get an appropriate data start offset - # when padding for reflinks; - # using the real alignment (8 bytes, from safetensors) - # would result in a unusable base data offset - self.add_custom_alignment(block_size) + # necessary to get an appropriate data start offset when padding for reflinks; + # using the real alignment (8 bytes, from safetensors) would result in a unusable base data offset + self.data_alignment = block_size + # for all shards to allow reading them on their own + for i, kv in enumerate(self.kv_data): + # insert at the start of the key-values + if Keys.General.ALIGNMENT in kv: + del kv[Keys.General.ALIGNMENT] + self.kv_data[i] = { Keys.General.ALIGNMENT: GGUFValue(block_size, GGUFValueType.UINT32), **kv } def print_plan(self) -> list[Path]: logger.info("Writing the following files:")