Quick Start
To run Molmo, first install dependencies:
pip install einops torchvision
Then, follow these steps:
from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig
from PIL import Image
import requests
import torch
processor = AutoProcessor.from_pretrained(
'allenai/Molmo-72B-0924',
trust_remote_code=True,
torch_dtype='auto',
device_map='auto'
)
model = AutoModelForCausalLM.from_pretrained(
'allenai/Molmo-72B-0924',
trust_remote_code=True,
torch_dtype='auto',
device_map='auto'
)
inputs = processor.process(
images=[Image.open(requests.get("https://picsum.photos/id/237/536/354", stream=True).raw)],
text="Describe this image."
)
inputs = {k: v.to(model.device).unsqueeze(0) for k, v in inputs.items()}
output = model.generate_from_batch(
inputs,
GenerationConfig(max_new_tokens=200, stop_strings="<|endoftext|>"),
tokenizer=processor.tokenizer
)
generated_tokens = output[0,inputs['input_ids'].size(1):]
generated_text = processor.tokenizer.decode(generated_tokens, skip_special_tokens=True)
print(generated_text)
To make inference more efficient, run with autocast:
with torch.autocast(device_type="cuda", enabled=True, dtype=torch.bfloat16):
output = model.generate_from_batch(
inputs,
GenerationConfig(max_new_tokens=200, stop_strings="<|endoftext|>"),
tokenizer=processor.tokenizer
)
We did most of our evaluation in this setting (autocast on, but float32 weights)
To even further reduce the memory requirements, the model can be run with bfloat16 weights:
model.to(dtype=torch.bfloat16)
inputs["images"] = inputs["images"].to(torch.bfloat16)
output = model.generate_from_batch(
inputs,
GenerationConfig(max_new_tokens=200, stop_strings="<|endoftext|>"),
tokenizer=processor.tokenizer
)
Note that we have observed that this can change the output of the model compared to running with float32 weights.
vLLM
Molmo is supported in vLLM, however please use version <=0.7.2 until a prepreprocessing bug is fixed.
Evaluations
Table with columns: Model, Average Score on 11 Academic Benchmarks, Human Preference Elo Rating| Model | Average Score on 11 Academic Benchmarks | Human Preference Elo Rating |
|---|
| Molmo 72B (this model) | 81.2 | 1077 |
| Molmo 7B-D | 77.3 | 1056 |
| Molmo 7B-O | 74.6 | 1051 |
| MolmoE 1B | 68.6 | 1032 |
| GPT-4o | 78.5 | 1079 |
| GPT-4V |
Benchmarks: AI2D test, ChartQA test, VQA v2.0 test, DocQA test, InfographicVQA test, TextVQA val, RealWorldQA, MMMU val, MathVista testmini, CountBenchQA, Flickr Count (we collected this new dataset that is significantly harder than CountBenchQA).
FAQs
I'm getting an error a broadcast error when processing images!
Your image might not be in RGB format. You can convert it using the following code snippet:
from PIL import Image
image = Image.open(...)
if image.mode != "RGB":
image = image.convert("RGB")
Molmo doesn't work great with transparent images!
We received reports that Molmo models might struggle with transparent images.
For the time being, we recommend adding a white or dark background to your images before passing them to the model. The code snippet below shows how to do this using the Python Imaging Library (PIL):
url = "..."
image = Image.open(requests.get(url, stream=True).raw)
gray_image = image.convert('L')
stat = ImageStat.Stat(gray_image)
average_brightness = stat.mean[0]
bg_color = (0, 0, 0) if average_brightness > 127 else (255, 255, 255)
new_image = Image.new('RGB', image.size, bg_color)
new_image.paste(image, (0, 0), image if image.mode == 'RGBA' else None)
processor = AutoProcessor.from_pretrained(
'allenai/Molmo-7B-D-0924',
trust_remote_code=True,
torch_dtype='auto',
device_map='auto'
)
License and Use
This model is licensed under Apache 2.0. It is intended for research and educational use.
For more information, please see our Responsible Use Guidelines.
The base model used is Qwen2-72B, whose license (the Tongyi Qianwen license) you can find here.