Skip to main content

hf-serve

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

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

Or for CUDA 13.0, including NVIDIA GB10 / DGX Spark:

uv sync --active --frozen --extra cuda-130

Or on AWS Trainium (Trn2 / Trn3) via Torch NeuronX 2.13+, the PyTorch-native Neuron backend that adds the neuron device (requires the Neuron driver and runtime, already available on the Neuron DLAMIs and Deep Learning Containers):

uv sync --active --frozen --extra neuron

On Neuron, --device auto resolves to neuron (or set --device neuron explicitly), and models run in PyTorch eager mode. The neuron extra requires Python 3.13+, and is not compatible with the kenlm extra, as pyctcdecode pins numpy<2 whereas torch-neuronx requires numpy>=2.

$ uv run hf-serve --help

KenLM is optional because its installation requires compiling a C++ extension. EmbeddingGemma 2 and normal audio inference do not need it. For ASR models that use KenLM language-model decoding, add --extra kenlm alongside your backend:

uv sync --active --frozen --extra cpu --extra kenlm

Video inputs require TorchCodec and system FFmpeg libraries. TorchCodec is included in the dependencies; this checkout selects its CPU wheels for all model backends, so video decoding does not require a separate CUDA runtime. If updating an existing environment, run uv sync --active --frozen --extra cpu (or your CUDA backend extra).

Container images

On each push to main, CI publishes images to ghcr.io/<owner>/hf-serve using the first seven characters of the commit SHA as the tag. Images are built on native runners for the architectures listed below:

Tag Backend Architectures
<sha> CUDA 12.6 linux/amd64, linux/arm64
<sha>-cu130-arm64 CUDA 13.0, tested on NVIDIA GB10 / DGX Spark linux/arm64
<sha>-cpu CPU linux/amd64, linux/arm64

For example, to pull the CUDA 13.0 image published by the upstream repository:

docker pull ghcr.io/huggingface/hf-serve:<sha>-cu130-arm64

Use a commit published after multi-platform support was added; older tags may only contain AMD64 images. Docker selects the architecture for the host.

To build the CUDA 13.0 variant locally from this checkout:

docker buildx build --platform linux/arm64 \
  --build-arg BASE_IMAGE=nvidia/cuda:13.0.2-devel-ubuntu24.04 \
  --build-arg TORCH_EXTRA=cuda-130 \
  --tag hf-serve:gb10 --load .

Examples

🤏 Run HuggingFaceTB/SmolLM3-3B with an OpenAI API

uv run hf-serve --model-id HuggingFaceTB/SmolLM3-3B --task text-generation --dtype float16

📏 Run google/embeddinggemma-2

EmbeddingGemma 2 supports text, images, audio, video, and interleaved inputs through Sentence Transformers. It requires Transformers 5.19+ and Sentence Transformers 6.1+.

uv run hf-serve --model-id google/embeddinggemma-2 --task feature-extraction

For embedding tasks, --device auto selects a single available device rather than sharding the model across GPUs. To select a specific GPU on a multi-GPU host:

CUDA_VISIBLE_DEVICES=0 uv run hf-serve --model-id google/embeddinggemma-2 --task feature-extraction --device cuda

The default precision is bfloat16 on CUDA devices that support it and float32 elsewhere. Use --dtype float32 or --dtype bfloat16 to override it; float16 is rejected because it produces invalid embeddings for this model.

Choose SearchQuery for search queries and Document for untitled documents. Other prompt names, including CodeRetrieval and SentenceSimilarity, are listed in the model card. No task prefix is added unless a prompt is selected.

curl http://localhost:8080/predict -H 'Content-Type: application/json' \
  -d '{"inputs":"What causes the northern lights?","prompt_name":"SearchQuery","dimensions":256}'

curl http://localhost:8080/v1/embeddings -H 'Content-Type: application/json' \
  -d '{"model":"google/embeddinggemma-2","input":"The northern lights are caused by charged particles from the sun.","prompt_name":"Document","dimensions":256}'

Both routes accept a single modality dictionary or a batch of dictionaries as well as the existing text strings. Media values can be URLs or server-local paths. Images also support base64. A list of media values inside one dictionary produces one shared embedding. You should can use the model's placeholder tokens to position media within text:

curl http://localhost:8080/predict -H 'Content-Type: application/json' \
  -d '{"inputs":{"text":"Waterproof running shoes. <|image|> Grip test: <|video|>","image":"https://example.com/shoe.jpg","video":"/data/grip-test.mp4"},"dimensions":512}'

