Model Card: Add SGLang Instruction

#7
Files changed (1) hide show
  1. README.md +85 -0
README.md CHANGED
@@ -105,6 +105,7 @@ Our AI models are designed and/or optimized to run on NVIDIA GPU-accelerated sys
105
 
106
  - [PyTorch](https://pytorch.org/)
107
  - [vLLM-Omni](https://github.com/vllm-project/vllm-omni)
 
108
 
109
  **Supported Hardware Microarchitecture Compatibility:**
110
 
@@ -401,6 +402,90 @@ With the supplied depth control, the generated output looks like this:
401
 
402
  <video src="https://huggingface.co/nvidia/Cosmos3-Nano-Sim-Transfer/resolve/main/assets/output/cosmos3-nano-sim-transfer-quickstart.mp4" controls autoplay loop muted playsinline width="640"></video>
403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  ## Ethical Considerations
405
 
406
  NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. Developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.
 
105
 
106
  - [PyTorch](https://pytorch.org/)
107
  - [vLLM-Omni](https://github.com/vllm-project/vllm-omni)
108
+ - [SGLang](https://github.com/sgl-project/sglang)
109
 
110
  **Supported Hardware Microarchitecture Compatibility:**
111
 
 
402
 
403
  <video src="https://huggingface.co/nvidia/Cosmos3-Nano-Sim-Transfer/resolve/main/assets/output/cosmos3-nano-sim-transfer-quickstart.mp4" controls autoplay loop muted playsinline width="640"></video>
404
 
405
+ ### Quick Start with SGLang
406
+
407
+ [SGLang](https://github.com/sgl-project/sglang) serves the same model through its OpenAI-compatible Videos API and generates the same depth-controlled video. Two things differ: the server reads the control video from a path it can open instead of accepting uploads, so the working directory is mounted into the container, and generation runs as an asynchronous job that the client polls. For edge, blur, and segmentation controls with SGLang, see the [SGLang notebook](https://github.com/NVIDIA/cosmos-framework/blob/main/.agents/skills/cookbooks/cosmos3/simulation/transfer/run_transfer_with_sglang.ipynb).
408
+
409
+ #### 1. Start the server
410
+
411
+ On the same kind of host, with the published [`lmsysorg/sglang:dev`](https://hub.docker.com/r/lmsysorg/sglang/tags) image, which includes the Cosmos3 pipelines from [sgl-project/sglang#39475](https://github.com/sgl-project/sglang/pull/39475):
412
+
413
+ ```bash
414
+ export SGLANG_HF_CACHE="${SGLANG_HF_CACHE:-$HOME/.cache/sglang-huggingface}" # The container runs as root.
415
+ mkdir -p "$SGLANG_HF_CACHE"
416
+ chmod 777 "$SGLANG_HF_CACHE"
417
+ docker pull lmsysorg/sglang:dev
418
+ docker run --init --runtime nvidia --gpus all --ipc=host \
419
+ -v "$SGLANG_HF_CACHE:/root/.cache/huggingface" \
420
+ -v "$PWD:$PWD:ro" \
421
+ --env "HF_TOKEN=$HF_TOKEN" \
422
+ -p 127.0.0.1:30000:30000 \
423
+ lmsysorg/sglang:dev \
424
+ sglang serve \
425
+ --model-path nvidia/Cosmos3-Nano-Sim-Transfer \
426
+ --host 0.0.0.0 --port 30000
427
+ ```
428
+
429
+ The container publishes the server on `127.0.0.1:30000` of the host and mounts the working directory, read-only, at the same path; the client below downloads the control video under that directory and names it by path. The `dev` tag moves with SGLang's main branch, so pull it before each start. The first start downloads the checkpoint; the HTTP port opens after the weights are loaded and the warmup request finishes. The distilled checkpoint fixes the step count and guidance, and the server reads its history window from the export's training configuration, so the request sets neither.
430
+
431
+ #### 2. Generate the depth video
432
+
433
+ Run this from the directory mounted above:
434
+
435
+ ```bash
436
+ pip install requests huggingface_hub
437
+ ```
438
+
439
+ ```python
440
+ import json
441
+ import time
442
+ from pathlib import Path
443
+
444
+ import requests
445
+ from huggingface_hub import snapshot_download
446
+
447
+ MODEL = "nvidia/Cosmos3-Nano-Sim-Transfer"
448
+ SERVER = "http://127.0.0.1:30000"
449
+ example_dir = Path(snapshot_download(
450
+ MODEL,
451
+ allow_patterns=[
452
+ "assets/sample_data/example1/example1_depth.mp4",
453
+ "assets/sample_data/example1/example1_upsampled_prompt.json",
454
+ ],
455
+ local_dir=Path("Cosmos3-Nano-Sim-Transfer").resolve(), # Inside the mounted working directory.
456
+ )) / "assets/sample_data/example1"
457
+ metadata = json.loads((example_dir / "example1_upsampled_prompt.json").read_text())
458
+
459
+ form = {
460
+ "model": MODEL,
461
+ "prompt": metadata["prompt"],
462
+ "size": "640x640",
463
+ "num_frames": "600", # Caps the control frames consumed; the server trims the clip to whole chunks.
464
+ "fps": "30",
465
+ "seed": str(metadata["seed"]),
466
+ "control_hint": "depth",
467
+ "control_path": str(example_dir / "example1_depth.mp4"), # Opened by the server; nothing is uploaded.
468
+ "extra_params": json.dumps({"emphasize_control_in_prompt": False}),
469
+ }
470
+ # Submit the job, poll it, and download the video. The form carries text fields only.
471
+ response = requests.post(f"{SERVER}/v1/videos", files=[(key, (None, value)) for key, value in form.items()], timeout=60)
472
+ response.raise_for_status()
473
+ job = response.json()
474
+ deadline = time.monotonic() + 7200
475
+ while job["status"] not in ("completed", "failed", "cancelled"):
476
+ if time.monotonic() > deadline:
477
+ raise TimeoutError(f"Job {job['id']} did not finish in time: {job}")
478
+ time.sleep(10)
479
+ job = requests.get(f"{SERVER}/v1/videos/{job['id']}", timeout=60).json()
480
+ if job["status"] != "completed":
481
+ raise RuntimeError(json.dumps(job, indent=2))
482
+ video = requests.get(f"{SERVER}/v1/videos/{job['id']}/content", timeout=600)
483
+ video.raise_for_status()
484
+ Path("robot_depth.mp4").write_bytes(video.content)
485
+ ```
486
+
487
+ The output follows the control clip, trimmed to the pipeline's whole latent chunks, so it can be a few frames shorter than the requested count.
488
+
489
  ## Ethical Considerations
490
 
491
  NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. Developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.