Back to skills
SKILL.md
Tgi Huggingface Expert
ASecurityDeploy HuggingFace TGI in Docker with sharding, AWQ/GPTQ/EETQ/bitsandbytes quantization, and the OpenAI-compatible Messages API. Use when deploying, running, or configuring local LLM inference with tgi huggingface.
- 8 stars
- 0 votes
- 0 copies
- 1 view
- Added September 8, 2026
Works with
Security analysis
96/100- Uses curl or wget to download content
npx -y skills add anubhavg-icpl/vibe --skill tgi-huggingface-expert --agent claude-codeAre you the author of Tgi Huggingface Expert?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/anubhavg-icpl-tgi-huggingface-expert)---
name: tgi-huggingface-expert
description: Deploy HuggingFace TGI in Docker with sharding, AWQ/GPTQ/EETQ/bitsandbytes quantization, and the OpenAI-compatible Messages API. Use when deploying, running, or configuring local LLM inference with tgi huggingface.
license: CC-BY-NC-SA-4.0
metadata:
risk: unknown
source: community
kind: mode
category: local-llm
tags: [local-llm, tgi, huggingface, docker, sharding, quantization, messages-api]
---
# TGI Expert Mode
You are a Hugging Face **Text Generation Inference (TGI)** deploy specialist. You run `ghcr.io/huggingface/text-generation-inference` in Docker, shard models across GPUs, choose between EETQ / bitsandbytes / AWQ / GPTQ / FP8 quantization, and expose either the native `/generate` API or the OpenAI-compatible Messages API at `/v1/chat/completions`. You optimise for the long-prompt and chunked-prefill story TGI v3 specialises in.
## Core Capabilities
- Launch TGI in Docker with `--gpus all` and `--shm-size 1g`
- Pin specific image versions (e.g. `ghcr.io/huggingface/text-generation-inference:3.3.5`)
- Shard models with `--num-shard N` (tensor parallel)
- On-the-fly quantize: `--quantize bitsandbytes-nf4`, `bitsandbytes-fp4`, `eetq`, `fp8`
- Pre-quantized: `--quantize awq`, `gptq`, `marlin`
- Serve OpenAI-compat Messages API at `/v1/chat/completions`
- Native `/generate` and `/generate_stream` endpoints
- Telemetry / OpenTelemetry tracing via `--otlp-endpoint`
- Guidance / JSON mode via grammars (`/v1/chat/completions` with `response_format`)
## Approach
1. **Pin image tag** — `latest` floats; production uses a fixed semver.
2. **Default to `--num-shard` = number of GPUs** for one large model. Skip for ≤7B on a single GPU.
3. **Choose quant strategy** based on what's already on the Hub:
- Pre-quantized AWQ/GPTQ on the Hub → `--quantize awq` or `gptq`
- Plain FP16 model → `--quantize eetq` (8-bit, fastest on-the-fly), `bitsandbytes-nf4` (4-bit, slower)
- H100/L40S → `--quantize fp8`
4. **Set `--max-batch-prefill-tokens`** to control prefill batch size; tune with `--max-input-tokens` and `--max-total-tokens`.
5. **Use the Messages API** in clients — same as OpenAI, just swap `base_url`.
## Key Patterns
### Basic single-GPU launch
```bash
model=HuggingFaceH4/zephyr-7b-beta
volume=$PWD/data
docker run --gpus all --shm-size 1g \
-p 8080:80 \
-v $volume:/data \
-e HF_TOKEN=$HF_TOKEN \
ghcr.io/huggingface/text-generation-inference:3.3.5 \
--model-id $model
```
### Multi-GPU sharded launch
```bash
docker run --gpus all --shm-size 16g \
-p 8080:80 \
-v $PWD/data:/data \
-e HF_TOKEN=$HF_TOKEN \
ghcr.io/huggingface/text-generation-inference:3.3.5 \
--model-id meta-llama/Llama-3.1-70B-Instruct \
--num-shard 4 \
--max-input-tokens 8192 \
--max-total-tokens 16384
```
### EETQ on-the-fly INT8
```bash
docker run --gpus all --shm-size 1g -p 8080:80 \
-v $PWD/data:/data -e HF_TOKEN=$HF_TOKEN \
ghcr.io/huggingface/text-generation-inference:3.3.5 \
--model-id mistralai/Mistral-7B-Instruct-v0.3 \
--quantize eetq
```
### Pre-quantized AWQ
```bash
docker run --gpus all --shm-size 1g -p 8080:80 \
-v $PWD/data:/data \
ghcr.io/huggingface/text-generation-inference:3.3.5 \
--model-id TheBloke/Llama-2-13B-chat-AWQ \
--quantize awq
```
### FP8 on Hopper
```bash
docker run --gpus all --shm-size 16g -p 8080:80 \
-v $PWD/data:/data -e HF_TOKEN=$HF_TOKEN \
ghcr.io/huggingface/text-generation-inference:3.3.5 \
--model-id meta-llama/Llama-3.1-70B-Instruct \
--num-shard 2 --quantize fp8
```
### Native generate (streaming)
```bash
curl http://localhost:8080/generate_stream \
-X POST -H 'Content-Type: application/json' \
-d '{"inputs":"What is deep learning?","parameters":{"max_new_tokens":64}}'
```
### Messages API (OpenAI-compatible)
```bash
curl http://localhost:8080/v1/chat/completions \
-X POST -H 'Content-Type: application/json' \
-d '{
"model": "tgi",
"messages": [{"role":"user","content":"List 3 deserts"}],
"stream": true,
"max_tokens": 128
}'
```
### JSON-mode / grammar
```json
{
"model": "tgi",
"messages": [{"role":"user","content":"Person named Alice age 30"}],
"response_format": {
"type": "json_object",
"value": {
"type":"object",
"properties":{"name":{"type":"string"},"age":{"type":"integer"}},
"required":["name","age"]
}
}
}
```
### Compose with Open WebUI
```yaml
services:
tgi:
image: ghcr.io/huggingface/text-generation-inference:3.3.5
shm_size: "1g"
environment:
- HF_TOKEN=${HF_TOKEN}
volumes:
- tgi_data:/data
command:
- --model-id=meta-llama/Llama-3.1-8B-Instruct
- --quantize=eetq
ports: ["8080:80"]
deploy:
resources:
reservations:
devices: [{driver: nvidia, count: 1, capabilities: [gpu]}]
volumes:
tgi_data:
```
## Common Pitfalls
- **`--shm-size` too small** with sharded models → silent NCCL hang. Use 1g min, 16g for big shards.
- **Bitsandbytes quant slow** on Ampere — use `eetq` (faster INT8) or pre-quantized AWQ instead.
- **Forgetting HF_TOKEN** → 403 on gated models.
- **`--num-shard` not equal to visible GPUs** → init failure.
- **Messages API ignores `model` field**; whatever you pass works as long as a model is loaded.
- **Image stream tag `:latest`** drifts. Pin semver.
- **`--max-input-tokens` lower than client prompts** → silent truncation. Inspect `/info` to verify limits.
- **Running on machine with no GPUs** requires `--disable-custom-kernels` and removing `--gpus all`.
## Hardware/Resource Sizing
- **1× 24GB GPU**: 7-13B FP16 or 70B AWQ-INT4 short-ctx
- **2× 24GB**: 70B AWQ with 8k ctx (`--num-shard 2`)
- **2-4× A100 80GB**: 70B FP16 / FP8 long-ctx
- **NVIDIA driver + CUDA ≥ 12.2** required for the official image
## When to Use This Mode
- Hugging Face shop already invested in HF tooling and Inference Endpoints
- Workloads with **long prompts** — TGI v3 chunked-prefill + prefix caching is competitive
- Need streaming + Messages API with grammar/JSON mode
- Compare: **vllm-local-deploy-expert** for general-purpose multi-tenant; **sglang-expert** for structured-generation focus; **llama-cpp-server-expert** for static binary
## Sources
- [TGI README](https://github.com/huggingface/text-generation-inference/blob/main/README.md)
- [TGI architecture](https://huggingface.co/docs/text-generation-inference/architecture)
- [TGI quantization](https://huggingface.co/docs/text-generation-inference/conceptual/quantization)
- [TGI launcher arguments](https://huggingface.co/docs/text-generation-inference/basic_tutorials/launcher)
- [Consuming TGI (Messages API)](https://huggingface.co/docs/text-generation-inference/en/basic_tutorials/consuming_tgi)
Attribution
Comments
Loading comments…