← Zurück zur Bibliothek
Inference Server Anbieter: Hugging Face

Hugging Face TGI

Text Generation Inference (TGI) ist Hugging Faces produktionsreife LLM-Serving-Lösung, die 2023 eingeführt wurde. TGI bietet optimierte Inferenz für beliebte Modelle (Llama, Mistral, Falcon, StarCoder) mit Continuous Batching, Tensor-Parallelismus, Quantisierung und Streaming-Unterstützung. Stand Oktober 2025 treibt TGI Hugging Faces Inference Endpoints an und wird von Tausenden Unternehmen für produktive LLM-Deployments genutzt. Hauptmerkmale: 2-3x schneller als naives PyTorch-Serving, automatisches Continuous Batching, Multi-GPU-Unterstützung, Docker-Deployment, OpenAI-kompatible API. Open Source (Apache 2.0) mit verfügbarem kommerziellem Support. Konkurriert mit vLLM und TensorRT-LLM für hochperformantes LLM-Serving.

Hugging Face TGI
inference serving llm optimization huggingface

Überblick

TGI optimiert LLM-Inferenz durch: (1) Continuous Batching - dynamisches Hinzufügen/Entfernen von Anfragen für maximale GPU-Auslastung, (2) Tensor-Parallelismus - Aufteilung von Modellen auf mehrere GPUs, (3) Flash Attention - 2-4x schnellere Attention-Berechnung, (4) Paged Attention - effizientes KV-Cache-Management, (5) Quantisierung - bitsandbytes, GPTQ, AWQ für kleineren Speicher-Footprint. Performance: Llama 3 70B liefert 45 Tokens/Sek./Nutzer auf 4× A100 vs. 15 Tokens/Sek. mit Vanilla Transformers = 3x Verbesserung. Unterstützt: Llama, Mistral, Mixtral, Falcon, StarCoder, Bloom, GPT-NeoX. Deployment: Docker-Container, Kubernetes, AWS/GCP/Azure. API: OpenAI-kompatibel plus Streaming, Tool Calling, Guided Generation.

Hauptfunktionen

  • Continuous Batching: 2-5x Durchsatzverbesserung durch dynamisches Batching
  • Tensor-Parallelismus: Nahtlose Verteilung von Modellen auf 2-8 GPUs
  • Flash Attention 2: Integriert für 2-4x schnellere Attention
  • Quantisierung: GPTQ-, AWQ-, bitsandbytes-Unterstützung für 4-8-Bit-Inferenz
  • Streaming: Token-für-Token-Streaming für Echtzeitantworten
  • Tool Calling: Function Calling und strukturierte JSON-Outputs
  • OpenAI-kompatibel: Drop-in-Ersatz für OpenAI API
  • Docker-Deployment: Einzelner Container mit allen Abhängigkeiten

Performance-Benchmarks

Llama 3 70B auf 4× A100 80GB: TGI erreicht 45 Tokens/Sek. Durchsatz mit 32 gleichzeitigen Nutzern vs. 15 Tokens/Sek. mit Transformers = 3x schneller. Mistral 7B auf einzelner A100: 120 Tokens/Sek. mit TGI vs. 40 Tokens/Sek. nativ = 3x schneller. Speicher: Llama 3 70B benötigt 140GB mit FP16, 70GB mit GPTQ 4-Bit. Latenz: Time-to-first-token ~50-100ms, nachfolgende Tokens streamen mit Modellgenerierungsgeschwindigkeit. TGI vs. vLLM: Ähnliche Performance (beide nutzen Continuous Batching + Flash Attention), TGI einfachere Integration ins Hugging Face-Ökosystem, vLLM etwas schneller für manche Workloads.

Code-Beispiel

# Deploy TGI with Docker
# docker run --gpus all --shm-size 1g -p 8080:80 \
#   -v $PWD/data:/data \
#   ghcr.io/huggingface/text-generation-inference:latest \
#   --model-id meta-llama/Meta-Llama-3-70B \
#   --quantize gptq \
#   --num-shard 4

# Client usage (OpenAI-compatible)
from huggingface_hub import InferenceClient

client = InferenceClient("http://localhost:8080")

# Streaming generation
for token in client.text_generation(
    "Write a Python function to calculate factorial:",
    max_new_tokens=200,
    stream=True
):
    print(token, end="", flush=True)

# Batch inference
responses = client.text_generation(
    ["Explain AI:", "What is Python?"],
    max_new_tokens=100
)

# Using OpenAI Python client (compatible API)
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="dummy"  # TGI doesn't require auth by default
)

response = client.chat.completions.create(
    model="tgi",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True
)

for chunk in response:
    print(chunk.choices[0].delta.content, end="")

# Tool calling / function calling
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get weather for location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string"}
            }
        }
    }
}]

response = client.chat.completions.create(
    model="tgi",
    messages=[{"role": "user", "content": "What's the weather in Paris?"}],
    tools=tools
)

if response.choices[0].message.tool_calls:
    print(response.choices[0].message.tool_calls[0].function)

TGI vs. vLLM vs. TensorRT-LLM

TGI: Beste Hugging Face-Integration, OpenAI-kompatible API, Docker-First, Apache 2.0. vLLM: Etwas schneller (5-10%), PagedAttention-Pionier, mehr Quantisierungsoptionen. TensorRT-LLM: Am schnellsten (10-20% über vLLM), nur NVIDIA, komplexes Setup. Wählen Sie TGI für: Hugging Face-Ökosystem-Nutzer, einfaches Deployment, kommerziellen Support-Bedarf. Wählen Sie vLLM für: Maximale Performance, Custom-Model-Formate. Wählen Sie TensorRT-LLM für: NVIDIA-Infrastruktur, absolute Spitzenperformance. Die meisten Organisationen starten mit TGI wegen der Benutzerfreundlichkeit und wechseln zu vLLM/TensorRT-LLM, wenn Performance zum Bottleneck wird.

Professionelle Integrationsdienste von 21medien

21medien bietet TGI-Deployment-Services inklusive Docker/Kubernetes-Setup, Multi-GPU-Konfiguration, Quantisierungsoptimierung, API-Integration und Produktions-Monitoring. Unser Team spezialisiert sich auf LLM-Serving-Infrastruktur, Kostenoptimierung durch Quantisierung und Batching sowie den Aufbau zuverlässiger Serving-Systeme. Kontaktieren Sie uns für maßgeschneiderte TGI-Deployment-Lösungen.

Ressourcen

GitHub: https://github.com/huggingface/text-generation-inference | Dokumentation: https://huggingface.co/docs/text-generation-inference | Docker Hub: https://hub.docker.com/r/huggingface/text-generation-inference