|
| 1 | +# DeepInfra Cosmos3 Dynamo videogen worker image. |
| 2 | +# |
| 3 | +# Overlay build: clones NVIDIA/cosmos-framework at a pinned ref, applies the |
| 4 | +# reviewed patches from ./patches, then follows upstream's own Dockerfile steps |
| 5 | +# (same base image, uv-managed env) and bakes in the DeepInfra worker. |
| 6 | +# There is no DeepInfra copy of the framework repo — this directory plus the |
| 7 | +# pin below is the complete, reviewable definition of the image. |
| 8 | +# |
| 9 | +# Build (from this directory; token file must hold an HF token whose account |
| 10 | +# has accepted the nvidia/Cosmos-Guardrail1 auto-gate — the secret mount keeps |
| 11 | +# it out of image layers and history): |
| 12 | +# docker build --secret id=hf_token,src=/path/to/token-file \ |
| 13 | +# -t localhost:30500/cosmos3-worker:v1 . |
| 14 | + |
| 15 | +ARG CUDA_VERSION=13.0.2 |
| 16 | +ARG BASE_IMAGE=nvidia/cuda:${CUDA_VERSION}-cudnn-devel-ubuntu24.04 |
| 17 | +FROM ${BASE_IMAGE} |
| 18 | + |
| 19 | +ENV DEBIAN_FRONTEND=noninteractive |
| 20 | + |
| 21 | +RUN --mount=type=cache,target=/var/cache/apt \ |
| 22 | + --mount=type=cache,target=/var/lib/apt \ |
| 23 | + apt-get update && \ |
| 24 | + apt-get install -y --no-install-recommends \ |
| 25 | + curl \ |
| 26 | + ffmpeg \ |
| 27 | + git \ |
| 28 | + git-lfs \ |
| 29 | + tree \ |
| 30 | + wget |
| 31 | + |
| 32 | +COPY --from=ghcr.io/astral-sh/uv:0.10.8 /uv /uvx /usr/local/bin/ |
| 33 | +ENV UV_LINK_MODE=copy |
| 34 | +ENV UV_PYTHON_CACHE_DIR=/root/.cache/uv/python |
| 35 | +ENV PATH="/root/.local/bin:$PATH" |
| 36 | + |
| 37 | +# Upstream pin. Bumping this ref is THE upstream-update mechanism; if a patch |
| 38 | +# in ./patches stops applying, the build fails loudly and the patch must be |
| 39 | +# rebased (or dropped because upstream absorbed the fix). |
| 40 | +ARG COSMOS_FRAMEWORK_REPO=https://github.com/NVIDIA/cosmos-framework.git |
| 41 | +ARG COSMOS_FRAMEWORK_REF=463ac142b47c637098a7e86d0631252f82b65418 |
| 42 | + |
| 43 | +WORKDIR /workspace |
| 44 | +RUN git clone --filter=blob:none ${COSMOS_FRAMEWORK_REPO} /workspace && \ |
| 45 | + git -C /workspace checkout ${COSMOS_FRAMEWORK_REF} |
| 46 | + |
| 47 | +# Upstream build steps (mirrors NVIDIA/cosmos-framework Dockerfile @ the pin, |
| 48 | +# minus bind-mounts: the sources are already in the layer from the clone). |
| 49 | +# NOTE: patches are applied LAST (near the entrypoint), not here. cosmos_framework |
| 50 | +# is installed editable (`uv pip install -e`), so patching /workspace afterward is |
| 51 | +# picked up live at runtime — and keeping the patch layer last means editing a |
| 52 | +# patch rebuilds in seconds instead of re-running the ~11GB gated HF prefetch. |
| 53 | +RUN --mount=type=cache,target=/root/.cache/uv uv python install |
| 54 | +RUN echo "$CUDA_VERSION" | sed -E 's/^([0-9]+)\.([0-9]+).*/cu\1\2/' > /root/.cuda-name |
| 55 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 56 | + uv sync --locked --no-install-project --no-editable --all-extras --group=$(cat /root/.cuda-name) |
| 57 | +ENV PATH="/workspace/.venv/bin:$PATH" |
| 58 | + |
| 59 | +# Triton bundled ptxas doesn't support latest GPU architectures |
| 60 | +ENV TRITON_PTXAS_PATH="/usr/local/cuda/bin/ptxas" |
| 61 | + |
| 62 | +# Serving deps. fastapi/uvicorn for standalone mode; ai-dynamo + uvloop for |
| 63 | +# production Dynamo mode. ai-dynamo provides the DistributedRuntime, frontend |
| 64 | +# binary, and endpoint registration used by the videogen worker pattern. |
| 65 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 66 | + uv pip install fastapi uvicorn ai-dynamo==1.1.1 uvloop |
| 67 | + |
| 68 | +# Pre-install the HF CLI tool so that `uvx hf@1.13.0` reuses this |
| 69 | +# installation instead of creating an ephemeral env missing `click`. |
| 70 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 71 | + uv tool install hf@1.13.0 --with click |
| 72 | + |
| 73 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 74 | + uv pip install --no-deps -e /workspace |
| 75 | + |
| 76 | +# Pre-fetch HuggingFace dependencies needed by cosmos_framework at model init |
| 77 | +# time: Qwen tokenizer configs (*.json, *.txt — few MB), Wan VAE checkpoints, |
| 78 | +# and the full Cosmos-Guardrail1 snapshot (the one gated repo — auto-approve |
| 79 | +# gate; the token account must have accepted it). The token comes in via a |
| 80 | +# BuildKit secret mount so it never persists in a layer or in image history. |
| 81 | +# This eliminates any runtime dependency on HuggingFace availability. |
| 82 | +# Revisions MUST match the pins in |
| 83 | +# cosmos_framework/inference/common/checkpoints.py and |
| 84 | +# cosmos_framework/auxiliary/guardrail/common/core.py at the ref above — the |
| 85 | +# runtime looks up these exact revisions; a mismatch silently falls back to a |
| 86 | +# live (unauthenticated, rate-limited) HF fetch at every pod boot. |
| 87 | +RUN --mount=type=secret,id=hf_token \ |
| 88 | + export HF_TOKEN=$(cat /run/secrets/hf_token 2>/dev/null || true) && \ |
| 89 | + uvx hf@1.13.0 download --format=json \ |
| 90 | + Qwen/Qwen3-0.6B \ |
| 91 | + --repo-type model \ |
| 92 | + --revision c1899de289a04d12100db370d81485cdf75e47ca \ |
| 93 | + --include '*.json' --include '*.txt' && \ |
| 94 | + uvx hf@1.13.0 download --format=json \ |
| 95 | + Qwen/Qwen3-VL-2B-Instruct \ |
| 96 | + --repo-type model \ |
| 97 | + --revision 89644892e4d85e24eaac8bacfd4f463576704203 \ |
| 98 | + --include '*.json' --include '*.txt' && \ |
| 99 | + uvx hf@1.13.0 download --format=json \ |
| 100 | + Qwen/Qwen3-VL-8B-Instruct \ |
| 101 | + --repo-type model \ |
| 102 | + --revision 0c351dd01ed87e9c1b53cbc748cba10e6187ff3b \ |
| 103 | + --include '*.json' --include '*.txt' && \ |
| 104 | + uvx hf@1.13.0 download --format=json \ |
| 105 | + Qwen/Qwen3-VL-32B-Instruct \ |
| 106 | + --repo-type model \ |
| 107 | + --revision 0cfaf48183f594c314753d30a4c4974bc75f3ccb \ |
| 108 | + --include '*.json' --include '*.txt' && \ |
| 109 | + uvx hf@1.13.0 download --format=json \ |
| 110 | + Wan-AI/Wan2.1-T2V-14B \ |
| 111 | + --repo-type model \ |
| 112 | + --revision a064a6c71f5be440641209c07bf2a5ce7a2ff5e4 \ |
| 113 | + Wan2.1_VAE.pth && \ |
| 114 | + uvx hf@1.13.0 download --format=json \ |
| 115 | + Wan-AI/Wan2.2-TI2V-5B \ |
| 116 | + --repo-type model \ |
| 117 | + --revision 921dbaf3f1674a56f47e83fb80a34bac8a8f203e \ |
| 118 | + Wan2.2_VAE.pth && \ |
| 119 | + uvx hf@1.13.0 download --format=json \ |
| 120 | + nvidia/Cosmos-Guardrail1 \ |
| 121 | + --repo-type model \ |
| 122 | + --revision d6d4bfa899a71454a700907664f3e88f503950cf |
| 123 | + |
| 124 | +# DeepInfra runtime settings. |
| 125 | +# - LD_LIBRARY_PATH is cleared so the venv/CUDA libs resolve without host leakage. |
| 126 | +# - torch.compile (inductor) and triton write kernel caches to a persistent |
| 127 | +# mountable location instead of an ephemeral home dir. |
| 128 | +ENV LD_LIBRARY_PATH="" |
| 129 | +ENV TORCHINDUCTOR_CACHE_DIR="/cache/torchinductor" |
| 130 | +ENV TRITON_CACHE_DIR="/cache/triton" |
| 131 | +RUN mkdir -p /cache/torchinductor /cache/triton |
| 132 | + |
| 133 | +# DeepInfra patches to upstream code (reviewed in deepinfra/dynamo). Applied |
| 134 | +# last so a patch edit doesn't invalidate the expensive prefetch layer above; |
| 135 | +# the editable install makes them live at runtime. Fails loudly if a patch no |
| 136 | +# longer applies against COSMOS_FRAMEWORK_REF (the signal to rebase or drop it). |
| 137 | +COPY patches /workspace/deepinfra-patches |
| 138 | +RUN git -C /workspace apply --verbose deepinfra-patches/*.patch |
| 139 | + |
| 140 | +# DeepInfra Dynamo videogen worker. Runtime args |
| 141 | +# (--served-model-name, --model, --num-gpus, ...) are appended to this command. |
| 142 | +# worker.py self-relaunches under torchrun when --num-gpus > 1. |
| 143 | +COPY worker.py /workspace/worker.py |
| 144 | +ENTRYPOINT ["python3", "worker.py"] |
0 commit comments