Views
No views yet
XGen-MM is a series of the latest foundational Large Multimodal Models (LMMs) developed by Salesforce AI Research. This series advances upon the successful designs of the BLIP series, incorporating fundamental enhancements that ensure a more robust and superior foundation. xgen-mm-phi3-mini-base-r-v1, achieves state-of-the-art performance under 5b parameters and demonstrates strong in-context learning capabilities.xgen-mm-phi3-mini-instruct-r-v1, achieves state-of-the-art performance among open-source and closed-source VLMs under 5b parameters.xgen-mm-phi3-mini-instruct-r-v1 supports flexible high-resolution image encoding with efficient visual token sampling.| Model | Shot | COCO (val) | NoCaps (val) | TextCaps (val) | OKVQA (val) | TextVQA (val) | VizWiz (testdev) | VQAv2 (testdev) |
|---|---|---|---|---|---|---|---|---|
| Flamingo-3B | 4 | 85.0 | - | - | 43.3 | 32.7 | 34 | 53.2 |
| 8 | 90.6 | - | - | 44.6 | 32.4 | 38.4 | 55.4 | |
| MM1-3B | 0 | 73.5 | 55.6 | 63.3 | 26.1 | 29.4 | 15.6 | 46.2 |
| 4 | 112.3 | 99.7 | 84.1 | 48.6 | 45.3 | 38.0 | 57.9 | |
| 8 | 114.6 | 104.7 | 88.8 | 48.4 | 44.6 | 46.4 | 63.6 | |
| xgen-mm-phi3-mini-base-r-v1 (Ours) | 0 | 81.7 | 80.2 | 60.7 | 26.5 | 36.0 | 21.2 | 48.1 |
| 4 | 110.5 | 101.7 | 84.6 | 49.2 | 46.1 | 38.4 | 63.9 | |
| 8 | 112.1 | 104.4 | 87.7 | 49.1 | 46.4 | 44.3 | 63.8 |
| Model | SEED-IMG | MMBench(dev) | MME-total | MME-P | MME-C | MMStar | MMMU (val) | MMVet | MathVista (mini) | ScienceQA (test) | POPE | AI2D | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MM1-3B-Chat | 68.8 | 67.8 | 1761 | 1482 | 279 | - | 33.9 | 43.7 | - | - | 87.4 | - | |
| openbmb/MiniCPM-V-2 | 67.1 | 69.6 | 1808 | - | - | - | 38.2 | - | 38.7 | - | - | - | |
| VILA1.5-3B | 67.9 | 63.4 | - | 1442 | - | - | 33.3 | 35.4 | - | 69.0 | 85.9 | - | |
| xtuner/llava-phi-3-mini-hf | 70.0 | 69.2 | 1790 | 1477 | 313 | 43.7 | 41.4 | - | - | 73.7 | 87.3 | 69.3 | |
| xgen-mm-phi3-mini-instruct-r-v1 (Ours) | 72.1 | 74.1 | 1827 | 1467 | 360 | 44.6 | 39.8 | 45.1 | 39.3 | 74.2 | 87.2 | 75.8 |
"4.41.0.dev0") of the transformers library. To get it, as of 05/07/2024, one can use pip uninstall -y transformers && pip install git+https://github.com/huggingface/transformers.1from transformers import AutoModelForVision2Seq, AutoTokenizer, AutoImageProcessor
2import requests
3from PIL import Image
4import IPython.display as display
5import torch
6model_name_or_path = "Salesforce/xgen-mm-phi3-mini-base-r-v1"
7model = AutoModelForVision2Seq.from_pretrained(model_name_or_path, trust_remote_code=True)
8tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True, use_fast=True, legacy=False)
9image_processor = AutoImageProcessor.from_pretrained(model_name_or_path, trust_remote_code=True)
10tokenizer = model.update_special_tokens(tokenizer)
11
12model = model.to('cuda')
13tokenizer.padding_side = "left"
14
15def apply_prompt_template(prompt, num_images=1, num_tokens_per_vis = 128, in_context=False, output=None):
16 """
17 num_tokens_per_vis: model.vlm.num_tokens_per_vis
18 """
19 placeholder_image_tokens = "<image placeholder>" * (num_tokens_per_vis - 1)
20 if in_context:
21 formatted_prompt = f"<image>{placeholder_image_tokens}" + f"{prompt}" + f"{output}" + "<|endofchunk|>"
22 else:
23 formatted_prompt = f"<image>{placeholder_image_tokens}"*num_images + f"{prompt}"
24 return formatted_prompt
25
26############ Zero shot inference ##########
27img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
28raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
29instruction = "Describe what is the dog doing in this image in one sentence:"
30print("==> Instruction: ", instruction)
31print("==> Image: ")
32display.display(raw_image.resize((int(raw_image.width*0.3), int(raw_image.height*0.3))))
33inputs = image_processor([raw_image], return_tensors="pt")
34prompt = apply_prompt_template(instruction)
35language_inputs = tokenizer([prompt], return_tensors="pt")
36inputs.update(language_inputs)
37inputs = {name: tensor.cuda() for name, tensor in inputs.items()}
38
39with torch.cuda.amp.autocast(dtype=torch.bfloat16):
40 generated_text = model.generate(**inputs,
41 pad_token_id=tokenizer.pad_token_id,
42 do_sample=False, max_new_tokens=64, top_p=None, num_beams=1,
43 length_penalty=1.0, repetition_penalty=3.0)
44prediction = tokenizer.decode(generated_text[0], skip_special_tokens=True)
45print("==> prediciton: ", prediction)
46print("-"*120)
47# ==> prediciton: The dog is sitting on the beach and waving at his owner.@misc{xue2024xgenmmblip3familyopen,
title={xGen-MM (BLIP-3): A Family of Open Large Multimodal Models},
author={Le Xue and Manli Shu and Anas Awadalla and Jun Wang and An Yan and Senthil Purushwalkam and Honglu Zhou and Viraj Prabhu and Yutong Dai and Michael S Ryoo and Shrikant Kendre and Jieyu Zhang and Can Qin and Shu Zhang and Chia-Chih Chen and Ning Yu and Juntao Tan and Tulika Manoj Awalgaonkar and Shelby Heinecke and Huan Wang and Yejin Choi and Ludwig Schmidt and Zeyuan Chen and Silvio Savarese and Juan Carlos Niebles and Caiming Xiong and Ran Xu},
year={2024},
eprint={2408.08872},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2408.08872},
}pip install torch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 --index-url https://download.pytorch.org/whl/cu121
pip install open_clip_torch==2.24.0
pip install einops
pip install einops-exts
pip install transformers==4.41.1transformers==4.41.1.