Image-Text-to-Text
Transformers
PyTorch
English
molmo
text-generation
multimodal
Mixture of Experts
olmo
olmoe
molmoe
custom_code
Instructions to use allenai/MolmoE-1B-0924 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use allenai/MolmoE-1B-0924 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="allenai/MolmoE-1B-0924", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("allenai/MolmoE-1B-0924", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use allenai/MolmoE-1B-0924 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "allenai/MolmoE-1B-0924" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "allenai/MolmoE-1B-0924", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/allenai/MolmoE-1B-0924
- SGLang
How to use allenai/MolmoE-1B-0924 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 "allenai/MolmoE-1B-0924" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "allenai/MolmoE-1B-0924", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "allenai/MolmoE-1B-0924" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "allenai/MolmoE-1B-0924", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use allenai/MolmoE-1B-0924 with Docker Model Runner:
docker model run hf.co/allenai/MolmoE-1B-0924
Multi-turn Chat History Management
#19
by Jaykumaran17 - opened
Hey Team,
I'm finding hard to properly integrate chat history as shown in the Molmo Chat WebPage.
Would be great if you could help me out with this, :>)
chat_history = []
while True:
print(f"{color_b}************ Enter Your Input Query: *****************{reset}")
input_query = input()
query_text = input_query + "\n"+ f"{chat_history}" if chat_history else input_query
print("######################")
if input_query == exit_trigger:
print(f"{color_r}**************************Exiting Molmo Chat!***************************{reset}")
break
inputs = processor.process(images=ip_img, text=query_text)
# Move inputs to the correct device and create a batch of size 1
inputs = {k: v.to(model.device).unsqueeze(0) for k, v in inputs.items()}
# Generate output; maximum 200 new tokens; stop generation when <|endoftext|> is generated
output = model.generate_from_batch(
inputs, GenerationConfig(max_new_tokens=500, stop_strings="<|endoftext|>"), tokenizer=processor.tokenizer
)
# Only get generated tokens; decode them to text
generated_tokens = output[0, inputs["input_ids"].size(1) :]
generated_text = processor.tokenizer.decode(generated_tokens, skip_special_tokens=True)
# Print the generated text
print(generated_text)
# format_chat = f"Previous Query: {query_text}\nYour Previous Response: {generated_text}"
format_chat = {
"Previous Query": input_query,
"Previous Model Response": generated_text
}
print("----------------------------------------------")
print(format_chat)
print("------------------------------------------------")
chat_history = save_history(chat_history, save_text = format_chat, remove_prev_str = False)
def save_history(chat_history, save_text: str = '', remove_prev_str: bool = False, remove_len: int = 1):
chat_history = [save_text]+chat_history
if remove_prev_str:
for _ in range(remove_len):
chat_history.pop(0)
return chat_history