FastAPI neural machine translation service with Opus-MT, mBART50, and M2M100 support. CPU & GPU , mi
8.3K
Production-ready FastAPI service for neural machine translation with multiple model family support.
All variants are available in this single repository as different tags:
| Tag | Full Image Name | Size | Description | Use Case |
|---|---|---|---|---|
cpu (or latest) | scottgal/mostlylucid-nmt:cpu | ~2.5GB | CPU with source code | Production CPU deployments |
cpu-min | scottgal/mostlylucid-nmt:cpu-min | ~1.5GB | CPU minimal, no preloaded models | Volume-mapped cache, flexible |
gpu | scottgal/mostlylucid-nmt:gpu | ~5GB | GPU with CUDA 12.6 + source | Production GPU deployments |
gpu-min | scottgal/mostlylucid-nmt:gpu-min | ~4GB | GPU minimal, no preloaded models | GPU with volume-mapped cache |
Note: All images are built from the same source code, just with different configurations and base images.
# Pull specific tag (always latest)
docker pull scottgal/mostlylucid-nmt:cpu # or :latest
docker pull scottgal/mostlylucid-nmt:cpu-min
docker pull scottgal/mostlylucid-nmt:gpu
docker pull scottgal/mostlylucid-nmt:gpu-min
# Pull specific version (pinned)
docker pull scottgal/mostlylucid-nmt:cpu-20250108.143022
docker pull scottgal/mostlylucid-nmt:cpu-min-20250108.143022
# Or just run (auto-pulls if not present)
docker run scottgal/mostlylucid-nmt:gpu
Each image includes two types of tags:
cpu (alias: latest), cpu-min, gpu, gpu-min (always point to most recent build)YYYYMMDD.HHMMSS (e.g., cpu-20250108.143022)All images include OCI labels with version, build date, git commit, and variant information.
Switch between them using MODEL_FAMILY environment variable.
latest - CPU Production ImageBest for: Production CPU deployments with preloaded models
docker run -d -p 8000:8000 scottgal/mostlylucid-nmt
min - CPU Minimal ImageBest for: Volume-mapped cache, switching model families without rebuilding
docker run -d -p 8000:8000 \
-v ./model-cache:/models \
-e MODEL_CACHE_DIR=/models \
-e MODEL_FAMILY=opus-mt \
scottgal/mostlylucid-nmt:cpu-min
gpu - GPU Production ImageBest for: Production GPU deployments with FP16, 10x faster
docker run -d --gpus all -p 8000:8000 \
-e USE_GPU=true \
-e EASYNMT_MODEL_ARGS='{"torch_dtype":"fp16"}' \
scottgal/mostlylucid-nmt:gpu
gpu-min - GPU Minimal ImageBest for: GPU with volume-mapped cache for large multilingual models
docker run -d --gpus all -p 8000:8000 \
-v ./model-cache:/models \
-e USE_GPU=true \
-e MODEL_FAMILY=mbart50 \
-e MODEL_CACHE_DIR=/models \
-e EASYNMT_MODEL_ARGS='{"torch_dtype":"fp16"}' \
scottgal/mostlylucid-nmt:gpu-min
Both :cpu and :gpu images include a minimal set of preloaded Opus‑MT models inside the image under /app/models. You can still map a cache directory, and it works on top of the preloaded set:
# CPU prepack with external cache overlay
docker run -d -p 8000:8000 \
-v ./model-cache:/models \
-e MODEL_CACHE_DIR=/models \
scottgal/mostlylucid-nmt:cpu
Behavior:
/app/models (zero first‑request latency for those pairs)./models (your mapped volume), persisting across restarts.Minimal images (:cpu-min, :gpu-min) do not include preloaded models. Mapping a cache directory is optional; without it, models will be re-downloaded each run.
By default, prepack images preload EN<->(es,fr,de,it) for Opus‑MT at build time. This is driven by a Docker build arg:
ARG PRELOAD_LANGS="es,fr,de,it" — legacy convenience that expands to EN<->XX (two repos per language).ARG PRELOAD_PAIRS, since Opus‑MT models are per-direction.Examples:
# CPU prepack: preload exact pairs (uses smart English pivot when a direct pair is missing)
docker build -t scottgal/mostlylucid-nmt:cpu \
--build-arg PRELOAD_PAIRS="en->de,de->en,fr->en,en->it,ja->de" .
# GPU prepack with pairs
docker build -f Dockerfile.gpu -t scottgal/mostlylucid-nmt:gpu \
--build-arg PRELOAD_PAIRS="en->de,en->fr,fr->en" .
# Legacy: preload by language list (expands to EN<->XX per language)
docker build -t scottgal/mostlylucid-nmt:cpu \
--build-arg PRELOAD_LANGS="es,fr,de" .
Notes:
ja->de) is not available, the preloader will fetch ja->en and en->de instead, so the runtime can pivot via English.:cpu-min, :gpu-min) preload nothing by design.# Model family selection
MODEL_FAMILY=opus-mt # or mbart50, m2m100
# Auto-fallback (enabled by default)
AUTO_MODEL_FALLBACK=1
MODEL_FALLBACK_ORDER="opus-mt,mbart50,m2m100"
# Volume-mapped cache
MODEL_CACHE_DIR=/models
# GPU optimization
USE_GPU=true
EASYNMT_MODEL_ARGS='{"torch_dtype":"fp16"}'
# Preload models (optional)
PRELOAD_MODELS="en->de,de->en,fr->en"
POST /translate - Translate text (batch supported)GET /lang_pairs - List supported language pairsGET /discover/opus-mt - Discover available Opus-MT modelsGET /discover/mbart50 - List mBART50 language pairsGET /discover/m2m100 - List M2M100 language pairsGET /healthz - Health checkGET /readyz - Readiness checkGET /cache - Cache statuscurl -X POST http://localhost:8000/translate \
-H 'Content-Type: application/json' \
-d '{
"text": ["Hello world", "Machine translation is amazing"],
"target_lang": "de",
"source_lang": "en",
"beam_size": 1
}'
GPU:
EASYNMT_MODEL_ARGS='{"torch_dtype":"fp16"}'EASYNMT_BATCH_SIZE=64WEB_CONCURRENCY=1PRELOAD_MODELS="en->de,de->en"CPU:
EASYNMT_BATCH_SIZE=8MAX_WORKERS_BACKEND=4Full documentation: https://github.com/scottgal/mostlylucid-nmt/blob/main/README.md
MIT License - Free for personal and commercial use
Content type
Image
Digest
sha256:95f6b69a8…
Size
4 GB
Last updated
9 months ago
docker pull scottgal/mostlylucid-nmt