Use image, audio, or video dictionaries without a prompt for media-only inputs. On Google Cloud, the same inputs can be supplied in instances. The native vector has 768 dimensions; the model supports shortening it to 512, 256, or 128. Outputs are L2-normalized after truncation by default. /predict also accepts normalize: false to disable that final normalization.

🥇 Run cross-encoder/ms-marco-MiniLM-L6-v2 with a TEI-compatible /rerank

uv run hf-serve --model-id cross-encoder/ms-marco-MiniLM-L6-v2 --task text-ranking

Besides / and /predict (which return {"scores": [...]}), text-ranking exposes /rerank, matching the Text Embeddings Inference (TEI) /rerank request, response, and error formats:

curl http://localhost:8080/rerank -H "Content-Type: application/json" -d '{"query":"What is Deep Learning?","texts":["Cheese is tasty","Deep Learning is..."],"return_text":true}'
# [{"index":1,"score":0.99,"text":"Deep Learning is..."},{"index":0,"score":0.0001,"text":"Cheese is tasty"}]

raw_scores: true returns the logits instead of the sigmoid scores. Inputs longer than the model's maximum sequence length are truncated from truncation_direction (right by default), unless truncate: false is set, in which case the request fails with HTTP 422. The same parameters can also be sent to / and /predict, either at the top level or within parameters.

To score explicit [query, document] pairs instead, send sentences to / or /predict, either a single pair or a list of pairs, which returns one score per pair (or one list of scores per pair for models with more than one label):

curl http://localhost:8080/predict -H "Content-Type: application/json" -d '{"sentences":[["What is Deep Learning?","Deep Learning is..."],["What is Deep Learning?","Cheese is tasty"]]}'
# {"scores":[0.99,0.0001]}

🔵 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

🟠 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

👂 Run facebook/wav2vec2-base-960h an automatic-speech-recognition model

uv run hf-serve --model-id facebook/wav2vec2-large-960h --task automatic-speech-recognition --dtype float16

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"}'

Run voice activity detection

The voice-activity-detection task supports diarization-capable audio frame classification models whose processor exposes extract_speaker_dict. It returns speaker segments with start, end (seconds), and speaker (arrival-order index):

uv run hf-serve --model-id your-org/your-model --task voice-activity-detection

Send an audio URL, base64-encoded audio, or an audio file through the same JSON, form, or binary endpoints used by ASR:

curl -L http://localhost:8080/predict-json \
    -H "Content-Type: application/json" \
    -d '{"inputs":"https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/diarization_example.mp3"}'

Offline inference is the default. To process the recording in streaming chunks within one request, add "parameters":{"streaming_mode":"low_latency"} to the JSON body, or send streaming_mode=low_latency with a form upload. The other supported modes are very_low_latency and ultra_low_latency. Each request has its own speaker cache; the API does not retain a streaming session across requests.

On Google Cloud, run with --cloud google and send audio strings in instances. The same parameters apply to every instance, and the response contains one predictions entry per instance:

{"instances": ["<base64-encoded audio>"], "parameters": {"streaming_mode": "low_latency"}}

🔈 Run facebook/wav2vec2-lv-60-espeak-cv-ft (with phonemizer and espeak)

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.

Metadata

Release files for hf-serve 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hf-serve 0.2.1
File Size Uploaded Provenance Actions
hf_serve-0.2.1.tar.gz 66.7 kB With provenance Details for hf_serve-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hf-serve 0.2.1
File Interpreter ABI Platform Actions
hf_serve-0.2.1-py3-none-any.whl Python 3 none any Details for hf_serve-0.2.1-py3-none-any.whl

Total release size: 186.6 kB

Release files / hf_serve-0.2.1.tar.gz

Download URL hf_serve-0.2.1.tar.gz
Size 66.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a3cb86330111245e7602009f5f5ee0af11e05cb72b8cbc1dc05f4bf05c5be22d
BLAKE2b-256 checksum
How to use checksums
2041c16ff644b1a98e610115b5c1988f8682cf8257e09d1819742e8408e38913
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":"26.04","id":"resolute","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 Nov 19, 2026.

Transparency log

Release files / hf_serve-0.2.1-py3-none-any.whl

Download URL hf_serve-0.2.1-py3-none-any.whl
Size 119.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cdfff430b64b48c478c8be55325024eba600b81d32e5c928c5915d4f6bcbd986
BLAKE2b-256 checksum
How to use checksums
fb236e2ca4011f40b7fb5b42d8306434cba106614f9ad1ce2c4f0a97bca399d5
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":"26.04","id":"resolute","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 Nov 19, 2026.

Transparency log

Security for hf-serve 0.2.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hf_serve-0.2.1.tar.gz

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 Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page