Instructions to use optimum-intel-internal-testing/tiny-random-molmo2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use optimum-intel-internal-testing/tiny-random-molmo2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="optimum-intel-internal-testing/tiny-random-molmo2", 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("optimum-intel-internal-testing/tiny-random-molmo2", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("optimum-intel-internal-testing/tiny-random-molmo2", trust_remote_code=True, 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 optimum-intel-internal-testing/tiny-random-molmo2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "optimum-intel-internal-testing/tiny-random-molmo2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "optimum-intel-internal-testing/tiny-random-molmo2", "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/optimum-intel-internal-testing/tiny-random-molmo2
- SGLang
How to use optimum-intel-internal-testing/tiny-random-molmo2 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 "optimum-intel-internal-testing/tiny-random-molmo2" \ --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": "optimum-intel-internal-testing/tiny-random-molmo2", "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 "optimum-intel-internal-testing/tiny-random-molmo2" \ --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": "optimum-intel-internal-testing/tiny-random-molmo2", "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 optimum-intel-internal-testing/tiny-random-molmo2 with Docker Model Runner:
docker model run hf.co/optimum-intel-internal-testing/tiny-random-molmo2
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("optimum-intel-internal-testing/tiny-random-molmo2", trust_remote_code=True)
model = AutoModelForMultimodalLM.from_pretrained("optimum-intel-internal-testing/tiny-random-molmo2", trust_remote_code=True, 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]:]))Quick Links
tiny-random-molmo2
A tiny Molmo2 (allenai/MolmoWeb-4B architecture) with random weights, used for the
OpenVINO GenAI VLMPipeline and genai-cli export tests. It produces meaningless text and is
meant only for testing.
- Text model: 3 layers, hidden size 128, 4 attention heads / 2 KV heads, head_dim 32, full Qwen vocabulary
- Vision (ViT): 3 layers, hidden size 64, 2 heads, head_dim 32; adapter uses the last two ViT layers
- 39.6M parameters, float32
- Tokenizer, processor configs, chat template and remote code (
*_molmo2.py) are copied unchanged fromallenai/MolmoWeb-4B
Molmo2 is remote code: load it with trust_remote_code=True and transformers>=4.57,<4.58
(einops and torchvision are also required).
Generation script
# uv run --with transformers==4.57.6 --with einops --with torchvision python make_tiny_molmo2.py <MolmoWeb-4B snapshot> <out>
import math
import shutil
import sys
from pathlib import Path
import torch
from transformers import AutoConfig, AutoModelForImageTextToText
src, out = Path(sys.argv[1]), Path(sys.argv[2])
torch.manual_seed(0)
cfg = AutoConfig.from_pretrained(src, trust_remote_code=True)
t, v, a = cfg.text_config, cfg.vit_config, cfg.adapter_config
t.hidden_size, t.num_attention_heads, t.num_key_value_heads, t.head_dim = 128, 4, 2, 32
t.num_hidden_layers, t.intermediate_size = 3, 256
v.hidden_size, v.intermediate_size, v.num_hidden_layers = 64, 128, 3
v.num_attention_heads = v.num_key_value_heads = 2
v.head_dim = 32
a.hidden_size, a.num_attention_heads, a.num_key_value_heads, a.head_dim = 64, 2, 2, 32
a.intermediate_size, a.text_hidden_size, a.vit_layers = 128, t.hidden_size, [-1, -2]
model = AutoModelForImageTextToText.from_config(cfg, trust_remote_code=True).float()
with torch.no_grad():
for name, p in model.named_parameters():
if name.endswith("norm.weight") or "ln_f" in name or "_norm" in name:
continue
if p.ndim == 2: # linear / embedding / positional embedding
std = 1.0 if ("wte" in name or "positional_embedding" in name) else 1.0 / math.sqrt(p.shape[1])
if name == "lm_head.weight":
std = 4.0 / math.sqrt(p.shape[1])
p.normal_(0.0, std)
elif name.endswith("bias"):
p.normal_(0.0, 0.02)
model.save_pretrained(out, safe_serialization=True)
for f in src.iterdir():
if f.is_file() and f.suffix != ".safetensors" and f.name not in ("config.json", "model.safetensors.index.json"):
shutil.copy(f, out / f.name)
- Downloads last month
- 22
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="optimum-intel-internal-testing/tiny-random-molmo2", 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)