Views
No views yet
ONNX O4 strategy optimized version of BAAI/bge-large-en-v1.5 optimal for Cuda. It should be much faster than the original
version.
1
2# pip install "optimum[onnxruntime-gpu]" transformers
3
4from optimum.onnxruntime import ORTModelForFeatureExtraction
5from transformers import AutoTokenizer
6
7tokenizer = AutoTokenizer.from_pretrained('hooman650/bge-large-en-v1.5-onnx-o4')
8model = ORTModelForFeatureExtraction.from_pretrained('hooman650/bge-large-en-v1.5-onnx-o4')
9model.to("cuda")
10
11pairs = ["pandas usually live in the jungles"]
12with torch.no_grad():
13 inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt', max_length=512)
14 sentence_embeddings = model(**inputs)[0][:, 0]
15
16# normalize embeddings
17sentence_embeddings = torch.nn.functional.normalize(sentence_embeddings, p=2, dim=1)