Views
No views yet
pip install --upgrade transformers.1import requests
2import torch
3from PIL import Image
4from transformers import MllamaForConditionalGeneration, AutoProcessor
5
6model_id = "AdaptLLM/biomed-Llama-3.2-11B-Vision-Instruct"
7
8model = MllamaForConditionalGeneration.from_pretrained(
9 model_id,
10 torch_dtype=torch.bfloat16,
11 device_map="auto",
12)
13processor = AutoProcessor.from_pretrained(model_id)
14
15url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"
16image = Image.open(requests.get(url, stream=True).raw)
17
18# NOTE: For AdaMLLM, always place the image at the beginning of the input instruction in the messages.
19messages = [
20 {"role": "user", "content": [
21 {"type": "image"},
22 {"type": "text", "text": "If I had to write a haiku for this one, it would be: "}
23 ]}
24]
25input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
26inputs = processor(
27 image,
28 input_text,
29 add_special_tokens=False,
30 return_tensors="pt"
31).to(model.device)
32
33output = model.generate(**inputs, max_new_tokens=30)
34print(processor.decode(output[0]))1@article{adamllm,
2 title={On Domain-Adaptive Post-Training for Multimodal Large Language Models},
3 author={Cheng, Daixuan and Huang, Shaohan and Zhu, Ziyu and Zhang, Xintong and Zhao, Wayne Xin and Luan, Zhongzhi and Dai, Bo and Zhang, Zhenliang},
4 journal={arXiv preprint arXiv:2411.19930},
5 year={2024}
6}1@inproceedings{
2cheng2024adapting,
3title={Adapting Large Language Models via Reading Comprehension},
4author={Daixuan Cheng and Shaohan Huang and Furu Wei},
5booktitle={The Twelfth International Conference on Learning Representations},
6year={2024},
7url={https://openreview.net/forum?id=y886UXPEZ0}
8}