Image-Text-to-Text
Transformers
Safetensors
English
qwen2
text-generation
conversational
text-generation-inference
Instructions to use TIGER-Lab/MAmmoTH-VL2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TIGER-Lab/MAmmoTH-VL2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="TIGER-Lab/MAmmoTH-VL2") 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 AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("TIGER-Lab/MAmmoTH-VL2") model = AutoModelForCausalLM.from_pretrained("TIGER-Lab/MAmmoTH-VL2", device_map="auto") 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?"} ] }, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use TIGER-Lab/MAmmoTH-VL2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TIGER-Lab/MAmmoTH-VL2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TIGER-Lab/MAmmoTH-VL2", "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/TIGER-Lab/MAmmoTH-VL2
- SGLang
How to use TIGER-Lab/MAmmoTH-VL2 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 "TIGER-Lab/MAmmoTH-VL2" \ --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": "TIGER-Lab/MAmmoTH-VL2", "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 "TIGER-Lab/MAmmoTH-VL2" \ --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": "TIGER-Lab/MAmmoTH-VL2", "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 TIGER-Lab/MAmmoTH-VL2 with Docker Model Runner:
docker model run hf.co/TIGER-Lab/MAmmoTH-VL2
Update README.md
Browse files
README.md
CHANGED
|
@@ -65,18 +65,9 @@ image_sizes = [[image.size[0], image.size[1]]]
|
|
| 65 |
prompt = "In the picture shown below, prove ΔWXY and ΔZWY are similar. Please conclude your answer as Answer: xxx at the end if possible."
|
| 66 |
|
| 67 |
# Set up conversation template
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
except KeyError:
|
| 72 |
-
available_templates = list(conv_templates.keys())
|
| 73 |
-
for template_name in available_templates:
|
| 74 |
-
if 'qwen' in template_name.lower():
|
| 75 |
-
conv_template = template_name
|
| 76 |
-
break
|
| 77 |
-
else:
|
| 78 |
-
conv_template = available_templates[0]
|
| 79 |
-
conv = copy.deepcopy(conv_templates[conv_template])
|
| 80 |
|
| 81 |
# Add question with image
|
| 82 |
question = DEFAULT_IMAGE_TOKEN + "\n" + prompt
|
|
|
|
| 65 |
prompt = "In the picture shown below, prove ΔWXY and ΔZWY are similar. Please conclude your answer as Answer: xxx at the end if possible."
|
| 66 |
|
| 67 |
# Set up conversation template
|
| 68 |
+
|
| 69 |
+
conv_template = "qwen_2_5"
|
| 70 |
+
conv = copy.deepcopy(conv_templates[conv_template])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Add question with image
|
| 73 |
question = DEFAULT_IMAGE_TOKEN + "\n" + prompt
|