forked from microsoft/DeepSpeed-MII
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminate.py
28 lines (23 loc) · 808 Bytes
/
terminate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0
# DeepSpeed Team
import grpc
import mii.legacy as mii
from mii.legacy.logging import logger
def terminate(deployment_name):
logger.info(f"Terminating server for {deployment_name}")
generator = mii.mii_query_handle(deployment_name)
if deployment_name in mii.non_persistent_models:
generator.terminate()
return
try:
generator.query({"query": ""})
except grpc.aio._call.AioRpcError as error:
if error._code == grpc.StatusCode.UNAVAILABLE:
logger.warn(f"Server for {deployment_name} not found")
else:
pass
except (KeyError, TypeError) as error:
pass
generator.terminate()
mii.client.terminate_restful_gateway(deployment_name)