0

我部署了一个机器学习模型,它需要 2 分钟的单次推理时间。所以我遇到了严重的超时错误,因为我在快速 API 中使用了后台工作人员来处理预测,但我仍然遇到了同样的错误。现在我不确定后台工作人员是否真的在工作。我已经发布了下面的代码,我已将其转换为使预测作为后台任务工作。

app = FastAPI()
response = {}
@app.get('/predict')
async def predictions(solute, solvent):
    mol = Chem.MolFromSmiles(solute)
    response["predictions"] = delta_g.item()
    return {'result': response}

async def predict(background_tasks: BackgroundTasks,solute,solvent):
    background_tasks.add_task(predictions,solute,solvent)
    
from predict_json import json_data_func

@app.get('/predict_two')
async def predictions_two(solute):
    for i in data:
        delta_g, interaction_map = model([get_graph_from_smile(Chem.MolToSmiles(Chem.AddHs(Chem.MolFromSmiles(solute)))).to(device), get_graph_from_smile(Chem.MolToSmiles(Chem.AddHs(Chem.MolFromSmiles(i)))).to(device)])
        response_two[i] = delta_g.item()
    return {'result': response_two}

async def predict_two(background_tasks: BackgroundTasks,solute):
    background_tasks.add_task(predictions_two,solute)
4

0 回答 0