feat(transformers): Add native Transformers config

#31

What does this PR do?

โ†’ Sets model_type from new to gte and adds rope_parameters, so the checkpoint loads directly with AutoModel / AutoConfig in Transformers ๐Ÿค— without trust_remote_code.
โ†’ Transformers support is being added in https://github.com/huggingface/transformers/pull/48416
โ†’ โš ๏ธ Please hold this until the Transformers PR above has landed ๐Ÿค—

Compatibility

โ†’ rope_scaling and rope_theta are replaced by rope_parameters. rope_scaling cannot be kept alongside it, because Transformers reads that key first and ntk is not one of its rope types.
โ†’ auto_map is left in place, but on this revision a trust_remote_code=True load no longer finds rope_theta / rope_scaling and falls back to the remote defaults (rope_theta=10000.0, rope_scaling=None) instead of this checkpoint's values. That changes the embeddings, and the gap grows with sequence length, so anyone staying on an older Transformers version should pin a revision from before this PR.

Produced by?

โ†’ rope_parameters is the standardised form of the existing rope_scaling / rope_theta pair. GTE applies NTK scaling statically at construction by rescaling the base and dividing the inverse frequencies by factor ** (2 / head_dim), which is exactly a linear scaling with base rope_theta * factor, so the inverse frequencies are unchanged.
โ†’ Outputs are reproduced against the original implementation on this checkpoint (max relative difference 1.4e-06), and the slow integration tests in the Transformers PR run against this revision.

harshaljanjani changed pull request title from โš ๏ธ DO NOT MERGE: feat(transformers): Add native Transformers config to feat(transformers): Add native Transformers config
harshaljanjani changed pull request status to open
Alibaba-NLP org

Thanks @harshaljanjani for implementing native GTE support in transformers (huggingface/transformers#48416) and opening this PR!

Building on commit 3a27607, I pushed a follow-up commit to finalize the native configuration, documentation, and helper script:

  • Updated config.json: set architectures to ["GteModel", "GteForTokenClassification"], dtype: "float16", tie_word_embeddings: true, and removed auto_map and legacy new-impl fields so transformers>=5.18.0 loads natively even if trust_remote_code=True is passed, and Hub metadata (transformersInfo, endpoints_compatible) is detected cleanly.
  • Updated README.md: removed trust_remote_code=True from the usage examples, updated the requirement to transformers>=5.18.0, and added a note crediting @harshaljanjani and pointing older transformers<5.18.0 users to revision="9bbca17".
  • Updated scripts/gte_embedding.py: removed trust_remote_code=True, passed dtype=torch.float16 if self.use_fp16 else torch.float32 so use_fp16=False / CPU fallback stays float32 under transformers v5, and passed output_hidden_states=return_dense with hidden_states[-1] fallback so dense+sparse encoding works with native GteForTokenClassification (TokenClassifierOutput).

Weights and tokenizer files remain unchanged. Keeping this PR open for final review before merging.

izhx changed pull request status to merged

Sign up or log in to comment