Instructions to use xlangai/OpenCUA-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use xlangai/OpenCUA-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="xlangai/OpenCUA-7B", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("xlangai/OpenCUA-7B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use xlangai/OpenCUA-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "xlangai/OpenCUA-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xlangai/OpenCUA-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/xlangai/OpenCUA-7B
- SGLang
How to use xlangai/OpenCUA-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "xlangai/OpenCUA-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xlangai/OpenCUA-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "xlangai/OpenCUA-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xlangai/OpenCUA-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use xlangai/OpenCUA-7B with Docker Model Runner:
docker model run hf.co/xlangai/OpenCUA-7B
Practicalities of fast inference (NOT OSWorld!)
Thanks lots of publicity on channels like youtube and twitter. But no examples of how to use!
Rather than use OSWorld (tried and very slow cumbersome) I made my own pipeline on ubuntu 20.04 running a second screen and VNC.
I worote a quick VNC client using asyncvnc. Much more efficient (no full VM overhead and no multiple servers on the VM!) and screen shots faster than real time in my rtx3090 setup. I customised the VNC client to pull the screenshots and run inference on them. I think ithsi is a better longterm solution than pyautogui.
Firstly the requirments file you refer to in the model card is not available. (unless you are referring to https://github.com/xlang-ai/OpenCUA/blob/main/model/requirement.txt)
I was able to run in python3.12, pytorch2.4(CUDA), transformers 4.49 so those requirments are not actually the minimal.
I foundin the grounding examples whatever I prompted I was still getting clicks (never text)
Im just in the process of implementing CoT
For speed increase has anyone tried BnB quantisation or half precision inference (havent looked at the detailed architecture to see if these are even possible yet)
Wow, this is very cool!
If you want to build an executable agent, you may follow OpenCUA's agent design in OSWorld (https://github.com/xlang-ai/OSWorld/blob/main/mm_agents/opencua_agent.py)
The system prompts in the repo follows our training data, so the model may output other kinds of actions.
Best,
Xinyuan