Image-Text-to-Text
Transformers
Safetensors
English
molmo2
multimodal
olmo
molmo
conversational
custom_code
Instructions to use sunjuice/Molmo2-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sunjuice/Molmo2-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="sunjuice/Molmo2-8B", 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)# Load model directly from transformers import AutoModelForImageTextToText model = AutoModelForImageTextToText.from_pretrained("sunjuice/Molmo2-8B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sunjuice/Molmo2-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sunjuice/Molmo2-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sunjuice/Molmo2-8B", "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/sunjuice/Molmo2-8B
- SGLang
How to use sunjuice/Molmo2-8B 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 "sunjuice/Molmo2-8B" \ --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": "sunjuice/Molmo2-8B", "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 "sunjuice/Molmo2-8B" \ --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": "sunjuice/Molmo2-8B", "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 sunjuice/Molmo2-8B with Docker Model Runner:
docker model run hf.co/sunjuice/Molmo2-8B
project complete
Browse files- modeling_molmo2.py +13 -1
modeling_molmo2.py
CHANGED
|
@@ -758,7 +758,7 @@ class Molmo2DecoderLayer(GradientCheckpointingLayer):
|
|
| 758 |
):
|
| 759 |
super().__init__()
|
| 760 |
self.config = config
|
| 761 |
-
|
| 762 |
self.self_attn = Molmo2Attention(config, layer_idx)
|
| 763 |
self.attn_norm = Molmo2RMSNorm(
|
| 764 |
config.hidden_size, eps=config.layer_norm_eps, device=device)
|
|
@@ -782,6 +782,7 @@ class Molmo2DecoderLayer(GradientCheckpointingLayer):
|
|
| 782 |
) -> tuple[torch.FloatTensor, Optional[tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 783 |
|
| 784 |
residual = hidden_states
|
|
|
|
| 785 |
hidden_states = self.attn_norm(hidden_states)
|
| 786 |
|
| 787 |
# Self Attention
|
|
@@ -797,12 +798,23 @@ class Molmo2DecoderLayer(GradientCheckpointingLayer):
|
|
| 797 |
**kwargs,
|
| 798 |
)
|
| 799 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 800 |
hidden_states = residual + self.dropout(hidden_states)
|
| 801 |
|
| 802 |
# Fully Connected
|
| 803 |
residual = hidden_states
|
| 804 |
hidden_states = self.ff_norm(hidden_states)
|
| 805 |
hidden_states = self.mlp(hidden_states)
|
|
|
|
| 806 |
|
| 807 |
hidden_states = residual + self.dropout(hidden_states)
|
| 808 |
|
|
|
|
| 758 |
):
|
| 759 |
super().__init__()
|
| 760 |
self.config = config
|
| 761 |
+
self.device = device
|
| 762 |
self.self_attn = Molmo2Attention(config, layer_idx)
|
| 763 |
self.attn_norm = Molmo2RMSNorm(
|
| 764 |
config.hidden_size, eps=config.layer_norm_eps, device=device)
|
|
|
|
| 782 |
) -> tuple[torch.FloatTensor, Optional[tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 783 |
|
| 784 |
residual = hidden_states
|
| 785 |
+
block_device = self.device
|
| 786 |
hidden_states = self.attn_norm(hidden_states)
|
| 787 |
|
| 788 |
# Self Attention
|
|
|
|
| 798 |
**kwargs,
|
| 799 |
)
|
| 800 |
|
| 801 |
+
def move_if_needed(x, device):
|
| 802 |
+
if x is None:
|
| 803 |
+
return x
|
| 804 |
+
if isinstance(x, tuple):
|
| 805 |
+
return tuple(move_if_needed(xx, device) for xx in x)
|
| 806 |
+
if hasattr(x, "device") and x.device != device:
|
| 807 |
+
return x.to(device)
|
| 808 |
+
return x
|
| 809 |
+
|
| 810 |
+
residual = move_if_needed(residual, block_device)
|
| 811 |
hidden_states = residual + self.dropout(hidden_states)
|
| 812 |
|
| 813 |
# Fully Connected
|
| 814 |
residual = hidden_states
|
| 815 |
hidden_states = self.ff_norm(hidden_states)
|
| 816 |
hidden_states = self.mlp(hidden_states)
|
| 817 |
+
residual = move_if_needed(residual, block_device)
|
| 818 |
|
| 819 |
hidden_states = residual + self.dropout(hidden_states)
|
| 820 |
|