HUB
Sign inSign up

olkowa/pattern-tei-rerank-cpu

By olkowa

•Updated 6 days ago

Image
0

47

olkowa/pattern-tei-rerank-cpu repository overview

⁠pattern-tei-rerank-cpu

Offline CPU reranker sidecar for the pattern MCP servers — Hugging Face TEI (CPU, candle backend) with Alibaba-NLP/gte-reranker-modernbert-base⁠ (149M params, 8k context, English) baked into the image as safetensors. No downloads, no API keys at runtime. Same model repo as the -gpu lane.

┌────────────────────────────────────────────────────────────────┐
│  architecture-pattern-mcp / agent-pattern-mcp                  │
|  design-pattern-mcp / blockchain-pattern-mcp                   |
│        ───────── HTTP /rerank ─────────►                       │
│                                                                │
│      ┌───────────────────────────────┐                         │
│      │    pattern-tei-rerank-cpu     │ ◄── pattern-tei-infra   │
│      │  gte-reranker-modernbert-base │                         │
│      │        :8080 (TEI, CPU)       │                         │
│      └───────────────────────────────┘                         │
└────────────────────────────────────────────────────────────────┘

⁠Architecture

This image is the reranker only. It contains no MCP server, no embedder, and no LLM client. The MCP servers (olk/architecture-pattern-mcp⁠, olk/design-pattern-mcp⁠, olk/agent-pattern-mcp⁠, olk/blockchain-pattern-mcp⁠) reach it via the shared Docker network pattern-tei-shared at the DNS name pattern-tei-rerank (see the pattern-tei-infra stack⁠).

Runtime base is ghcr.io/huggingface/text-embeddings-inference:cpu-1.9, but the router binary is not stock: it is self-built from TEI v1.9.4 plus unmerged upstream PR #884⁠ with the CPU candle feature set candle,http (see Startup and --warmup-tokens⁠ below). Pinned invariants: --model-id /data/reranker-model --dtype float32 (candle backend; sequence-classification models take no --pooling flag).

No GPU machinery anywhere in this build: no nvcc, no CUDA_COMPUTE_CAP, no compute-cap match patch (that check is compiled in only with the cuda feature), no entrypoint bypass (the cpu base has no per-arch dispatcher — it execs the router directly), and no USE_FLASH_ATTENTION (no flash kernel is compiled and the CPU load path never consults it). Weights live at /data/reranker-model; never mount over /data (a named volume would hide later image updates).

⁠What you get

  • Model: Alibaba-NLP/gte-reranker-modernbert-base — English, 149M params, 8k context, Apache 2.0 (fp32 model.safetensors baked in, same repo as the -gpu lane)
  • Server: TEI router v1.9.4 + PR #884 on :8080 (candle/CPU, float32)
  • Endpoints: POST /rerank (raw TEI) · GET /health · GET /info
  • Fully offline: weights baked in at build time, runs with HF_HUB_OFFLINE=1
  • Image defaults: MAX_CONCURRENT_REQUESTS=64, MAX_BATCH_TOKENS=16384, MAX_CLIENT_BATCH_SIZE=48, AUTO_TRUNCATE=true, WARMUP_TOKENS=0, PROMETHEUS_PORT=0 (metrics not exposed)
  • Stack override: pattern-tei-infra runs it at MAX_BATCH_TOKENS=8192 (shared with the GPU lane — the overlay swaps images, not tunables; see Configuration⁠)
  • Image: linux/amd64, CPU-only (no CUDA base) · Runs: on amd64 Linux hosts; no GPU required

No config.json patching is needed: max_position_embeddings=8192 is at or below every MAX_BATCH_TOKENS this image runs with, so TEI accepts the model config without the warmup warning that affects larger-context models.

⁠CPU lane

The stack's CPU lane (docker-compose.cpu.yml overlay) swaps in the -cpu pair and drops the base file's CDI GPU reservation via deploy: !reset {} (Compose !reset tag — needs Compose v2.24+; without it the stack would not start on a GPU-less host). The overlay changes images, not tunables: every TEI_RERANK_* default below is identical on both lanes.

⁠Startup and --warmup-tokens

