Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced InferenceClient #1474

Merged
merged 50 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1fa1639
First draft for an enhanced InferenceClient
Wauplin May 15, 2023
c0796fb
Merge branch 'main' into enhanced-inference-client
Wauplin May 17, 2023
3b65b3c
Merge branch 'main' into enhanced-inference-client
Wauplin May 19, 2023
ecfec27
Added more tasks
Wauplin May 19, 2023
8d70590
docs
Wauplin May 19, 2023
4d45b48
handle image and audio from URLs as well
Wauplin May 19, 2023
6acb14c
open anything as binary
Wauplin May 22, 2023
e1d5c76
image-to-image + some refacto
Wauplin May 22, 2023
92a4d95
make InferenceClient experiemental for now
Wauplin May 22, 2023
7b07de3
Handle timeouts
Wauplin May 22, 2023
2a7de0f
comments and docstrings
Wauplin May 22, 2023
c52d915
docs
Wauplin May 22, 2023
abf4198
fix docs
Wauplin May 22, 2023
8e3910e
fix docs?
Wauplin May 22, 2023
b79edc0
stupid copy-paste
Wauplin May 22, 2023
2dcd24c
unity
Wauplin May 24, 2023
158a67a
add text-to-image
Wauplin May 24, 2023
1ebef66
change
Wauplin May 24, 2023
22a3ba8
better
Wauplin May 24, 2023
d6fdab2
better docs?
Wauplin May 24, 2023
4caffc5
remove experiemntal
Wauplin May 24, 2023
cd04737
not experimental at all
Wauplin May 24, 2023
684f173
implement feature-extraction
Wauplin May 25, 2023
b5baa9f
sentence similarity + docstrings
Wauplin May 25, 2023
593239b
image to text
Wauplin May 25, 2023
3ab9fc6
docstring
Wauplin May 25, 2023
628b4ee
move warnings in docs
Wauplin May 25, 2023
4a71f60
quality
Wauplin May 25, 2023
9b6330a
more docs
Wauplin May 25, 2023
2013de0
fix code block
Wauplin May 25, 2023
616a8d6
detailed guide
Wauplin May 25, 2023
668e3f0
typos
Wauplin May 25, 2023
745fd51
links in docs
Wauplin May 26, 2023
cbd3e4f
fix types
Wauplin May 26, 2023
7388abe
more links
Wauplin May 26, 2023
6aaf3ed
add a todo
Wauplin May 26, 2023
8b22a70
Add VCR tests
Wauplin May 26, 2023
67c69f5
more tests
Wauplin May 26, 2023
1e11213
No VCR recording in CI
Wauplin May 26, 2023
3383597
pip freeze in CI
Wauplin May 26, 2023
c93d9b5
use urllib3 v1.x in tests
Wauplin May 26, 2023
59ad549
Merge branch 'main' into enhanced-inference-client
Wauplin May 30, 2023
e0f5498
Apply suggestions from code review
Wauplin May 30, 2023
26f054d
Apply suggestions from code review
Wauplin May 30, 2023
57c0611
requested changed
Wauplin May 30, 2023
b3651dd
add reco
Wauplin May 30, 2023
aa28a0d
Merge branch 'main' into enhanced-inference-client
Wauplin May 30, 2023
978fbf2
supported list as table instead
Wauplin May 30, 2023
a22ffb7
table header
Wauplin May 30, 2023
91fc7d6
Update tests/test_inference_client.py
Wauplin May 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ jobs:

esac

# Easy debugging if CI is broken
- name: Pip freeze
run: pip freeze

# Run tests
- name: Run tests
working-directory: ./src # For code coverage to work
run: |
PYTEST="python -m pytest --cov=./huggingface_hub --cov-report=xml:../coverage.xml"
PYTEST="python -m pytest --cov=./huggingface_hub --cov-report=xml:../coverage.xml --vcr-record=none"

case "${{ matrix.test_name }}" in

Expand Down Expand Up @@ -150,10 +154,14 @@ jobs:
pip install .[testing]
# sudo apt install -y libsndfile1-dev

# Easy debugging if CI is broken
- name: Pip freeze
run: pip freeze

# Run tests
- name: Run tests
working-directory: ./src # For code coverage to work
run: python -m pytest --cov=./huggingface_hub --cov-report=xml:../coverage.xml ../tests
run: python -m pytest --cov=./huggingface_hub --cov-report=xml:../coverage.xml --vcr-record=none ../tests

