MiniCPM
MiniCPM copied to clipboard
[Feature Request]: emebdding&reranker服务问题
Feature request / 功能建议
请问什么框架可以提供mini-embedding和mini-reranker的推理服务,transformers推理好像不能直接支持异步
我们可以将encode或rerank转为异步函数,然后用fastapi启服务
You can try FastAPI.
首先 First
pip install fastapi
pip install asgiref
pip install uvicorn
然后我们把encode或rerank函数改为异步的。
Then we make the func encode or rerank to async.
from fastapi import FastAPI
import uvicorn
from asgiref.sync import sync_to_async
app = FastAPI()
@app.get('/embedding')
async def embedding(queries):
embeddings = await sync_to_async(encode)(queries)
return {'embedding':embeddings}
if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=YOUR_PORT)
谢谢。但是我测试下来好像还没有原来的方式快
谢谢。但是我测试下来好像还没有原来的方式快
这里的demo是按条来进行推理的,实际部署可以根据情况按batch推理。如果对性能有更大的要求,可以尝试转为onnx格式部署。