Why this image carries a custom router build instead of stock cpu-1.9:

  • Stock TEI cpu-1.9 has no --warmup-tokens / WARMUP_TOKENS flag. It always runs a synthetic warmup pass of min(max_input_length, max_batch_tokens) tokens before serving. Measured cost for this 149M model: ~78 s of an ~81 s cold start — warmup is the boot time.
  • The only workaround on stock TEI is lowering MAX_BATCH_TOKENS (upstream issue #819⁠), which caps throughput to buy back startup time.
  • Upstream PR #884⁠ (open/unmerged) adds --warmup-tokens / WARMUP_TOKENS. This image builds the router from TEI v1.9.4 + PR #884 (pinned SHA 5806bdc) and sets WARMUP_TOKENS=0 (skip the synthetic pass) by default, so the container is ready in seconds (weight load only).

Semantics of WARMUP_TOKENS (this image only — stock TEI ignores the variable):

ValueBehaviour
0 (default)Skip the synthetic warmup pass
N > 0Warm with N tokens instead of the full default
N > MAX_BATCH_TOKENSRejected at startup

⁠Configuration

All tunables are environment variables (clap fallbacks; CLI flags win). Image defaults are overridable per container, e.g. docker run -e WARMUP_TOKENS=512 …, or in the stack via the TEI_RERANK_* compose variables (compose overrides image ENV):

VariableImage defaultStack defaultNotes
WARMUP_TOKENS (TEI_RERANK_WARMUP_TOKENS)00Skip (0) / shrink (N) the warmup pass. Custom-build flag, see above
MAX_CONCURRENT_REQUESTS (TEI_RERANK_MAX_CONCURRENT_REQUESTS)6464Must be ≥ texts per rerank request. TEI consumes one queue slot per text
MAX_CLIENT_BATCH_SIZE (TEI_RERANK_MAX_CLIENT_BATCH_SIZE)4848Must be ≥ the MCP client's RERANKER_MAX_BATCH_SIZE (default 48). Binding invariant: max_batch_size ≤ min(MAX_CLIENT_BATCH_SIZE, MAX_CONCURRENT_REQUESTS)
MAX_BATCH_TOKENS (TEI_RERANK_MAX_BATCH_TOKENS)163848192Shared with the GPU lane (the overlay swaps images, not tunables). The 8192 exists as the GPU lane's CUDA OOM guard: the no-flash f32 cross-encoder needs ~3.2 GB transient attention per 8k-token pair; a 16384-token batch of two long pairs overflows an 11 GB card shared with the embedder (CUDA_ERROR_OUT_OF_MEMORY → consumer ERR_008)
AUTO_TRUNCATE (TEI_RERANK_AUTO_TRUNCATE)truetrueKeep on: requirement strings can exceed model input length
PORT (TEI_RERANK_PORT)80808080If changed, update RERANKER_BASE_URL on the MCP side and the stack healthcheck URL (hardcoded to http://127.0.0.1:8080/health in docker-compose.yml)
PROMETHEUS_PORT (TEI_RERANK_PROMETHEUS_PORT)00Disabled; /metrics never exposed
HOSTNAME (TEI_RERANK_HOSTNAME)0.0.0.00.0.0.0Informational: Docker injects its own HOSTNAME at runtime, which TEI rejects as non-IP and falls back to 0.0.0.0

The MCP consumer chunks its fused candidate pool into requests of RERANKER_MAX_BATCH_SIZE (default 48, config.json → RERANKER_MAX_BATCH_SIZE) against http://pattern-tei-rerank:8080, with keep_retrieval_score preserving the stage-1 fusion score alongside the cross-encoder logit.

⁠Prerequisites

  • Docker 24+ with compose plugin v2.24+ (docker compose version; v2.24+ for the !reset merge tag in the CPU overlay)
  • Disk: several GB free (weights + CPU base, no CUDA payload)
  • CPU-only: no GPU required; amd64 Linux host (images are single-arch — no arm64 manifest, emulation aside)

⁠Quick start

Part of the pattern-tei-infra⁠ stack (recommended — shared Docker network pattern-tei-shared, DNS name pattern-tei-rerank). The CPU lane adds the overlay file (-f docker-compose.cpu.yml, or make docker-up-cpu):

git clone https://github.com/olk/pattern-tei-infra.git && cd pattern-tei-infra
# Registry deploy: pin BOTH CPU images in .env so up/pull reuse them
# (defaults are local build names, not pullable refs).
# systemd ignores the repo .env — install the same lines plus
# COMPOSE_FILE=docker-compose.yml:docker-compose.cpu.yml in
# /etc/pattern-tei-infra/.env (the unit's WorkingDirectory), or a
# post-reboot start falls back to the unpullable local names.
printf '%s\n' \
  'TEI_IMAGE_CPU=olkowa/pattern-tei-embed-cpu:1.2.0' \
  'TEI_RERANK_IMAGE_CPU=olkowa/pattern-tei-rerank-cpu:1.2.0' > .env
docker compose -f docker-compose.yml -f docker-compose.cpu.yml up -d
# ... or build locally first: make docker-build-tei-cpu && <same up command>

Or standalone (no MCP consumer):

docker run -d --name pattern-tei-rerank -p 8080:8080 \
  olkowa/pattern-tei-rerank-cpu:1.2.0
curl -fsS http://localhost:8080/health

Mirrored on GHCR at ghcr.io/olk/pattern-tei-rerank-cpu. The lane is part of the image name, never the tag (:1.2.0 / :latest exist per lane). GPU counterpart: olkowa/pattern-tei-rerank-gpu (same model repo).

Nothing to configure — no env vars, no model download, no HF token. Cold start is seconds (WARMUP_TOKENS=0); expect ~80 s only if you explicitly set a large WARMUP_TOKENS.

⁠Operations

# Update (registry deploy — requires TEI_IMAGE_CPU + TEI_RERANK_IMAGE_CPU in .env,
# or in /etc/pattern-tei-infra/.env under systemd; otherwise compose tries
# to pull the local build names)
docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml pull

# Logs
docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml logs -f pattern-tei-rerank

# Health
docker inspect --format '{{.State.Health.Status}}' pattern-tei-rerank

# Re-enable a warmup pass (e.g. to smooth first-request latency)
TEI_RERANK_WARMUP_TOKENS=512 docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml up -d pattern-tei-rerank

# Restore the image batch default (the stack's 8192 is the GPU lane's CUDA OOM
# guard; the CPU overlay swaps images, not tunables)
TEI_RERANK_MAX_BATCH_TOKENS=16384 docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml up -d pattern-tei-rerank

# Pin a version (both images — the stack always runs the pair)
TEI_IMAGE_CPU=olkowa/pattern-tei-embed-cpu:1.2.0 \
TEI_RERANK_IMAGE_CPU=olkowa/pattern-tei-rerank-cpu:1.2.0 \
  docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml up -d

Healthcheck: GET /health, 60 s start_period. No /data mounts — weights are baked in; drop stale named volumes from older deploys (docker volume rm pattern-tei-infra_tei-rerank-data).

Tag summary
Recent tags
Content type
Image
Digest
sha256:df4a7b0d8…
Size
612.2 MB
Last updated
6 days ago
docker pull olkowa/pattern-tei-rerank-cpu:latest