Skip to content

Commit 7d21234

Browse files
authored
convert : use correct context length for nomic-embed-text-v2 (#13216)
1 parent 074e42a commit 7d21234

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

convert_hf_to_gguf.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def prepare_metadata(self, vocab_only: bool):
506506
def set_gguf_parameters(self):
507507
self.gguf_writer.add_block_count(self.block_count)
508508

509-
if (n_ctx := self.find_hparam(["max_position_embeddings", "n_ctx"], optional=True)) is not None:
509+
if (n_ctx := self.find_hparam(["max_position_embeddings", "n_ctx", "n_positions"], optional=True)) is not None:
510510
self.gguf_writer.add_context_length(n_ctx)
511511
logger.info(f"gguf: context length = {n_ctx}")
512512

@@ -3627,8 +3627,13 @@ def __init__(self, dir_model: Path, ftype: gguf.LlamaFileType, fname_out: Path,
36273627
if self._tokenizer_is_xlmroberta:
36283628
self._xlmroberta_tokenizer_init()
36293629

3630-
# the HF config claims n_ctx=8192, but it uses RoPE scaling
3631-
self.hparams["n_ctx"] = 2048
3630+
npos, mtp = self.hparams["n_positions"], self.hparams.get("max_trained_positions", 2048)
3631+
if npos == 8192 and mtp == 2048:
3632+
self.hparams["n_positions"] = 2048 # nomic-embed-text v1 and v1.5 are trained for 2048 tokens.
3633+
elif npos == 2048 and mtp == 2048:
3634+
self.hparams["n_positions"] = 512 # nomic-embed-text-v2-moe is trained for 512 tokens.
3635+
else:
3636+
raise ValueError(f"unrecognized parameters: n_positions={npos}, max_trained_positions={mtp}")
36323637

36333638
assert self.hparams["activation_function"] == "gelu" if self.is_moe else "swiglu"
36343639

0 commit comments

Comments
 (0)