使用官方代码报错 ,Failed to import transformers.models.auto because of the following error

#15
by haaaaaaaa1 - opened

`from sentence_transformers import *

model = SentenceTransformer("Alibaba-NLP/gte-Qwen1.5-7B-instruct", trust_remote_code=True)

In case you want to reduce the maximum length:

model.max_seq_length = 8192

queries = [
"how much protein should a female eat",
"summit define",
]
documents = [
"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments.",
]

query_embeddings = model.encode(queries, prompt_name="query")
document_embeddings = model.encode(documents)

scores = (query_embeddings @ document_embeddings.T) * 100
print(scores.tolist())`

出错信息如下,循环引用了?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "D:\langchain\ragtestaliemb.py", line 1, in
from sentence_transformers import *
File "D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\sentence_transformers_init.py", line 3, in
from .datasets import SentencesDataset, ParallelSentencesDataset
File "D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\sentence_transformers\datasets_init
.py", line 3, in
from .ParallelSentencesDataset import ParallelSentencesDataset
File "D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\sentence_transformers\datasets\ParallelSentencesDataset.py", line 4, in
from .. import SentenceTransformer
File "D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\sentence_transformers\SentenceTransformer.py", line 38, in
from .models import Transformer, Pooling, Normalize
File "D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\sentence_transformers\models_init_.py", line 1, in
from .Transformer import Transformer
File "D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\sentence_transformers\models\Transformer.py", line 2, in
from transformers import AutoModel, AutoTokenizer, AutoConfig, T5Config, MT5Config
File "", line 1075, in _handle_fromlist
File "D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\transformers\utils\import_utils.py", line 1525, in getattr
module = self._get_module(self._class_to_module[name])
File "D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\transformers\utils\import_utils.py", line 1537, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.models.auto because of the following error (look up to see its traceback):
cannot import name 'sentencepiece' from partially initialized module 'sentencepiece' (most likely due to a circular import) (D:\ProgramData\Anaconda3\envs\llm\lib\site-packages\sentencepiece_init.py)

thx

Alibaba-NLP org

请贴一下你的transformers 版本和sentence-transformers版本

Sign up or log in to comment