ValueError: Asked to use CUDAExecutionProvider as an ONNX Runtime execution provider, but the available execution providers are ['AzureExecutionProvider', 'CPUExecutionProvider'].

#2
by chuangzhidian - opened

Traceback (most recent call last):
File "/media/data/xgp/repo/bge_onnx.py", line 10, in
model = ORTModelForFeatureExtraction.from_pretrained(MODEL_PATH, provider="CUDAExecutionProvider") # omit provider for CPU usage.
File "/root/anaconda3/lib/python3.9/site-packages/optimum/onnxruntime/modeling_ort.py", line 669, in from_pretrained
return super().from_pretrained(
File "/root/anaconda3/lib/python3.9/site-packages/optimum/modeling_base.py", line 402, in from_pretrained
return from_pretrained_method(
File "/root/anaconda3/lib/python3.9/site-packages/optimum/onnxruntime/modeling_ort.py", line 517, in _from_pretrained
model = ORTModel.load_model(
File "/root/anaconda3/lib/python3.9/site-packages/optimum/onnxruntime/modeling_ort.py", line 359, in load_model
validate_provider_availability(provider) # raise error if the provider is not available
File "/root/anaconda3/lib/python3.9/site-packages/optimum/onnxruntime/utils.py", line 273, in validate_provider_availability
raise ValueError(
ValueError: Asked to use CUDAExecutionProvider as an ONNX Runtime execution provider, but the available execution providers are ['AzureExecutionProvider', 'CPUExecutionProvider'].

do not know why it's not using cuda, my script as follows:
from optimum.onnxruntime import ORTModelForFeatureExtraction
from transformers import AutoTokenizer
import torch
MODEL_PATH = r'/data/xp/scripts/bge-m3-onnx'

Make sure that you download the model weights locally to bge-m3-onnx

model = ORTModelForFeatureExtraction.from_pretrained(MODEL_PATH, provider="CUDAExecutionProvider") # omit provider for CPU usage.
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)

sentences = [
"English: The quick brown fox jumps over the lazy dog.",
"Spanish: El rápido zorro marrón salta sobre el perro perezoso.",
"French: Le renard brun rapide saute par-dessus le chien paresseux.",
"German: Der schnelle braune Fuchs springt über den faulen Hund.",
"Italian: La volpe marrone veloce salta sopra il cane pigro.",
"Japanese: 速い茶色の狐が怠惰な犬を飛び越える。",
"Chinese (Simplified): 快速的棕色狐狸跳过懒狗。",
"Russian: Быстрая коричневая лиса прыгает через ленивую собаку.",
"Arabic: ﺎﻠﺜﻌﻠﺑ ﺎﻠﺒﻨﻳ ﺎﻠﺳﺮﻴﻋ ﻲﻘﻓﺯ ﻑﻮﻗ ﺎﻠﻜﻠﺑ ﺎﻠﻜﺳﻮﻟ.",
"Hindi: तेज़ भूरी लोमड़ी आलसी कुत्ते के ऊपर कूद जाती है।"
]

encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt').to("cuda")

Get the embeddings

out=model(**encoded_input,return_dict=True).last_hidden_state

normalize the embeddings

dense_vecs = torch.nn.functional.normalize(out[:, 0], dim=-1)

tried this as well :pip install onnxruntime-gpu==1.15.1 -f https://download.onnxruntime.ai/onnxruntime_stable.html
but i get the following error:

(base) root@gptai:/data/xp/repo# python bge_onnx.py
['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'CPUExecutionProvider']
Traceback (most recent call last):
File "/data/xp/repo/bge_onnx.py", line 16, in
model = ORTModelForFeatureExtraction.from_pretrained(MODEL_PATH, provider="CUDAExecutionProvider") # omit provider for CPU usage.
File "/root/anaconda3/lib/python3.9/site-packages/optimum/onnxruntime/modeling_ort.py", line 669, in from_pretrained
return super().from_pretrained(
File "/root/anaconda3/lib/python3.9/site-packages/optimum/modeling_base.py", line 402, in from_pretrained
return from_pretrained_method(
File "/root/anaconda3/lib/python3.9/site-packages/optimum/onnxruntime/modeling_ort.py", line 517, in _from_pretrained
model = ORTModel.load_model(
File "/root/anaconda3/lib/python3.9/site-packages/optimum/onnxruntime/modeling_ort.py", line 359, in load_model
validate_provider_availability(provider) # raise error if the provider is not available
File "/root/anaconda3/lib/python3.9/site-packages/optimum/onnxruntime/utils.py", line 262, in validate_provider_availability
raise ImportError(
ImportError: onnxruntime-gpu package is installed, but CUDA requirements could not be loaded. Make sure to meet the required dependencies: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html

Sign up or log in to comment