単純なトランスフォーマー Roberta モデルを使用して分類を行うサービスを実行しようとしています。推論スクリプト/関数自体は、テスト時に期待どおりに機能しています。それを高速APIに含めると、サーバーがシャットダウンします。
uvicorn==0.11.8
fastapi==0.61.1
simpletransformers==0.51.6
cmd : uvicorn --host 0.0.0.0 --port 5000 src.main:app
@app.get("/article_classify")
def classification(text:str):
"""function to classify article using a deep learning model.
Returns:
[type]: [description]
"""
_,_,result = inference(text)
return result
エラー :
INFO: Started server process [8262]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
INFO: 127.0.0.1:36454 - "GET / HTTP/1.1" 200 OK
INFO: 127.0.0.1:36454 - "GET /favicon.ico HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:36454 - "GET /docs HTTP/1.1" 200 OK
INFO: 127.0.0.1:36454 - "GET /openapi.json HTTP/1.1" 200 OK
before
100%|████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 17.85it/s]
INFO: Shutting down
INFO: Finished server process [8262]
推論スクリプト:
model_name = "checkpoint-3380-epoch-20"
model = MultiLabelClassificationModel("roberta","src/outputs/"+model_name)
def inference(input_text,model_name="checkpoint-3380-epoch-20"):
"""Function to run inverence on one sample text"""
#model = MultiLabelClassificationModel("roberta","src/outputs/"+model_name)
all_tags =[]
if isinstance(input_text,str):
print("before")
result ,output = model.predict([input_text])
print(result)
tags=[]
for idx,each in enumerate(result[0]):
if each==1:
tags.append(classes[idx])
all_tags.append(tags)
elif isinstance(input_text,list):
result ,output = model.predict(input_text)
tags=[]
for res in result :
for idx,each in enumerate(res):
if each==1:
tags.append(classes[idx])
all_tags.append(tags)
return result,output,all_tags
更新:フラスコで試してみましたが、サービスは機能していますが、フラスコの上にuvicornを追加すると、再起動のループでスタックします。