# Upload code coverage
- name: Upload coverage reports to Codecov with GitHub Action
Expand Down
3 changes: 2 additions & 1 deletion docs/source/_redirects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ how-to-manage: guides/repository
how-to-model-cards: guides/model-cards
how-to-upstream: guides/upload
search-the-hub: guides/search
guides/manage_spaces: guides/manage-spaces
guides/manage_spaces: guides/manage-spaces
package_reference/inference_api: package_reference/inference_client
4 changes: 2 additions & 2 deletions docs/source/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
title: Downloading files
- local: package_reference/mixins
title: Mixins & serialization methods
- local: package_reference/inference_api
title: Inference API
- local: package_reference/inference_client
title: Inference Client
- local: package_reference/hf_file_system
title: HfFileSystem
- local: package_reference/utilities
Expand Down
304 changes: 280 additions & 24 deletions docs/source/guides/inference.mdx

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions docs/source/package_reference/inference_api.mdx

This file was deleted.

48 changes: 48 additions & 0 deletions docs/source/package_reference/inference_client.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Inference

Inference is the process of using a trained model to make predictions on new data. This process can be compute-intensive
which makes it interesting to run on a remote machine. The `huggingface_hub` library provides an easy way to call a
service that runs fast inference for hosted models. There are several services you can connect to:
- [Inference API](https://huggingface.co/docs/api-inference/index): a service that allows you to run accelerated inference
Wauplin marked this conversation as resolved.
Show resolved Hide resolved
on Hugging Face's infrastructure and for free. This service is a fast way to get started, tests different models and
prototype AI products.
- [Inference Endpoints](https://huggingface.co/inference-endpoints): a product to easily deploy models to production.
Inference is run by Hugging Face in a dedicated, fully managed infrastructure on the Cloud of your choice.
- [SageMaker Hugging Face Inference Toolkit](https://github.com/aws/sagemaker-huggingface-inference-toolkit)

All of these services can be called with the `InferenceClient` client. Please refer to [this guide](../guides/inference)
for more information on how to use it.

## Inference Client

[[autodoc]] InferenceClient

### InferenceTimeoutError

[[autodoc]] InferenceTimeoutError

### Return types

For most tasks, the return value has a built-in type (string, list, image...). Here is a list for the more complex types.

[[autodoc]] huggingface_hub._inference_types.ClassificationOutput

[[autodoc]] huggingface_hub._inference_types.ConversationalOutputConversation

[[autodoc]] huggingface_hub._inference_types.ConversationalOutput

[[autodoc]] huggingface_hub._inference_types.ImageSegmentationOutput

## InferenceAPI

[`InferenceAPI`] is the legacy way to call the Inference API. The interface is more simplistic and requires to know
Wauplin marked this conversation as resolved.
Show resolved Hide resolved
the input parameters and output format for each task. It also lacks the ability to connect to other services like
Wauplin marked this conversation as resolved.
Show resolved Hide resolved
Inference Endpoints or AWS SageMaker. It is still supported but we recommend using [`InferenceClient`] whenever possible.
Check out [this guide](../guides/inference#legacy-inferenceapi-client) to learn how to switch from [`InferenceAPI`] to
[`InferenceClient`] in your scripts.

[[autodoc]] InferenceApi
- __init__
- __call__
- all

3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ def get_version() -> str:
"pytest-cov",
"pytest-env",
"pytest-xdist",
"pytest-vcr", # to mock Inference
"urllib3<2.0", # VCR.py broken with urllib3 2.0 (see https://urllib3.readthedocs.io/en/stable/v2-migration-guide.html)
"soundfile",
"Pillow",
"gradio", # to test webhooks
"numpy", # for embeddings
]

# Typing extra dependencies list is duplicated in `.pre-commit-config.yaml`
Expand Down
8 changes: 8 additions & 0 deletions src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
# WARNING: any comment added in this dictionary definition will be lost when
# re-generating the file !
_SUBMOD_ATTRS = {
"_inference": [
"InferenceClient",
"InferenceTimeoutError",
],
"_login": [
"interpreter_login",
"login",
Expand Down Expand Up @@ -342,6 +346,10 @@ def __dir__():
# make style
# ```
if TYPE_CHECKING: # pragma: no cover
from ._inference import (
InferenceClient, # noqa: F401
InferenceTimeoutError, # noqa: F401
)
from ._login import (
interpreter_login, # noqa: F401
login, # noqa: F401
Expand Down
Loading