Skip to content

Commit 233d773

Browse files
authored
convert : force setting sliding_window from original config (ggml-org#15867)
* 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 * fix flake8 error * add link to huggingface PR
1 parent a885dcf commit 233d773

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

convert_hf_to_gguf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5128,6 +5128,20 @@ class EmbeddingGemma(Gemma3Model):
51285128

51295129
def set_gguf_parameters(self):
51305130
super().set_gguf_parameters()
5131+
5132+
# Override the sliding window size as it gets adjusted by the Gemma3TextConfig
5133+
# constructor. We want to use the value from the original model's config.json.
5134+
# ref: https://github.com/huggingface/transformers/pull/40700
5135+
with open(self.dir_model / "config.json", "r", encoding="utf-8") as f:
5136+
config = json.load(f)
5137+
orig_sliding_window = config.get("sliding_window")
5138+
if orig_sliding_window is None:
5139+
raise ValueError("sliding_window not found in model config - this is required for the model")
5140+
5141+
logger.info(f"Using original sliding_window from config: {orig_sliding_window} "
5142+
f"instead of {self.hparams['sliding_window']}")
5143+
self.gguf_writer.add_sliding_window(orig_sliding_window)
5144+
51315145
self._try_set_pooling_type()
51325146

51335147

0 commit comments

Comments
 (0)