meg-huggingface
commited on
Commit
•
506d239
1
Parent(s):
a9f6487
More handling of inference endpoints: Delete when done.
Browse files
main_backend_toxicity.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import logging
|
2 |
import pprint
|
3 |
import re
|
4 |
-
from huggingface_hub import snapshot_download
|
5 |
|
6 |
from src.backend.inference_endpoint import create_endpoint
|
7 |
from src.backend.run_toxicity_eval import main
|
@@ -81,6 +81,7 @@ def run_auto_eval():
|
|
81 |
hf_repo=QUEUE_REPO,
|
82 |
local_dir=EVAL_REQUESTS_PATH_BACKEND,
|
83 |
)
|
|
|
84 |
|
85 |
|
86 |
if __name__ == "__main__":
|
|
|
1 |
import logging
|
2 |
import pprint
|
3 |
import re
|
4 |
+
from huggingface_hub import snapshot_download, delete_inference_endpoint
|
5 |
|
6 |
from src.backend.inference_endpoint import create_endpoint
|
7 |
from src.backend.run_toxicity_eval import main
|
|
|
81 |
hf_repo=QUEUE_REPO,
|
82 |
local_dir=EVAL_REQUESTS_PATH_BACKEND,
|
83 |
)
|
84 |
+
delete_inference_endpoint(endpoint_name)
|
85 |
|
86 |
|
87 |
if __name__ == "__main__":
|
src/backend/inference_endpoint.py
CHANGED
@@ -15,23 +15,15 @@ def create_endpoint(endpoint_name, repository, framework="pytorch", task="text-g
|
|
15 |
logger.info("Creating endpoint %s..." % endpoint_name)
|
16 |
# TODO(mm): Handle situation where it's paused
|
17 |
try:
|
18 |
-
endpoint = create_inference_endpoint(endpoint_name, repository=repository, framework=framework, task=task, accelerator=accelerator, vendor=vendor, region=region, type=type, instance_size=instance_size, instance_type=instance_type
|
19 |
-
)
|
20 |
except huggingface_hub.utils._errors.HfHubHTTPError as e:
|
21 |
-
endpoint = update_endpoint_exception(accelerator,
|
22 |
-
endpoint_name, framework,
|
23 |
-
instance_size, instance_type,
|
24 |
-
repository, task)
|
25 |
except requests.exceptions.HTTPError as e:
|
26 |
-
endpoint = update_endpoint_exception(accelerator,
|
27 |
-
endpoint_name, framework,
|
28 |
-
instance_size, instance_type,
|
29 |
-
repository, task)
|
30 |
except Exception as e:
|
31 |
logger.debug("Hit error")
|
32 |
logger.debug(e)
|
33 |
sys.exit()
|
34 |
-
|
35 |
endpoint.fetch()
|
36 |
logger.info("Endpoint status: %s." % (endpoint.status))
|
37 |
if endpoint.status == "scaledToZero":
|
@@ -54,9 +46,7 @@ def create_endpoint(endpoint_name, repository, framework="pytorch", task="text-g
|
|
54 |
return generation_url
|
55 |
|
56 |
|
57 |
-
def update_endpoint_exception(accelerator,
|
58 |
-
framework, instance_size, instance_type,
|
59 |
-
repository, task):
|
60 |
logger.debug("Hit the following exception:")
|
61 |
logger.debug(e)
|
62 |
logger.debug("Attempting to continue.")
|
|
|
15 |
logger.info("Creating endpoint %s..." % endpoint_name)
|
16 |
# TODO(mm): Handle situation where it's paused
|
17 |
try:
|
18 |
+
endpoint = create_inference_endpoint(endpoint_name, repository=repository, framework=framework, task=task, accelerator=accelerator, vendor=vendor, region=region, type=type, instance_size=instance_size, instance_type=instance_type)
|
|
|
19 |
except huggingface_hub.utils._errors.HfHubHTTPError as e:
|
20 |
+
endpoint = update_endpoint_exception(e, endpoint_name=endpoint_name, repository=repository, framework=framework, task=task, accelerator=accelerator, vendor=vendor, region=region, type=type, instance_size=instance_size, instance_type=instance_type)
|
|
|
|
|
|
|
21 |
except requests.exceptions.HTTPError as e:
|
22 |
+
endpoint = update_endpoint_exception(e, endpoint_name, repository=repository, framework=framework, task=task, accelerator=accelerator, vendor=vendor, region=region, type=type, instance_size=instance_size, instance_type=instance_type)
|
|
|
|
|
|
|
23 |
except Exception as e:
|
24 |
logger.debug("Hit error")
|
25 |
logger.debug(e)
|
26 |
sys.exit()
|
|
|
27 |
endpoint.fetch()
|
28 |
logger.info("Endpoint status: %s." % (endpoint.status))
|
29 |
if endpoint.status == "scaledToZero":
|
|
|
46 |
return generation_url
|
47 |
|
48 |
|
49 |
+
def update_endpoint_exception(e, endpoint_name, repository, framework, task, accelerator, vendor, region, type, instance_size, instance_type):
|
|
|
|
|
50 |
logger.debug("Hit the following exception:")
|
51 |
logger.debug(e)
|
52 |
logger.debug("Attempting to continue.")
|