Skip to main content

Configuration Reference

miLLM is configured entirely through environment variables (with .env file support, case-sensitive names). In Docker Compose these go in the api service's environment: block; in Kubernetes, in the deployment's env:.

Core

VariableDefaultDescription
DATABASE_URLpostgresql+asyncpg://postgres:postgres@localhost:5432/millmPostgreSQL DSN (async driver required)
MODEL_CACHE_DIR/app/model_cacheWhere downloaded model weights live
SAE_CACHE_DIR/app/sae_cacheWhere downloaded SAEs live
HF_TOKENServer-wide HuggingFace token for gated repos; per-request tokens in API calls take precedence and are never persisted
HOST / PORT0.0.0.0 / 8000Bind address and port
DEBUGfalseEnables debug behavior; never use in production
REDIS_URLOptional Redis for cache/real-time state
AUTO_LOAD_MODELModel ID or name to load automatically at startup — recommended for unattended deployments

HTTP & logging

VariableDefaultDescription
CORS_ORIGINS*Comma-separated allowed origins. Set explicitly (e.g. http://localhost:3000,https://webui.example.com) when browsers call the API cross-origin
LOG_LEVELINFODEBUG / INFO / WARNING / ERROR
LOG_FORMATconsoleconsole for humans, json for log pipelines

Concurrency & timeouts

VariableDefaultDescription
MAX_CONCURRENT_REQUESTS1Must stay 1. This is a correctness constraint, not a throughput knob: values above 1 race on steering apply/restore and on the shared sensing buffer. Leave it at 1
MAX_PENDING_REQUESTS10Queue depth beyond the concurrent slots; overflow returns 503 (QUEUE_FULL, backpressure)
MAX_DOWNLOAD_WORKERS2Parallel model/SAE downloads
MAX_LOAD_WORKERS1Parallel model loads (keep at 1)
GRACEFUL_UNLOAD_TIMEOUT30.0Seconds to wait for in-flight requests before unloading a model
DOWNLOAD_TIMEOUT3600.0Max seconds for a single download

Performance

VariableDefaultDescription
TORCH_COMPILE(auto)true/false/unset. Unset = auto: compile on CUDA for non-bitsandbytes models. Compilation speeds up decoding significantly; first request after model load (and after SAE attach/detach) pays a one-time recompile (~20 s). The SAE hook is fully honored under compilation — see Architecture
TORCH_COMPILE_MODEreduce-overheaddefault / reduce-overhead / max-autotune
KV_CACHE_MODEdynamicstatic enables compiled static KV cache (needs a C compiler for triton in the image)
SPECULATIVE_MODELHF model ID of a small draft model for speculative decoding. Works with steering: draft proposes, the steered main model verifies — output correctness preserved, acceptance rate lower
SPECULATIVE_NUM_TOKENS5Tokens the draft proposes per step

Continuous batching (opt-in)

High-throughput batched inference via HuggingFace ContinuousBatchingManager. Trade-offs in Architecture.

VariableDefaultDescription
ENABLE_CONTINUOUS_BATCHINGfalseStart CBM at model load
CBM_MAX_QUEUE_SIZE256Manager queue size
CBM_DEFAULT_TEMPERATURE0.7Fixed sampling temperature for batched requests; requests with a different value fall back to serial
CBM_DEFAULT_TOP_P0.95Fixed top-p, same fallback rule
CBM_DEFAULT_MAX_TOKENS512Default generation length
CBM_FORCE_SERIAL_MONITORINGfalseRoute monitored requests to the serial path for exact per-request activation attribution (trades throughput for fidelity)

Example configurations

.env — single-GPU research box
AUTO_LOAD_MODEL=gemma-2-2b
MAX_CONCURRENT_REQUESTS=1
CORS_ORIGINS=http://localhost:3000
LOG_FORMAT=console
.env — shared inference server
ENABLE_CONTINUOUS_BATCHING=true
CBM_FORCE_SERIAL_MONITORING=true
MAX_PENDING_REQUESTS=32
LOG_FORMAT=json
LOG_LEVEL=INFO