hf-serve
[!WARNING] This project is still experimental, meant to replace the former
huggingface-inference-toolkit.
Installation
First you need to setup your environment with uv (or with your preferred Python environment manager).
uv venv --python 3.12
source .venv/bin/activate
[!NOTE] Due to the need of
--preview-features extra-build-dependenciesto installflash-attnwithuvwithout compiling it, but rather relying on the pre-built binaries, you need to useuvv0.8.13 (or higher, but beware on major updates since the feature is still experimental, so < v0.9.0 is recommended until stable).Reference: https://docs.astral.sh/uv/concepts/projects/config/#augmenting-build-dependencies
To update
uvonce installed ifuv versionis lower than v0.8.13, simplyuv self update.
Install it from the uv.lock file for CPU / MPS as follows:
uv sync --active --frozen --extra cpu
Alternatively, install it on NVIDIA CUDA 12.6 as follows:
uv sync --active --frozen --extra cuda --extra flash-attn --preview-features extra-build-dependencies
Or if you're on CUDA 12.8 then:
uv sync --active --frozen --extra cuda-128 --extra flash-attn --preview-features extra-build-dependencies
[!NOTE] There's no
cuda-130(CUDA 13.0) extra for now, asflash-attn==2.8.3's wheel-detection logic predates CUDA 13 and would silently install a mismatchedcu12wheel that fails at import time. It'll be added back once upstream fixes this.
[!WARNING] The default registry for the NVIDIA CUDA wheels for PyTorch is set to CUDA 12.6. If you want to install another PyTorch version as per the CUDA compatibility, then run e.g.
uv pip install -e . --torch-backend cu128, but note it won't be relying on theuv.lockso some dependencies might mismatch.Reference: https://docs.astral.sh/uv/guides/integration/pytorch/#automatic-backend-selection
$ uv run hf-serve --help
Examples
[!NOTE] On the examples below, given the recently introduced
extra-build-dependenciesforflash-attnon CUDA as per https://docs.astral.sh/uv/concepts/projects/config/#build-isolation, it means that you'll need to run the examples asuv run --preview-features extra-build-dependencies ...to disable the warning:warning: The `extra-build-dependencies` option is experimental and may change without warning. Pass `--preview-features extra-build-dependencies` to disable this warning.
🤏 Run HuggingFaceTB/SmolLM3-3B with an OpenAI API
uv run hf-serve --model-id HuggingFaceTB/SmolLM3-3B --task text-generation --dtype float16
[!NOTE] If you are running on an instance with NVIDIA GPU, it's recommended to install
hf-servewithflash-attnextra in order to benefit from accelerated inference:uv sync --active --frozen --extra cuda --extra flash-attn --preview-features extra-build-dependencies
🔵 Run sentence-transformers/all-MiniLM-L6-v2 on Azure AI
uv run hf-serve --model-id sentence-transformers/all-MiniLM-L6-v2 --task sentence-similarity --dtype float32 --cloud azure
[!WARNING] Given that Azure AI Foundry and Azure ML expect the inference route to be
/scorerather than/predict, which is the standard for Inference Endpoints API, and since/scoreis a redirect to/predict, then we need to send thecurlrequest with the-L/--locationflag so that it follows the redirect, otherwise we get an HTTP 307.curl -L http://localhost:8080/score -H "Content-Type: application/json" -d '{"inputs":{"source_sentence":"What is Deep Learning?","sentences":["Deep Learning is...","Deep Learning is not..."]}}'
🟠 Run sentence-transformers/all-MiniLM-L6-v2 on Amazon SageMaker
uv run hf-serve --model-id sentence-transformers/all-MiniLM-L6-v2 --task sentence-similarity --dtype float32 --cloud sagemaker
[!NOTE] When
--cloud sagemakeris set, middleware internally routesGET /pingto/healthandPOST /invocationsto/predict. To invoke another POST route, setrouteinX-Amzn-SageMaker-Custom-Attributes, for exampleroute=/v1/chat/completions. Unknown routes are rejected with HTTP 400. When deployingDockerfile.sagemaker, setTASKin the SageMaker model's container environment. SetMODEL_IDto load from the Hub. If neitherMODEL_IDnorMODEL_DIRis provided, model artifacts extracted by SageMaker into/opt/ml/modelare selected automatically.curl http://localhost:8080/ping curl http://localhost:8080/invocations -H "Content-Type: application/json" -d '{"inputs":{"source_sentence":"What is Deep Learning?","sentences":["Deep Learning is...","Deep Learning is not..."]}}'
👂 Run facebook/wav2vec2-base-960h an automatic-speech-recognition model
[!NOTE] Before running
automatic-speech-recognitionor really any ofaudio-classificationorzero-shot-audio-classificationyou will need to install some system dependencies in advance for those to work asffmpegandlibmagic-dev.
uv run hf-serve --model-id facebook/wav2vec2-large-960h --task automatic-speech-recognition --dtype float16
[!WARNING] On MacOS, if you installed
ffmpegviabrew, you will need to set the following environment variable in advanceDYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/libReference: https://github.com/pytorch/torchcodec/issues/570#issuecomment-2913609176
And, then you can send a sample request as:
curl -L http://localhost:8080/predict \
-H "Content-Type: application/json" \
-d '{"inputs":"https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/1.flac"}'
[!WARNING] Given the nature of some tasks that need to support JSON, forms, and files, the
/predictmethod for those is a redirect to the respective inner endpoint:/predict-json,/predict-form, and/predict-file. Those are non-standard but required to keep full compatibility with the current Hugging Face Inference Endpoints API Specification, but in reality the redirect response (HTTP 307) shouldn't be used as an routing route, but rather dedicated routes for those.
[!NOTE] The OpenAI Audio Transcriptions API is still not yet part of
hf-servebut it's on the roadmap and it will be released soon, stay tuned!
🔈 Run facebook/wav2vec2-lv-60-espeak-cv-ft (with phonemizer and espeak)
[!NOTE] Some models as e.g.
facebook/wav2vec2-lv-60-espeak-cv-ft, rely onphonemizerfor the "phonemization" of words and texts in many languages, based at the same time on different Text-To-Speech (TTS) backends as e.g.espeak-ngwhich is supports a lot of languages and IPA (International Phonetic Alphabet). This being said, such models require custom dependencies that need to be installed beforehand as those don't come as defaulthf-servedependencies; whilst those can be installed as e.g. on MacOS:brew install ffmpeg brew install espeak
[!WARNING] Beware that when installing
ffmpegwithbrewon a specific version as e.g.brew install ffmpeg@7as it will be installed as "keg-only", meaning that it won't be symlinked into/opt/homebrew, meaning that the path to the library won't be/opt/homebrew/libbut rather/opt/homebrew/opt/ffmpeg/libinstead, meaning that on MacOS you'll need to setDYLD_FALLBACK_LIBRARY_PATHto wherever theffmpeglibrary is installed in.
To run facebook/wav2vec2-lv-60-espeak-cv-ft on e.g. MacOS, you need to run the following:
DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib uv run hf-serve --model-id facebook/wav2vec2-lv-60-espeak-cv-ft --task automatic-speech-recognition --dtype float16 --device mps
Note that if you have installed another version of ffmpeg with brew as e.g. brew install ffmpeg@7, you should use the following command instead:
DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/opt/ffmpeg@7/lib uv run hf-serve --model-id facebook/wav2vec2-lv-60-espeak-cv-ft --task automatic-speech-recognition --dtype float16 --device mps
The main difference relies on the path used for DYLD_FALLBACK_LIBRARY_PATH which is now pointing to the exact brew-installed version of ffmpeg instead. More information on the compatibility issues with ffmpeg, torchcodec and torch at https://github.com/meta-pytorch/torchcodec?tab=readme-ov-file#installing-torchcodec.
Release files for hf-serve 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hf_serve-0.1.4.tar.gz | 52.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hf_serve-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 154.1 kB
Release files / hf_serve-0.1.4.tar.gz
| Download URL | hf_serve-0.1.4.tar.gz |
|---|---|
| Size | 52.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
744481f2f850b8978d273b04afda494637014c8f221efca532d2f7224b49a0b3
|
|
BLAKE2b-256 checksum How to use checksums |
d6d61862ece0fc37d0f5a3aa7b15eceebb593789895eb078937d5dd14e15ac0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.
Transparency logRelease files / hf_serve-0.1.4-py3-none-any.whl
| Download URL | hf_serve-0.1.4-py3-none-any.whl |
|---|---|
| Size | 101.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1284e679ac9ca9d840a3802d63ac240fa88432c1aeeed81e03bfb0cfa742dc60
|
|
BLAKE2b-256 checksum How to use checksums |
a711e910c5a63f5d59420401ae0d01625b1c4211812d2c018273ff018fe00214
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.
Transparency log