-
Notifications
You must be signed in to change notification settings - Fork 760
Add NIM inference path for the Cosmos 3 Generator #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
5a53966
58828a1
df58ea4
f0a18ef
c07a2e3
b60617e
b9dd3af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,16 +11,17 @@ backend you want to run and follow that one section. | |
| | [Transformers](#transformers) | Hugging Face Transformers inference | Reasoner | | ||
| | [vLLM](#vllm) | OpenAI-compatible reasoning server (image/video understanding) | Reasoner | | ||
| | [vLLM-Omni](#vllm-omni) | OpenAI-compatible generation server (image/video/audio/action) | Generator (Audiovisual, Action) | | ||
| | [NIM](#nim) | Prebuilt OpenAI-compatible reasoning server (image/video understanding); no venv | Reasoner | | ||
| | [NIM](#nim) | Prebuilt NGC containers; Reasoner serving plus Generator audiovisual T2V/I2V only | Reasoner, Generator (Audiovisual) | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the same naming conventions as above (image/video/audio). Since this reflects two separate NIMs for now, use (video to text reasoning) for reasoner. |
||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Linux with NVIDIA GPU access. | ||
| - [`uv`](https://docs.astral.sh/uv/getting-started/installation/), `git`, and `git-lfs` installed. | ||
| - Hugging Face access to the gated Cosmos3 model repos. Generator also requires | ||
| access to the gated | ||
| - Hugging Face access to the gated Cosmos3 model repos for Hugging Face based | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. be more explicit, or state all supported backends except NIM. Make sure to remember SGLang and TRT-LLM if making access claims. |
||
| backends. Generator also requires access to the gated | ||
| [nvidia/Cosmos-1.0-Guardrail](https://huggingface.co/nvidia/Cosmos-1.0-Guardrail) | ||
| HF repository. Authenticate once before the first run: | ||
| HF repository for Diffusers, vLLM-Omni, and Cosmos Framework examples. | ||
| Authenticate once before the first run: | ||
|
|
||
| ```bash | ||
| uvx hf@latest auth login | ||
|
|
@@ -32,7 +33,7 @@ backend you want to run and follow that one section. | |
| (vLLM-Omni `extra_params`/`extra_args`), or | ||
| `--no-guardrails` (Cosmos Framework). | ||
| - For the Cosmos Framework backend: access to `git@github.com:NVIDIA/cosmos-framework.git`. | ||
| - For the NIM backend: an NGC API key (used as `NGC_API_KEY`), which you can generate on [build.nvidia.com](https://build.nvidia.com/nvidia/cosmos3-nano-reasoner) or [NGC](https://catalog.ngc.nvidia.com/orgs/nim/teams/nvidia/containers/cosmos3-reasoner), plus a one-time `docker login nvcr.io` (username `$oauthtoken`, password = your key). The HF login above is not needed for NIM. | ||
| - For the NIM backend: an NGC API key (used as `NGC_API_KEY`), which you can generate on [build.nvidia.com](https://build.nvidia.com/) or [NGC](https://catalog.ngc.nvidia.com/), plus a one-time `docker login nvcr.io` (username `$oauthtoken`, password = your key). The HF login above is not needed for NIM. This repository uses the Reasoner NIM image `nvcr.io/nim/nvidia/cosmos3-reasoner` and the Generator NIM image `nvcr.io/nim/nvidia/cosmos3-generator`. | ||
| - Enough local disk for the venv/image, the uv cache, and the model cache. Nano | ||
| downloads plus CUDA dependencies can take tens of GiB. | ||
|
|
||
|
|
@@ -388,14 +389,28 @@ Ensure the server has enough GPUs for the product of enabled degrees | |
|
|
||
| ## NIM | ||
|
|
||
| Prebuilt NGC containers for Cosmos3. Like vLLM-Omni, NIM runs from Docker, so | ||
| there is no venv or `--torch-backend` to manage. Unlike the Hugging Face based | ||
| backends, NIM authenticates with an NGC API key instead of a Hugging Face token | ||
| (see [Prerequisites](#prerequisites)). | ||
|
|
||
| Authenticate Docker to NGC once: | ||
|
|
||
| ```bash | ||
| export NGC_API_KEY=<your_key> | ||
| echo "$NGC_API_KEY" | docker login nvcr.io --username '$oauthtoken' --password-stdin | ||
| ``` | ||
|
|
||
| Both NIMs expose readiness at `GET /v1/health/ready` after model download, | ||
| engine initialization, and warmup complete. | ||
|
|
||
| ### Reasoner NIM | ||
|
|
||
| A prebuilt container that serves the Reasoner over an OpenAI-compatible API for | ||
| image and video understanding. Like vLLM-Omni this is a Docker image, so there is | ||
| no venv or `--torch-backend` to manage; unlike the other backends it | ||
| authenticates with an NGC API key instead of Hugging Face (see | ||
| [Prerequisites](#prerequisites)). | ||
| image and video understanding. | ||
|
|
||
| Start a Nano server (publishes the OpenAI-compatible API on port 8000; the first | ||
| run downloads the model into `~/.cache/nim`): | ||
| Start a Nano Reasoner server (publishes the API on port 8000; the first run | ||
| downloads the model into `~/.cache/nim`): | ||
|
|
||
| ```bash | ||
| export NGC_API_KEY=<your_key> | ||
|
|
@@ -415,6 +430,62 @@ The container serves `nvidia/cosmos3-nano-reasoner` (or | |
| `nvidia/cosmos3-super-reasoner`); pass that exact name as the request `model`, or | ||
| resolve it dynamically with `client.models.list()`. | ||
|
|
||
| ### Generator NIM | ||
|
|
||
| A prebuilt container that serves **Cosmos3-Generator Text2Video and Image2Video | ||
| only** through `POST /v1/infer`. The NIM infers mode from the request fields: | ||
| non-empty `prompt` with no `image` means T2V; `image` provided means I2V. The | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicit - Text-to-video, image-to-video |
||
| response is JSON with a base64-encoded MP4 in `b64_video`. | ||
|
|
||
| It does **not** expose text-to-image, video-to-video, sound/audio generation, | ||
| action modes, or transfer controls. Use vLLM-Omni or Cosmos Framework for those | ||
| broader Generator workflows. | ||
|
|
||
| Start a Nano Generator server (default `NIM_MODEL_SIZE=nano`, `NIM_PRECISION=fp8`, | ||
| `NIM_PERF_PROFILE=latency`): | ||
|
|
||
| ```bash | ||
| export NGC_API_KEY=<your_key> | ||
| export LOCAL_NIM_CACHE="${LOCAL_NIM_CACHE:-$HOME/.cache/nim}" | ||
| mkdir -p "$LOCAL_NIM_CACHE" | ||
| chmod -R 777 "$LOCAL_NIM_CACHE" 2>/dev/null || true | ||
|
|
||
| docker run --runtime=nvidia --gpus all \ | ||
| --shm-size=32GB \ | ||
| --ulimit nofile=65536:65536 \ | ||
| -e NGC_API_KEY="$NGC_API_KEY" \ | ||
| -v "$LOCAL_NIM_CACHE:/opt/nim/.cache" \ | ||
| -p 8000:8000 \ | ||
| nvcr.io/nim/nvidia/cosmos3-generator:1.0.0 | ||
| ``` | ||
|
|
||
| For **Cosmos3-Super Generator**, add `-e NIM_MODEL_SIZE=super`. Other selection | ||
| knobs: | ||
|
|
||
| | Env var | Values | Default | Use | | ||
| | --- | --- | --- | --- | | ||
| | `NIM_MODEL_SIZE` | `nano`, `super` | `nano` | Selects 8B Nano or 32B Super | | ||
| | `NIM_PRECISION` | `bf16`, `fp8`, `nvfp4` | `fp8` | Selects precision; `nvfp4` requires Blackwell | | ||
| | `NIM_PERF_PROFILE` | `latency`, `throughput` | `latency` | Optimizes profile selection objective | | ||
| | `NIM_TAGS_SELECTOR` | comma-separated `key=value` filters | unset | Advanced profile pinning, e.g. `model_size=super,nim_tp=2` | | ||
|
|
||
| A quick T2V smoke test: | ||
|
|
||
| ```bash | ||
| curl -sS -X POST http://127.0.0.1:8000/v1/infer \ | ||
| -H 'Accept: application/json' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{ | ||
| "prompt": "A humanoid robot walks through a futuristic warehouse, inspecting shelves of mechanical components.", | ||
| "seed": 42, | ||
| "guidance_scale": 6.0, | ||
| "steps": 35, | ||
| "resolution": "256", | ||
| "num_output_frames": 25, | ||
| "fps": 24.0 | ||
| }' | jq -r '.b64_video' | base64 -d > /tmp/cosmos3_generator_nim_t2v.mp4 | ||
| ``` | ||
|
|
||
| ## Verify the environment | ||
|
|
||
| For the Cosmos Framework / Diffusers / vLLM venvs, check that PyTorch sees the GPU: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly, "text to video" and "image to video". This is a different readme file and the first time the acronym is presented.