Text Generation Inference (TGI): Hugging Face's Production Server
Hugging Face's Text Generation Inference (TGI) is the production-grade LLM server behind Hugging Face's Inference Endpoints and used by major companies. For local deployment, it offers continuous batching, flash attention, tensor parallelism, and quantization support in a single Docker container. Here's when and how to use it.
Quick Start with Docker
TGI runs as a Docker container: docker run --gpus all -p 8080:80 -v $PWD/models:/data ghcr.io/huggingface/text-generation-inference --model-id meta-llama/Llama-3.1-8B-Instruct --huggingface-hub-token YOUR_TOKEN. The container downloads the model automatically. TGI exposes an OpenAI-compatible endpoint and its own REST API with streaming support. The --quantize bitsandbytes-nf4 flag enables 4-bit quantization without separate model preparation.
Key TGI Features
Continuous batching (Orca scheduling) dynamically groups requests for maximum GPU utilization — idle GPU cycles between user requests are eliminated. PagedAttention manages KV cache memory like OS virtual memory, allowing more concurrent users per GPU. Guided generation (structured output) enforces JSON schemas or regex patterns on model outputs, making it excellent for tool calling and structured data extraction pipelines.
TGI vs vLLM vs Ollama
TGI and vLLM have comparable throughput for multi-user serving. TGI has slightly better HuggingFace model compatibility and simpler Docker setup. vLLM has more community momentum and better OpenAI API compatibility. Ollama is significantly easier to operate but has lower multi-user throughput. For a single developer or small team, Ollama wins on simplicity. For 10+ concurrent users, TGI or vLLM is the right choice.

Comments
Post a Comment