LostGentoo's picture
Upload HF Inference Endpoint throughput/latency benches
27c1dd3 verified
|
Raw
History Blame Contribute Delete
9.96 kB
# CLI Reference & Raw REST API Fallback
## `hf endpoints` command surface
```
hf endpoints deploy NAME --repo ORG/MODEL --framework FRAMEWORK \
--accelerator {gpu|cpu} --instance-type TYPE --instance-size SIZE \
--vendor {aws|azure|gcp} --region REGION [--namespace NS] [--task TASK] \
[--min-replica N] [--max-replica N] [--scale-to-zero-timeout MIN] \
[--scaling-metric {pendingRequests|hardwareUsage}] [--scaling-threshold F] \
[--token TOKEN]
hf endpoints update NAME [same flags as deploy, all optional, partial update]
hf endpoints describe NAME [--namespace NS] [--token TOKEN]
hf endpoints ls [--namespace NS]
hf endpoints pause NAME
hf endpoints resume NAME
hf endpoints scale-to-zero NAME
hf endpoints delete NAME
hf endpoints catalog ls
hf endpoints catalog deploy --repo ORG/MODEL
```
**Check `hf version` before trusting any of this.** The installed CLI can be badly stale (e.g. 1.5.0 when 1.20+ exists — `hf` doesn't warn loudly, just nags "a new version is available" on unrelated commands). Update with `curl -LsSf https://hf.co/cli/install.sh | bash -`. Newer versions add real flags (`--custom-image`, `-e/--env`, `--secrets`, `--type`) that a stale install's `--help` won't show — always re-run `--help` after updating rather than trusting memorized flag lists (including this file's).
`--instance-type` examples: `nvidia-t4`, `nvidia-l4`, `nvidia-a10g`, `nvidia-l40s`, `nvidia-a100`, `nvidia-h100`, `nvidia-h200`, `nvidia-rtx-pro-6000` (Blackwell — currently the only Blackwell SKU on IE, `aws/us-east-2` only, check `GET /v2/provider` for current availability since regions/types shift), `intel-icl`, `intel-spr`. `--instance-size` is `x1`/`x2`/`x4`/`x8` (GPU count) or CPU vCPU tier.
### `--framework` does NOT mean "engine" — this is the single biggest CLI trap
`--framework` example text says `'e.g. vllm'`, but this is **misleading even on the latest CLI (verified against 1.20.1 source)**. The server's real `EndpointFramework` enum (confirmed via `GET /openapi.json`) is only `custom | pytorch | llamacpp`. Passing `--framework vllm` gets relayed byte-for-byte to the API and **fails with `422 unknown variant "vllm"`** — the CLI does no translation, at any version checked.
The actual engine selection lives in a *separate* JSON field, `model.image`, which the CLI has **no flag for at all**:
- `image: {"huggingface": {}}` (empty object) — the real "native, auto-select" path. This is what the Python client defaults to when no engine is forced. The backend picks the best native engine (vLLM/TGI/SGLang) for the model itself; you don't get to force a specific one this way, and you won't know which it picked until you check the boot logs.
- `image: {"vLLM": {tensorParallelSize, dataParallelSize, maxNumSeqs, maxNumBatchedTokens, kvCacheDtype, healthRoute, port, url}}` — the structured object the *dashboard's* "vLLM configuration" panel writes. **Confirmed via a real dashboard-created endpoint**: `url` = `"vllm/vllm-openai:v0.23.0"` (the official upstream vLLM Docker Hub image, version-pinned — not an HF-custom wrapper), `healthRoute` = `/health`, `port` = `8000`. So the "native vLLM" support is literally the standard vLLM project image; you *can* now construct this block by hand via raw API (`PUT`) since the URL is no longer a mystery — but the version tag will drift over time, so if hand-constructing, check a fresh dashboard-created endpoint's config first to get the current pinned tag rather than trusting this file indefinitely.
- `image: {"llamacpp": {...}}` — the one native engine actually reachable via `--framework llamacpp` and real CLI flags, since `llamacpp` is a genuine `EndpointFramework` enum value.
- `image: {"custom": {"url": ..., "healthRoute": ..., "port": ...}}` — bring your own container (e.g. official `vllm/vllm-openai` image), reachable via `--framework custom --custom-image ...` on current CLI, or raw API `model.image.custom`. This is the fallback if you need to *force* vLLM specifically and the auto-select path doesn't pick it — but work out the correct entrypoint/mount-path/args on a cheap instance before pointing it at expensive hardware, since none of that is HF-managed anymore once you're in `custom`.
**Practical recipe to get a specific native engine (e.g. vLLM) without guessing the dashboard's URL:** deploy with `framework: "pytorch"`, `image: {"huggingface": {}}`, appropriate `task`, and inspect the endpoint logs once running to see which engine was actually selected. If it's not what you wanted, that's the signal to move to the `custom` image path deliberately.
### What the CLI cannot do even after updating
No flag sets the structured `image.vLLM` engine-tuning fields (`tensorParallelSize`, `maxNumSeqs`, `maxNumBatchedTokens`, `kvCacheDtype`) — those only exist in the OpenAPI schema, reachable only via raw API `PUT` on an endpoint already using the native vLLM image (which itself you can't select without knowing its `url`, see above). llama.cpp's own args (`-np`, `-c`, `--spec-type`) similarly need raw API `model.args`, not any CLI flag — `--container-args` explicitly requires `--custom-image` per current CLI help, so it doesn't reach the native `llamacpp` image either.
## Raw REST API
Base: `https://api.endpoints.huggingface.cloud/v2/endpoint/{namespace}/{name}`
Auth: `Authorization: Bearer $TOKEN` — the token needs `write` role / `inference.endpoints.write` scope. **The `hf` CLI's own login token may not have this** — check with `hf auth whoami` (or `curl -H "Authorization: Bearer $TOKEN" https://huggingface.co/api/whoami-v2`) before assuming a write will succeed; a scope mismatch fails as HTTP 403 `{"error":"Forbidden...missing permissions: inference.endpoints.write"}`, not an auth error.
### Read current config
```bash
TOKEN=$(cat ~/.cache/huggingface/token)
curl -s -H "Authorization: Bearer $TOKEN" \
"https://api.endpoints.huggingface.cloud/v2/endpoint/$NAMESPACE/$NAME"
```
### Update config — MUST use PUT with a full body, not PATCH
`PATCH` returns **HTTP 405 Method Not Allowed** — this API does full-replace semantics only. Always `GET` the current config first, edit the fields you need, and `PUT` the whole thing back (a no-op PUT of the unchanged config is a safe way to verify write access).
```bash
curl -X PUT \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"compute": {
"accelerator": "gpu",
"instanceType": "nvidia-a10g",
"instanceSize": "x1",
"scaling": {
"minReplica": 0, "maxReplica": 1, "scaleToZeroTimeout": 15,
"metric": "hardwareUsage", "measure": {"hardwareUsage": 80.0}, "threshold": 80.0
}
},
"model": {
"repository": "unsloth/Qwen3.5-4B-MTP-GGUF",
"revision": "COMMIT_SHA",
"task": "image-text-to-text",
"framework": "llamacpp",
"image": {
"llamacpp": {
"healthRoute": "/health", "port": 80,
"url": "ghcr.io/ggml-org/llama.cpp:server-cuda",
"modelPath": "Model-Q8_0.gguf",
"ctxSize": 0, "nParallel": 10, "threadsHttp": 20, "nGpuLayers": 9999
}
},
"args": ["-ngl","99","-c","81920","-fa","on","-np","10"],
"env": {"SOME_VAR": "value"},
"secrets": {"SOME_SECRET": "value"}
}
}' \
"https://api.endpoints.huggingface.cloud/v2/endpoint/$NAMESPACE/$NAME"
```
Response includes `status.state` (`initializing` / `updating` / `running` / `paused`) and `status.message` (human-readable, e.g. "No replicas are ready yet", "Endpoint is ready"). Poll `describe`/`GET` after any write — updates restart the container (brief downtime + cold start).
### Health & inference endpoints (once running)
```bash
curl -H "Authorization: Bearer $TOKEN" "$ENDPOINT_URL/health" # {"status":"ok"}
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"model":"...", "messages":[...], "max_tokens":N}' \
"$ENDPOINT_URL/v1/chat/completions" # OpenAI-compatible
```
A `503 {"error":"503 Service Unavailable","code":"SERVICE_UNAVAILABLE"}` on every path (health, root, v1/models) with no path-specific difference means the HF gateway itself is responding, not a routing problem — almost always a cold start from scale-to-zero (`status.state: "initializing"`, `readyReplica: 0`) or mid-`updating`. Check `describe`/`GET` state before debugging further.
## Custom router (advanced, load-balancing across replicas)
Enable via a top-level `customRouter` object on create/update (API-only, no CLI/UI support as of this writing):
```json
"customRouter": {
"tag": "your-org/your-router-image:1.0.0",
"env": {},
"port": 3000
}
```
Reference implementation `queued-least-latency` exposes Prometheus metrics at `/_custom_router/metrics` (`custom_router_queue_depth`, `custom_router_backend_ewma_latency_seconds`, `custom_router_backend_inflight_requests`, etc). Useful when replicas have heterogeneous performance or traffic bursts faster than autoscaling reacts. Raise `CUSTOM_ROUTER_LATENCY_THRESHOLD` above default (3.0s) for LLM/batching workloads where concurrent-per-replica requests increase throughput; leave at default for diffusion/no-batching-benefit workloads.
## Autoscaling reference
- Scale-up check runs every ~1 minute; scale-down every ~2 minutes, with a 300s stabilization window after scaling down.
- `hardwareUsage` metric: scale up when avg utilization (CPU or GPU) over a 1-min window exceeds threshold (default 80%).
- `pendingRequests` metric: scale up when avg pending (in-flight + queued, no HTTP status yet) requests exceed 1.5/replica over 20s — a leading indicator vs. the lagging hardware metric.
- `min-replica 0` (scale-to-zero) requires explicit opt-in; default min is 1 (always-on).
- Add header `X-Scale-Up-Timeout: 600` on a client request to make the proxy hold (rather than 503) while a replica cold-starts, up to N seconds.