Instructions to use nvidia/NV-Embed-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/NV-Embed-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="nvidia/NV-Embed-v2", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("nvidia/NV-Embed-v2", trust_remote_code=True, dtype="auto") - sentence-transformers
How to use nvidia/NV-Embed-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("nvidia/NV-Embed-v2", trust_remote_code=True) sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
How do I run nvidia/NV-Embed-v2 in Colab?
from transformers import AutoModel
model_name = "nvidia/NV-Embed-v2"
model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
AttributeError Traceback (most recent call last)
in <cell line: 4>()
2
3 model_name = "nvidia/NV-Embed-v2"
----> 4 model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
5 # model = AutoModel.from_pretrained(model_name)
5 frames
/usr/local/lib/python3.10/dist-packages/transformers/configuration_utils.py in getattribute(self, key)
200 if key != "attribute_map" and key in super().getattribute("attribute_map"):
201 key = super().getattribute("attribute_map")[key]
--> 202 return super().getattribute(key)
203
204 def init(self, **kwargs):
AttributeError: 'LatentAttentionConfig' object has no attribute '_attn_implementation_internal'
Hi, @pympk . Please install the transformer package as suggested here: https://huggingface.co/nvidia/NV-Embed-v2#2-required-packages
Similar reported issue is also here: https://huggingface.co/nvidia/NV-Embed-v1/discussions/50