From b6335d3342692b3dc20da613076b4737572246bc Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 8 Sep 2025 08:47:15 +0200 Subject: [PATCH 1/3] convert : force setting sliding_window from original config This commit modifies the set_gguf_parameters method for EmbeddingGemma so that it reads the sliding_window parameter from the original model config.json and uses that value. The motivation for this change is that the Gemma3TextConfig constructor adjusts the sliding_window value, which can lead to inconsistencies when converting models as we expects this value to match the original model's configuration. Refs: https://github.com/huggingface/transformers/blob/bb45d3631ec7026db04a77d33a52b31766372160/src/transformers/models/gemma3/configuration_gemma3.py#L230 --- convert_hf_to_gguf.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/convert_hf_to_gguf.py b/convert_hf_to_gguf.py index 717b8a6595010..b7b5d36929586 100755 --- a/convert_hf_to_gguf.py +++ b/convert_hf_to_gguf.py @@ -5128,6 +5128,20 @@ class EmbeddingGemma(Gemma3Model): def set_gguf_parameters(self): super().set_gguf_parameters() + + # Override the sliding window size as it gets adjusted by the Gemma3TextConfig + # constructor. We want to use the value from the original model's config.json. + with open(self.dir_model / "config.json", "r", encoding="utf-8") as f: + config = json.load(f) + orig_sliding_window = config.get("sliding_window") + if orig_sliding_window is None: + raise ValueError("sliding_window not found in model config - this is required for the model") + + logger.info(f"Using original sliding_window from config: {orig_sliding_window} " + f"instead of {self.hparams['sliding_window']}" + ) + self.gguf_writer.add_sliding_window(orig_sliding_window) + self._try_set_pooling_type() From 11d9d2c3d59675907163b3be89e56b30e3417f53 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 8 Sep 2025 09:09:07 +0200 Subject: [PATCH 2/3] fix flake8 error --- convert_hf_to_gguf.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/convert_hf_to_gguf.py b/convert_hf_to_gguf.py index b7b5d36929586..0c07c045518ce 100755 --- a/convert_hf_to_gguf.py +++ b/convert_hf_to_gguf.py @@ -5138,8 +5138,7 @@ def set_gguf_parameters(self): raise ValueError("sliding_window not found in model config - this is required for the model") logger.info(f"Using original sliding_window from config: {orig_sliding_window} " - f"instead of {self.hparams['sliding_window']}" - ) + f"instead of {self.hparams['sliding_window']}") self.gguf_writer.add_sliding_window(orig_sliding_window) self._try_set_pooling_type() From 7d11b7386f6c6a3182fe4381345f75e1ed050a2f Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 8 Sep 2025 09:09:56 +0200 Subject: [PATCH 3/3] add link to huggingface PR --- convert_hf_to_gguf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/convert_hf_to_gguf.py b/convert_hf_to_gguf.py index 0c07c045518ce..62a546ee22201 100755 --- a/convert_hf_to_gguf.py +++ b/convert_hf_to_gguf.py @@ -5131,6 +5131,7 @@ def set_gguf_parameters(self): # Override the sliding window size as it gets adjusted by the Gemma3TextConfig # constructor. We want to use the value from the original model's config.json. + # ref: https://github.com/huggingface/transformers/pull/40700 with open(self.dir_model / "config.json", "r", encoding="utf-8") as f: config = json.load(f) orig_sliding_window = config.get("sliding_window")