Add SGLang usage section to the Cosmos3-Edge model card

#53
by majchrow - opened
Files changed (1) hide show
  1. README.md +146 -1
README.md CHANGED
@@ -8,6 +8,10 @@ tags:
8
  - nvidia
9
  - cosmos
10
  - cosmos3
 
 
 
 
11
  ---
12
 
13
  # **Cosmos 3: Omnimodal World Models for Physical AI**
@@ -173,6 +177,7 @@ Our AI models are designed and/or optimized to run on NVIDIA GPU-accelerated sys
173
 
174
  - [vLLM-Omni](https://github.com/vllm-project/vllm-omni)
175
  - [vLLM](https://github.com/vllm-project/vllm)
 
176
  - [PyTorch](https://github.com/nvidia/cosmos3)
177
 
178
  **Supported Hardware Microarchitecture Compatibility:**
@@ -837,6 +842,146 @@ Thinking is enabled by default. To disable it, add the following argument to the
837
  extra_body={"chat_template_kwargs": {"enable_thinking": False}}
838
  ```
839
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
840
  ## Limitations
841
 
842
  Cosmos3 may produce imperfect outputs in challenging scenarios. Generation artifacts include temporal inconsistency, unstable camera or object motion, imprecise physical interactions, and action-state drift — especially in long-horizon or high-resolution outputs. Reasoning may also be incorrect: object states, causal relationships, spatial geometry, temporal ordering, agent intent, and future outcomes can be misinferred, and complex or long-context inputs may yield hallucinated entities, inconsistent interpretations, or implausible predictions. Because the model lacks an explicit physics simulator, 3D geometry, 4D space-time evolution, object permanence, contact dynamics, and physical laws are only approximated — producing artifacts such as disappearing or morphing objects, unrealistic collisions, and physically implausible motions. Quality further degrades in out-of-distribution environments, safety-critical edge cases, and domains underrepresented in training.
@@ -845,7 +990,7 @@ Cosmos3 outputs should not be treated as physically accurate simulation, reliabl
845
 
846
  ## Inference
847
 
848
- **Acceleration Engine:** [vLLM-Omni](https://github.com/vllm-project/vllm-omni), [vLLM](https://github.com/vllm-project/vllm), [PyTorch](https://pytorch.org/)
849
 
850
  **Test Hardware:** B200, H100, H20, RTX PRO 6000, DGX Station, DGX Spark, Jetson Thor, Jetson AGX Orin
851
 
 
8
  - nvidia
9
  - cosmos
10
  - cosmos3
11
+ - vllm
12
+ - vllm-omni
13
+ - sglang
14
+ - sglang-diffusion
15
  ---
16
 
17
  # **Cosmos 3: Omnimodal World Models for Physical AI**
 
177
 
178
  - [vLLM-Omni](https://github.com/vllm-project/vllm-omni)
179
  - [vLLM](https://github.com/vllm-project/vllm)
180
+ - [SGLang](https://github.com/sgl-project/sglang)
181
  - [PyTorch](https://github.com/nvidia/cosmos3)
182
 
183
  **Supported Hardware Microarchitecture Compatibility:**
 
842
  extra_body={"chat_template_kwargs": {"enable_thinking": False}}
843
  ```
844
 
845
+ ### SGLang
846
+
847
+ [SGLang Diffusion](https://docs.sglang.io/docs/sglang-diffusion/index) can serve `nvidia/Cosmos3-Edge` through OpenAI-compatible image and video generation endpoints. Install SGLang from the main branch with diffusion dependencies, then start a server:
848
+
849
+ ```bash
850
+ git clone --branch main https://github.com/sgl-project/sglang.git
851
+ cd sglang
852
+ pip install -e "python[diffusion]"
853
+ pip install "cosmos-guardrail==0.3.1"
854
+
855
+ sglang serve --model-path nvidia/Cosmos3-Edge
856
+ ```
857
+
858
+ Cosmos 3 support in SGLang Diffusion currently requires the SGLang main branch. Switch to a stable SGLang release once Cosmos 3 support is included there.
859
+
860
+ Cosmos3-Edge is a compact model that fits comfortably on a single GPU. Pass `--dit-cpu-offload false` to keep the transformer resident on device and avoid host transfers:
861
+
862
+ ```bash
863
+ sglang serve \
864
+ --model-path nvidia/Cosmos3-Edge \
865
+ --dit-cpu-offload false
866
+ ```
867
+
868
+ Additional GPUs shard the visual sequence with `--num-gpus N --ulysses-degree N`, or split the two classifier-free-guidance branches with `--enable-cfg-parallel`.
869
+
870
+ Supported SGLang endpoints:
871
+
872
+ | Mode | Endpoint | Notes |
873
+ | --- | --- | --- |
874
+ | Text to image | `POST /v1/images/generations` | Returns base64 image data by default |
875
+ | Text to video | `POST /v1/videos` | Creates an async job; poll `GET /v1/videos/{id}` and download `/content` |
876
+ | Image to video | `POST /v1/videos` | Upload the conditioning image with `input_reference` |
877
+
878
+ Cosmos3-Edge is trained at 256p and 480p. SGLang applies these per-mode defaults when the request leaves them unset; generating above the trained range degrades quality sharply.
879
+
880
+ | Mode | Default size | Guidance | Flow shift |
881
+ | --- | --- | --- | --- |
882
+ | Text to image | `640x640` | `7.0` | `3.0` |
883
+ | Text to video / image to video | `832x480` | `5.0` | `3.0` |
884
+
885
+ Supported sizes are `832x480`, `480x832`, `640x480`, `480x640`, `640x640`, `480x480`, `448x256`, `256x448`, and `256x256`.
886
+
887
+ Example image-to-video request, using the conditioning image and JSON-upsampled prompt from this repo's `assets/`:
888
+
889
+ ```python
890
+ import json
891
+ import mimetypes
892
+ import time
893
+ from pathlib import Path
894
+
895
+ import requests
896
+
897
+ base_url = "http://localhost:30000"
898
+
899
+ # 1. Read JSON-upsampled prompt and negative prompt
900
+ json_prompt = json.load(open("assets/example_i2v_prompt.json"))
901
+ negative_prompt = json.load(open("assets/negative_prompt.json"))
902
+
903
+ # 2. Submit the job; SGLang's video endpoint is asynchronous
904
+ image_path = Path("assets/example_i2v_input.jpg")
905
+ mime_type = mimetypes.guess_type(image_path)[0] or "image/png"
906
+ data = {
907
+ "prompt": json.dumps(json_prompt),
908
+ "negative_prompt": json.dumps(negative_prompt),
909
+ "size": "832x480",
910
+ "num_frames": "121",
911
+ "fps": "24",
912
+ "num_inference_steps": "50",
913
+ "guidance_scale": "5.0",
914
+ "flow_shift": "3.0",
915
+ "max_sequence_length": "4096",
916
+ "seed": "0",
917
+ "extra_params": json.dumps({"guardrails": True, "use_duration_template": False}),
918
+ }
919
+
920
+ with image_path.open("rb") as image_file:
921
+ files = {"input_reference": (image_path.name, image_file, mime_type)}
922
+ print("Sending request to server...")
923
+ response = requests.post(f"{base_url}/v1/videos", data=data, files=files)
924
+ response.raise_for_status()
925
+ job_id = response.json()["id"]
926
+
927
+ # 3. Poll until the job completes
928
+ while True:
929
+ status = requests.get(f"{base_url}/v1/videos/{job_id}").json()["status"]
930
+ if status == "completed":
931
+ break
932
+ if status == "failed":
933
+ raise RuntimeError(f"Generation failed for job {job_id}")
934
+ time.sleep(1)
935
+
936
+ # 4. Download the generated video
937
+ output_path = Path("/tmp/cosmos3_edge_i2v.mp4")
938
+ output_path.write_bytes(requests.get(f"{base_url}/v1/videos/{job_id}/content").content)
939
+ print(f"Saved video to {output_path}")
940
+ ```
941
+
942
+ Text-to-video needs no file upload, so post a JSON body instead of a multipart form:
943
+
944
+ ```python
945
+ body = {
946
+ "prompt": json.dumps(json_prompt),
947
+ "negative_prompt": json.dumps(negative_prompt),
948
+ "size": "832x480",
949
+ "num_frames": 121,
950
+ "fps": 24,
951
+ "num_inference_steps": 50,
952
+ "guidance_scale": 5.0,
953
+ "flow_shift": 3.0,
954
+ "max_sequence_length": 4096,
955
+ "seed": 0,
956
+ "extra_params": {"guardrails": True, "use_duration_template": False},
957
+ }
958
+ response = requests.post(f"{base_url}/v1/videos", json=body)
959
+ ```
960
+
961
+ Poll and download the result the same way. Text-to-image uses the synchronous `POST /v1/images/generations` endpoint, which takes a JSON body and returns base64 image data:
962
+
963
+ ```python
964
+ import base64
965
+
966
+ body = {
967
+ "prompt": json.dumps(json_prompt),
968
+ "negative_prompt": json.dumps(negative_prompt),
969
+ "size": "640x640",
970
+ "n": 1,
971
+ "seed": 0,
972
+ "max_sequence_length": 4096,
973
+ "extra_params": {"guardrails": True},
974
+ }
975
+ response = requests.post(f"{base_url}/v1/images/generations", json=body)
976
+ response.raise_for_status()
977
+ image_bytes = base64.b64decode(response.json()["data"][0]["b64_json"])
978
+ Path("/tmp/cosmos3_edge_t2i.png").write_bytes(image_bytes)
979
+ ```
980
+
981
+ SGLang accepts Cosmos 3 request options including `max_sequence_length`, `flow_shift`, `extra_params.guardrails`, `extra_params.use_duration_template`, and `extra_params.use_system_prompt`. The SGLang Diffusion endpoints cover image and video generation only, and this checkpoint ships without a sound head, so it does not generate audio.
982
+
983
+ For complete serving instructions and request examples, see the [Cosmos3 SGLang cookbook](https://docs.sglang.io/cookbook/diffusion/Cosmos/Cosmos3).
984
+
985
  ## Limitations
986
 
987
  Cosmos3 may produce imperfect outputs in challenging scenarios. Generation artifacts include temporal inconsistency, unstable camera or object motion, imprecise physical interactions, and action-state drift — especially in long-horizon or high-resolution outputs. Reasoning may also be incorrect: object states, causal relationships, spatial geometry, temporal ordering, agent intent, and future outcomes can be misinferred, and complex or long-context inputs may yield hallucinated entities, inconsistent interpretations, or implausible predictions. Because the model lacks an explicit physics simulator, 3D geometry, 4D space-time evolution, object permanence, contact dynamics, and physical laws are only approximated — producing artifacts such as disappearing or morphing objects, unrealistic collisions, and physically implausible motions. Quality further degrades in out-of-distribution environments, safety-critical edge cases, and domains underrepresented in training.
 
990
 
991
  ## Inference
992
 
993
+ **Acceleration Engine:** [vLLM-Omni](https://github.com/vllm-project/vllm-omni), [vLLM](https://github.com/vllm-project/vllm), [SGLang](https://github.com/sgl-project/sglang), [SGLang Diffusion](https://docs.sglang.io/docs/sglang-diffusion/index), [PyTorch](https://pytorch.org/)
994
 
995
  **Test Hardware:** B200, H100, H20, RTX PRO 6000, DGX Station, DGX Spark, Jetson Thor, Jetson AGX Orin
996