llava-gemma-2b is a large multimodal model (LMM) trained using the
LLaVA-v1.5 framework with the 2-billion parameter
google/gemma-2b-it model as language backbone and the CLIP-based vision encoder.
This model card was created by
Benjamin Consolvo and the authors listed above.
Using
llava-gemma requires a
modified preprocessor if your transformers version is < 4.41.1
For current usage, see
usage.py or the following code block:
1import requests
2from PIL import Image
3from transformers import (
4 LlavaForConditionalGeneration,
5 AutoTokenizer,
6 AutoProcessor,
7 CLIPImageProcessor
8)
9#In this repo, needed for version < 4.41.1
10#from processing_llavagemma import LlavaGemmaProcessor
11#processor = LlavaGemmaProcessor( tokenizer=AutoTokenizer.from_pretrained(checkpoint), image_processor=CLIPImageProcessor.from_pretrained(checkpoint))
12
13checkpoint = "Intel/llava-gemma-2b"
14
15# Load model
16model = LlavaForConditionalGeneration.from_pretrained(checkpoint)
17processor = AutoProcessor.from_pretrained(checkpoint)
18
19# Prepare inputs
20# Use gemma chat template
21prompt = processor.tokenizer.apply_chat_template(
22 [{'role': 'user', 'content': "<image>\nWhat's the content of the image?"}],
23 tokenize=False,
24 add_generation_prompt=True
25)
26url = "https://www.ilankelman.org/stopsigns/australia.jpg"
27image = Image.open(requests.get(url, stream=True).raw)
28inputs = processor(text=prompt, images=image, return_tensors="pt")
29
30# Generate
31generate_ids = model.generate(**inputs, max_length=30)
32output = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
33print(output)
For straightforward use as a chatbot (without images), you can modify the last portion of code to the following:
1# Prepare inputs
2# Use gemma chat template
3prompt = processor.tokenizer.apply_chat_template(
4 [{'role': 'user', 'content': "Summarize the following paragraph? In this paper, we introduced LLaVA-Gemma, a compact vision-language model leveraging the Gemma Large Language Model in two variants, Gemma-2B and Gemma-7B. Our work provides a unique opportunity for researchers to explore the trade-offs between computational efficiency and multimodal understanding in small-scale models. The availability of both variants allows for a comparative analysis that sheds light on how model size impacts performance in various tasks. Our evaluations demonstrate the versatility and effectiveness of LLaVA-Gemma across a range of datasets, highlighting its potential as a benchmark for future research in small-scale vision-language models. With these models, future practitioners can optimize the performance of small-scale multimodal models more directly."}],
5 tokenize=False,
6 add_generation_prompt=True
7)
8# url = "https://www.ilankelman.org/stopsigns/australia.jpg"
9# image = Image.open(requests.get(url, stream=True).raw)
10inputs = processor(text=prompt, images=None, return_tensors="pt")
11
12# Generate
13generate_ids = model.generate(**inputs, max_length=300)
14output = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
15print(output)
The model was trained using the LLaVA-v1.5 data mixture. This is listed as follows:
Performance of LLaVA-Gemma models across seven benchmarks. Highlighted box indicates strongest performance amongst LLaVA-Gemma models. Bottom two rows show self-reported performance of Llava Phi-2 and LLaVA-v1.5 respectively. The bolded gemma-2b-it is the current model used here in this model card.
Intel is committed to respecting human rights and avoiding causing or contributing to adverse impacts on human rights. See
Intel’s Global Human Rights Principles. Intel’s products and software are intended only to be used in applications that do not cause or contribute to adverse impacts on human rights.
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
1@misc{hinck2024llavagemma,
2 title={LLaVA-Gemma: Accelerating Multimodal Foundation Models with a Compact Language Model},
3 author={Musashi Hinck and Matthew L. Olson and David Cobbley and Shao-Yen Tseng and Vasudev Lal},
4 year={2024},
5 eprint={2404.01331},
6 url={https://arxiv.org/abs/2404.01331},
7 archivePrefix={arXiv},
8 primaryClass={cs.CL}
9}