from flask import Flask
from flask import request
from flask_cors import CORS
from text2vec import SentenceModel
import os
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
app = Flask(name)
CORS(app, supports_credentials=True, origins='*')
t2v_model = SentenceModel("shibing624/text2vec-base-chinese")
def to_embeddings_text2vec_list(items):
sentence_embeddings = t2v_model.encode(items)
ret_list=[]
for s in sentence_embeddings:
ret_list.append(s.tolist())
return ret_list
Is there an existing issue for this?
Current Behavior
使用text2vec库,带gpu的torch。推理一定会报错,无法正常使用。 使用transformers,修改 model.to("cuda"),则随机出现各种bug,有50%概览能正常启动,执行几次推理之后,又开始出现各种神奇的bug。 搞了一天,我都开始怀疑是不是3060坏了....... 最后搞下来只有cpu能正常工作,没有一点点问题。只要用gpu加速,就一定有bug。
Expected Behavior
from flask import Flask from flask import request from flask_cors import CORS from text2vec import SentenceModel import os os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" app = Flask(name) CORS(app, supports_credentials=True, origins='*') t2v_model = SentenceModel("shibing624/text2vec-base-chinese")
def to_embeddings_text2vec(item): sentence_embeddings = t2v_model.encode(item) return sentence_embeddings.tolist()
def to_embeddings_text2vec_list(items): sentence_embeddings = t2v_model.encode(items) ret_list=[] for s in sentence_embeddings: ret_list.append(s.tolist()) return ret_list
@app.route('/') def hello_world(): return "ok"
@app.route('/text2vec', methods=['GET']) def text2vec(): return to_embeddings_text2vec(request.args.get('q'))
@app.route('/text2vec', methods=['POST']) def text2vecs(): data=request.json["qs"] return to_embeddings_text2vec_list(data)
if name == 'main': app.run(host='0.0.0.0', port=3000)
Steps To Reproduce
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" t2v_model = SentenceModel("shibing624/text2vec-base-chinese") def to_embeddings_text2vec_list(items): sentence_embeddings = t2v_model.encode(items) ret_list=[] for s in sentence_embeddings: ret_list.append(s.tolist()) return ret_list
Environment
Anything else?
No response