Quick Start
To run Molmo, first install dependencies:
pip install einops torchvision
Then, follow these steps:
from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfigfrom PIL import Imageimport requests # load the processorprocessor = AutoProcessor.from_pretrained( 'allenai/Molmo-7B-O-0924', trust_remote_code=True, torch_dtype='auto', device_map='auto') # load the modelmodel = AutoModelForCausalLM.from_pretrained( 'allenai/Molmo-7B-O-0924', trust_remote_code=True, torch_dtype='auto', device_map='auto') # process the image and textinputs = processor.process( images=[Image.open(requests.get("https://picsum.photos/id/237/536/354", stream=True).raw)], text="Describe this image.") # move inputs to the correct device and make a batch of size 1inputs = {k: v.to(model.device).unsqueeze(0) for k, v in inputs.items()} # generate output; maximum 200 new tokens; stop generation when <|endoftext|> is generatedoutput = model.generate_from_batch( inputs, GenerationConfig(max_new_tokens=200, stop_strings="<|endoftext|>"), tokenizer=processor.tokenizer) # only get generated tokens; decode them to textgenerated_tokens = output[0,inputs['input_ids'].size(1):]generated_text = processor.tokenizer.decode(generated_tokens, skip_special_tokens=True) # print the generated textprint(generated_text) # >>> This photograph captures an adorable black Labrador puppy sitting on a weathered# wooden deck. The deck's planks, which are a mix of light and dark brown with ...
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 evaluations 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 this can sometimes 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 | 81.2 | 1077 |
| Molmo 7B-D | 77.3 | 1056 |
| Molmo 7B-O (this model) | 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):
# Load the imageurl = "..."image = Image.open(requests.get(url, stream=True).raw) # Convert the image to grayscale to calculate brightnessgray_image = image.convert('L') # Convert to grayscale # Calculate the average brightnessstat = ImageStat.Stat(gray_image)average_brightness = stat.mean[0] # Get the average value # Define background color based on brightness (threshold can be adjusted)bg_color = (0, 0, 0) if average_brightness > 127 else (255, 255, 255) # Create a new image with the same size as the original, filled with the background colornew_image = Image.new('RGB', image.size, bg_color) # Paste the original image on top of the background (use image as a mask if needed)new_image.paste(image, (0, 0), image if image.mode == 'RGBA' else None) # Now you can pass the new_image to Molmoprocessor = 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.