Image-Text-to-Text
Transformers
Safetensors
English
qwen3_5
cybersecurity
cyber-safety
defensive-security
malware-analysis
incident-response
lora-merged
conversational
Instructions to use OpenModel-Labs/CSM-1-Preview with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenModel-Labs/CSM-1-Preview with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenModel-Labs/CSM-1-Preview") 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("OpenModel-Labs/CSM-1-Preview") model = AutoModelForMultimodalLM.from_pretrained("OpenModel-Labs/CSM-1-Preview", device_map="auto") 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?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use OpenModel-Labs/CSM-1-Preview with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenModel-Labs/CSM-1-Preview" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenModel-Labs/CSM-1-Preview", "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/OpenModel-Labs/CSM-1-Preview
- SGLang
How to use OpenModel-Labs/CSM-1-Preview 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 "OpenModel-Labs/CSM-1-Preview" \ --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": "OpenModel-Labs/CSM-1-Preview", "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 "OpenModel-Labs/CSM-1-Preview" \ --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": "OpenModel-Labs/CSM-1-Preview", "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 OpenModel-Labs/CSM-1-Preview with Docker Model Runner:
docker model run hf.co/OpenModel-Labs/CSM-1-Preview
Download example_chat.py from OpenModel-Labs/CSM-1-Preview: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/OpenModel-Labs/CSM-1-Preview/resolve/main/example_chat.py
- Command line
-
hf download hf://OpenModel-Labs/CSM-1-Preview/example_chat.py
-
curl -L -o example_chat.py https://huggingface.co/OpenModel-Labs/CSM-1-Preview/resolve/main/example_chat.py
1.62 kB
| # example_chat.py — minimal streaming chat with OpenModel-Labs/CSM-1-Preview | |
| # pip install -U torch transformers accelerate flash-linear-attention huggingface_hub | |
| import sys, threading, torch | |
| from huggingface_hub import hf_hub_download | |
| from transformers import AutoTokenizer, AutoModelForImageTextToText, TextIteratorStreamer | |
| REPO = "OpenModel-Labs/CSM-1-Preview" | |
| system = open(hf_hub_download(REPO, "system_prompt.txt"), encoding="utf-8").read() | |
| tok = AutoTokenizer.from_pretrained(REPO) | |
| model = AutoModelForImageTextToText.from_pretrained(REPO, dtype=torch.bfloat16, device_map="auto") | |
| model.eval() | |
| messages = [{"role": "system", "content": system}] | |
| print("Cyber Safety Model - type a question, Ctrl+C to quit.") | |
| while True: | |
| try: | |
| q = input("\nyou > ").strip() | |
| except (EOFError, KeyboardInterrupt): | |
| break | |
| if not q: | |
| continue | |
| messages.append({"role": "user", "content": q}) | |
| prompt = tok.apply_chat_template(messages, add_generation_prompt=True, tokenize=False, enable_thinking=False) | |
| inputs = tok(prompt, return_tensors="pt", add_special_tokens=False).to(model.device) | |
| streamer = TextIteratorStreamer(tok, skip_prompt=True, skip_special_tokens=True) | |
| kw = dict(**inputs, streamer=streamer, max_new_tokens=1024, do_sample=True, | |
| temperature=0.7, top_p=0.9, top_k=20) | |
| threading.Thread(target=lambda: model.generate(**kw), daemon=True).start() | |
| reply = "" | |
| for chunk in streamer: | |
| reply += chunk | |
| sys.stdout.write(chunk) | |
| sys.stdout.flush() | |
| messages.append({"role": "assistant", "content": reply.strip()}) | |
| print() | |