From 157b1e949718c655894d476ca156331030fd7933 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Fri, 18 Jun 2021 11:09:31 +0200 Subject: [PATCH 1/7] Simplify manage to autodetect task+framework if possible. --- api-inference-community/manage.py | 44 ++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/api-inference-community/manage.py b/api-inference-community/manage.py index da83716970..357aaf4753 100755 --- a/api-inference-community/manage.py +++ b/api-inference-community/manage.py @@ -4,6 +4,8 @@ import os import subprocess import uuid +import ast +from huggingface_hub import HfApi class cd: @@ -63,6 +65,30 @@ def show(args): print(" " * 4, key.value) +def resolve(model_id: str) -> [str, str]: + info = HfApi().model_info(model_id) + task = info.pipeline_tag + framework = None + frameworks = { + "flair", + "speechbrain", + "allennlp", + "asteroid", + "espnet", + "sentence-transformers", + "spacy", + } + for tag in info.tags: + if tag in frameworks: + if framework is None: + framework = tag + else: + raise Exception( + "This model seems to implement 2 frameworks, we cannot infer" + ) + return task, framework.replace("-", "_") + + def start(args): import sys @@ -71,6 +97,14 @@ def start(args): model_id = args.model_id task = args.task framework = args.framework + if task is None or framework is None: + rtask, rframework = resolve(model_id) + if task is None: + task = rtask + print(f"Inferred task : {task}") + if framework is None: + framework = rframework + print(f"Inferred framework : {framework}") local_path = os.path.join( os.path.dirname(os.path.dirname(__file__)), "docker_images", framework @@ -85,6 +119,12 @@ def docker(args): model_id = args.model_id task = args.task framework = args.framework + if task is None or framework is None: + rtask, rframework = resolve(model_id) + if task is None: + task = rtask + if framework is None: + framework = rframework tag = create_docker(framework) run_docker_command = [ @@ -124,13 +164,11 @@ def main(): parser_start.add_argument( "--task", type=str, - required=True, help="Which task to load", ) parser_start.add_argument( "--framework", type=str, - required=True, help="Which framework to load", ) parser_start.set_defaults(func=start) @@ -146,13 +184,11 @@ def main(): parser_docker.add_argument( "--task", type=str, - required=True, help="Which task to load", ) parser_docker.add_argument( "--framework", type=str, - required=True, help="Which framework to load", ) parser_docker.set_defaults(func=docker) From 59d5892a036fe9852a3b87533d999e4cc3a67bc7 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Fri, 18 Jun 2021 16:48:01 +0200 Subject: [PATCH 2/7] Style. --- api-inference-community/manage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-inference-community/manage.py b/api-inference-community/manage.py index 357aaf4753..336e934c53 100755 --- a/api-inference-community/manage.py +++ b/api-inference-community/manage.py @@ -4,7 +4,7 @@ import os import subprocess import uuid -import ast + from huggingface_hub import HfApi From d1e1472ebf0be51b4c38452a367359c1b860dc00 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Fri, 18 Jun 2021 16:50:06 +0200 Subject: [PATCH 3/7] Adding huggingface_hub as test dependency. --- .github/workflows/python-api-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-api-tests.yaml b/.github/workflows/python-api-tests.yaml index 1464d4c787..4432b380bc 100644 --- a/.github/workflows/python-api-tests.yaml +++ b/.github/workflows/python-api-tests.yaml @@ -25,7 +25,7 @@ jobs: working-directory: api-inference-community run: | pip install --upgrade pip - pip install pytest pillow httpx + pip install pytest pillow httpx huggingface_hub pip install -e . - run: make test working-directory: api-inference-community From 7e863050380738b637cf66649d4e412ddd4807bc Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Fri, 18 Jun 2021 17:14:08 +0200 Subject: [PATCH 4/7] Actions should run on PRs not on push. --- .github/workflows/python-api-allennlp.yaml | 2 +- .github/workflows/python-api-quality.yaml | 2 +- .github/workflows/python-api-tests.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-api-allennlp.yaml b/.github/workflows/python-api-allennlp.yaml index 9cd9439a93..1f8c45817c 100644 --- a/.github/workflows/python-api-allennlp.yaml +++ b/.github/workflows/python-api-allennlp.yaml @@ -1,7 +1,7 @@ name: allennlp-docker on: - push: + pull-request: paths: - "api-inference-community/docker_images/allennlp/**" jobs: diff --git a/.github/workflows/python-api-quality.yaml b/.github/workflows/python-api-quality.yaml index f5be350d90..99717d1200 100644 --- a/.github/workflows/python-api-quality.yaml +++ b/.github/workflows/python-api-quality.yaml @@ -1,7 +1,7 @@ name: Inference API code quality on: - push: + pull_request: paths: - "api-inference-community/**" diff --git a/.github/workflows/python-api-tests.yaml b/.github/workflows/python-api-tests.yaml index 4432b380bc..14a19690a1 100644 --- a/.github/workflows/python-api-tests.yaml +++ b/.github/workflows/python-api-tests.yaml @@ -1,6 +1,6 @@ name: Inference API Python-tests on: - push: + pull_request: paths: - "api-inference-community/**" jobs: From 3376aad4450e12641f4edbf981b7bcf358e2ab65 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Fri, 18 Jun 2021 17:17:46 +0200 Subject: [PATCH 5/7] Fix failing test. --- api-inference-community/api_inference_community/validation.py | 1 + api-inference-community/tests/test_routes.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/api-inference-community/api_inference_community/validation.py b/api-inference-community/api_inference_community/validation.py index f413cf62f8..8680cd6cb4 100644 --- a/api-inference-community/api_inference_community/validation.py +++ b/api-inference-community/api_inference_community/validation.py @@ -172,6 +172,7 @@ class StringInput(BaseModel): "token-classification": StringInput, "translation": StringInput, "zero-shot-classification": StringInput, + "text-to-speech": StringInput, } BATCH_ENABLED_PIPELINES = ["feature-extraction"] diff --git a/api-inference-community/tests/test_routes.py b/api-inference-community/tests/test_routes.py index e7259ed69c..09a8523d0b 100644 --- a/api-inference-community/tests/test_routes.py +++ b/api-inference-community/tests/test_routes.py @@ -124,7 +124,7 @@ async def startup_event(): app.get_pipeline = get_pipeline with TestClient(app) as client: - response = client.post("/", data=b"") + response = client.post("/", data=b"2222") self.assertEqual( response.status_code, From fd78149090a8b734346162f3c736f17b3a38af85 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Mon, 21 Jun 2021 10:30:52 +0200 Subject: [PATCH 6/7] Alphabetical order. --- api-inference-community/manage.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api-inference-community/manage.py b/api-inference-community/manage.py index 336e934c53..9cd80c24cf 100755 --- a/api-inference-community/manage.py +++ b/api-inference-community/manage.py @@ -70,13 +70,14 @@ def resolve(model_id: str) -> [str, str]: task = info.pipeline_tag framework = None frameworks = { - "flair", - "speechbrain", "allennlp", "asteroid", "espnet", + "flair", "sentence-transformers", "spacy", + "speechbrain", + "timm", } for tag in info.tags: if tag in frameworks: From ada017a38c50d316c52d353750e71ecedccb8f9d Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Mon, 21 Jun 2021 10:36:51 +0200 Subject: [PATCH 7/7] Using library_name --- api-inference-community/manage.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/api-inference-community/manage.py b/api-inference-community/manage.py index 9cd80c24cf..480d0a5f6e 100755 --- a/api-inference-community/manage.py +++ b/api-inference-community/manage.py @@ -68,25 +68,7 @@ def show(args): def resolve(model_id: str) -> [str, str]: info = HfApi().model_info(model_id) task = info.pipeline_tag - framework = None - frameworks = { - "allennlp", - "asteroid", - "espnet", - "flair", - "sentence-transformers", - "spacy", - "speechbrain", - "timm", - } - for tag in info.tags: - if tag in frameworks: - if framework is None: - framework = tag - else: - raise Exception( - "This model seems to implement 2 frameworks, we cannot infer" - ) + framework = info.library_name return task, framework.replace("-", "_")