tangyue0820 xuanli1 commited on
Commit
97ce140
·
1 Parent(s): 5b9b37b

Usage: switch reasnor examples to vLLM (#48)

Browse files

- Usage: switch reasnor examples to vLLM (aea74fb9d7576027b9d838b2603b42635746ad30)
- Update vLLM video media I/O arguments (25962f78f182c79014542ef449e07d00655ca266)


Co-authored-by: Xuan Li <xuanli1@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +64 -22
README.md CHANGED
@@ -735,9 +735,31 @@ Example outputs:
735
 
736
  <img width="1280" src="https://huggingface.co/nvidia/Cosmos3-Edge/resolve/main/assets/edge_action_id_av_1_output.png">
737
 
738
- ### Reasoning
739
 
740
- The reasoner generates text from a prompt and an optional image or video (`vision_path`); output is written to `reasoner_text.txt`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
741
 
742
  Image input:
743
 
@@ -749,29 +771,47 @@ User prompt:
749
  The task is to put flower into the red bottle. Generate a plan consisting of subtasks for accomplish the task.
750
  ```
751
 
752
- ```shell
753
- cat > reasoner_edge.json <<'JSON'
754
- {
755
- "model_mode": "reasoner",
756
- "prompt": "The task is to put flower into the red bottle. Generate a plan consisting of subtasks for accomplish the task.",
757
- "vision_path": "https://huggingface.co/nvidia/Cosmos3-Edge/resolve/main/assets/example_reasoning_input.png"
758
- }
759
- JSON
760
-
761
- python -m cosmos_framework.scripts.inference \
762
- --parallelism-preset=latency \
763
- -i reasoner_edge.json \
764
- -o outputs/reasoner_edge \
765
- --checkpoint-path Cosmos3-Edge \
766
- --seed 0
767
- ```
768
 
769
- The generated text is written to `outputs/reasoner_edge/<sample_name>/reasoner_text.txt`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
770
 
771
  Example output:
772
 
773
  ```text
774
- <think>
775
  Got it, let's try to figure out how to put the flower into the red bottle. First, I need to identify the objects: the flower is the green one with the red center, and the red bottle is the red container. So the steps would involve moving the flower to the red bottle.
776
 
777
  First, the robot arm needs to locate the flower. Then, grasp the flower. After grasping, lift it, then move it towards the red bottle. Then, position the flower over the red bottle's opening, and finally release it into the bottle. Wait, but maybe I need to check if the red bottle has an opening that can accept the flower. Assuming the red bottle is a container with an opening, so the steps would be: move to flower, grasp, lift, move to red bottle, position over opening, release. Let me make sure each step is clear.
@@ -789,9 +829,11 @@ To accomplish the task of putting the flower into the red bottle, the plan shoul
789
  Each step ensures the flower is picked up, transported, and placed into the red bottle in a controlled manner.
790
  ```
791
 
792
- Thinking is enabled by default. Disabling it requires setting the reasoner chat template's `enable_thinking=False`, which the offline CLI does not currently expose — use the online serving path (`chat_template_kwargs={"enable_thinking": False}`) for a no-think response.
793
 
794
- Guardrails are enabled by default (sourced from `nvidia/Cosmos-Guardrail1`); pass `--no-guardrails` to disable, or `--offload-guardrail-models` to keep them on CPU. For multi-GPU recipes, online Ray serving, and the full argument reference, see cosmos-framework `docs/inference.md`.
 
 
795
 
796
  ## Limitations
797
 
 
735
 
736
  <img width="1280" src="https://huggingface.co/nvidia/Cosmos3-Edge/resolve/main/assets/edge_action_id_av_1_output.png">
737
 
738
+ ### vLLM
739
 
740
+ #### Container
741
+
742
+ ```bash
743
+ docker pull vllm/vllm-openai:cosmos3
744
+ ```
745
+
746
+ #### General Invocation
747
+
748
+ You can use the `vllm` package to deploy the Cosmos3-Edge reasoner as an OpenAI-compatible API endpoint. The recommended vLLM serving configuration for `nvidia/Cosmos3-Edge` on a single GPU is:
749
+
750
+ ```bash
751
+ vllm serve nvidia/Cosmos3-Edge \
752
+ --host 0.0.0.0 \
753
+ --port 8000 \
754
+ --max-model-len 131072 \
755
+ --allowed-local-media-path / \
756
+ --mm-processor-kwargs '{"do_resize": true, "min_pixels": 4096, "max_pixels": 16777216}' \
757
+ --media-io-kwargs '{"video": {"num_frames": 256}}'
758
+ ```
759
+
760
+ #### Examples
761
+
762
+ ##### Reasoning
763
 
764
  Image input:
765
 
 
771
  The task is to put flower into the red bottle. Generate a plan consisting of subtasks for accomplish the task.
772
  ```
773
 
774
+ ```python
775
+ import base64
776
+ import json
777
+ from pathlib import Path
 
 
 
 
 
 
 
 
 
 
 
 
778
 
779
+ import openai
780
+
781
+ # 1. Read the image reasoning prompt
782
+ example = json.load(open("assets/example_reasoning_prompt.json"))
783
+ image_path = Path("assets/example_reasoning_input.png").resolve()
784
+ image_url = (
785
+ "data:image/png;base64," + base64.b64encode(image_path.read_bytes()).decode()
786
+ )
787
+
788
+ # 2. Query the OpenAI-compatible vLLM server
789
+ client = openai.OpenAI(
790
+ api_key="EMPTY",
791
+ base_url="http://localhost:8000/v1",
792
+ )
793
+
794
+ response = client.chat.completions.create(
795
+ model=client.models.list().data[0].id,
796
+ messages=[
797
+ {
798
+ "role": "user",
799
+ "content": [
800
+ {"type": "image_url", "image_url": {"url": image_url}},
801
+ {"type": "text", "text": example["prompt"]},
802
+ ],
803
+ },
804
+ ],
805
+ max_tokens=example["max_tokens"],
806
+ )
807
+
808
+ # 3. Print the default response (thinking is enabled)
809
+ print(response.choices[0].message.content)
810
+ ```
811
 
812
  Example output:
813
 
814
  ```text
 
815
  Got it, let's try to figure out how to put the flower into the red bottle. First, I need to identify the objects: the flower is the green one with the red center, and the red bottle is the red container. So the steps would involve moving the flower to the red bottle.
816
 
817
  First, the robot arm needs to locate the flower. Then, grasp the flower. After grasping, lift it, then move it towards the red bottle. Then, position the flower over the red bottle's opening, and finally release it into the bottle. Wait, but maybe I need to check if the red bottle has an opening that can accept the flower. Assuming the red bottle is a container with an opening, so the steps would be: move to flower, grasp, lift, move to red bottle, position over opening, release. Let me make sure each step is clear.
 
829
  Each step ensures the flower is picked up, transported, and placed into the red bottle in a controlled manner.
830
  ```
831
 
832
+ Thinking is enabled by default. To disable it, add the following argument to the `client.chat.completions.create(...)` call:
833
 
834
+ ```python
835
+ extra_body={"chat_template_kwargs": {"enable_thinking": False}}
836
+ ```
837
 
838
  ## Limitations
839