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
moving past keyvalue dynamically
Browse files- modeling_molmo2.py +15 -24
modeling_molmo2.py
CHANGED
|
@@ -1054,31 +1054,22 @@ class Molmo2TextModel(Molmo2PreTrainedModel):
|
|
| 1054 |
position_embeddings_i = position_embeddings
|
| 1055 |
|
| 1056 |
block_device = next(decoder_block.parameters()).device
|
| 1057 |
-
if hidden_states.device != block_device:
|
| 1058 |
-
hidden_states = hidden_states.to(block_device)
|
| 1059 |
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
-
|
| 1064 |
-
|
| 1065 |
-
|
| 1066 |
-
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
return tuple(
|
| 1076 |
-
tuple(p.to(device) for p in layer)
|
| 1077 |
-
for layer in past_key_values
|
| 1078 |
-
)
|
| 1079 |
-
|
| 1080 |
-
past_key_values = move_past_key_values(past_key_values, block_device)
|
| 1081 |
-
position_embeddings_i = position_embeddings_i.to(block_device)
|
| 1082 |
|
| 1083 |
layer_outputs = decoder_block(
|
| 1084 |
hidden_states,
|
|
|
|
| 1054 |
position_embeddings_i = position_embeddings
|
| 1055 |
|
| 1056 |
block_device = next(decoder_block.parameters()).device
|
|
|
|
|
|
|
| 1057 |
|
| 1058 |
+
def move_if_needed(x, device):
|
| 1059 |
+
if x is None:
|
| 1060 |
+
return x
|
| 1061 |
+
if isinstance(x, tuple):
|
| 1062 |
+
return tuple(move_if_needed(xx, device) for xx in x)
|
| 1063 |
+
if hasattr(x, "device") and x.device != device:
|
| 1064 |
+
return x.to(device)
|
| 1065 |
+
return x
|
| 1066 |
+
|
| 1067 |
+
hidden_states = move_if_needed(hidden_states, block_device)
|
| 1068 |
+
causal_mask_mapping = move_if_needed(causal_mask_mapping, block_device)
|
| 1069 |
+
position_ids = move_if_needed(position_ids, block_device)
|
| 1070 |
+
position_embeddings_i = move_if_needed(position_embeddings_i, block_device)
|
| 1071 |
+
cache_position = move_if_needed(cache_position, block_device)
|
| 1072 |
+
past_key_values = move_if_needed(past_key_values, block_device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1073 |
|
| 1074 |
layer_outputs = decoder_block(
|
| 1075 |
hidden_states,
|