@@ -506,7 +506,7 @@ def prepare_metadata(self, vocab_only: bool):
506
506
def set_gguf_parameters (self ):
507
507
self .gguf_writer .add_block_count (self .block_count )
508
508
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 :
510
510
self .gguf_writer .add_context_length (n_ctx )
511
511
logger .info (f"gguf: context length = { n_ctx } " )
512
512
@@ -3627,8 +3627,13 @@ def __init__(self, dir_model: Path, ftype: gguf.LlamaFileType, fname_out: Path,
3627
3627
if self ._tokenizer_is_xlmroberta :
3628
3628
self ._xlmroberta_tokenizer_init ()
3629
3629
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 } " )
3632
3637
3633
3638
assert self .hparams ["activation_function" ] == "gelu" if self .is_moe else "swiglu"
3634
3639
0 commit comments