MiniCPM icon indicating copy to clipboard operation
MiniCPM copied to clipboard

[Feature Request]: emebdding&reranker服务问题

Open lyj157175 opened this issue 1 year ago • 1 comments

Feature request / 功能建议

请问什么框架可以提供mini-embedding和mini-reranker的推理服务,transformers推理好像不能直接支持异步

lyj157175 avatar Sep 06 '24 08:09 lyj157175

我们可以将encodererank转为异步函数,然后用fastapi启服务 You can try FastAPI.

首先 First

pip install fastapi
pip install asgiref
pip install uvicorn

然后我们把encodererank函数改为异步的。 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)

Kaguya-19 avatar Sep 07 '24 04:09 Kaguya-19

谢谢。但是我测试下来好像还没有原来的方式快

lyj157175 avatar Sep 09 '24 09:09 lyj157175

谢谢。但是我测试下来好像还没有原来的方式快

这里的demo是按条来进行推理的,实际部署可以根据情况按batch推理。如果对性能有更大的要求,可以尝试转为onnx格式部署。

Kaguya-19 avatar Sep 10 '24 03:09 Kaguya-19