TIGER-Lab/Mantis-8B-Idefics2

Model

14

stars

10

commits

10

repos using this model

2

linked in READMEs

Nov 15, 2024

updated

conversational
endpoints_compatible
idefics2
image-text-to-text
llama3
llava
lmm
mantis
multimodal
safetensors
siglip
text-generation-inference
transformers
vlm
Browse cluster: Multimodal LLM Vision Architectures

README

🔥 Mantis (TMLR 2024)

Paper | Website | Github | Models | Demo | Wandb

Mantis

Excited to announce Mantis-Idefics2, with enhanced ability in multi-image scenarios! It's fine-tuned on Mantis-Instruct from Idefics2-8b

Summary

  • Mantis-Idefics2 is an LMM with interleaved text and image as inputs, trained on Mantis-Instruct under academic-level resources (i.e. 36 hours on 16xA100-40G).
  • Mantis is trained to have multi-image skills including co-reference, reasoning, comparing, temporal understanding.
  • Mantis reaches the state-of-the-art performance on five multi-image benchmarks (NLVR2, Q-Bench, BLINK, MVBench, Mantis-Eval), and also maintain a strong single-image performance on par with CogVLM and Emu2.

Multi-Image Performance

ModelsSizeFormatNLVR2Q-BenchMantis-EvalBLINKMVBenchAvg
GPT-4V-sequence88.8076.5262.6751.1443.5064.5
Open Source Models
Random--48.9340.2023.0438.0927.3035.5
Kosmos21.6Bmerge49.0035.1030.4137.5021.6234.7
LLaVA-v1.57Bmerge53.8849.3231.3437.1336.0041.5
LLava-V1.67Bmerge58.8854.8045.6239.5540.9048.0
Qwen-VL-Chat7Bmerge58.7245.9039.1731.1742.1543.4
Fuyu8Bmerge51.1049.1527.1936.5930.2038.8
BLIP-213Bmerge59.4251.2049.7739.4531.4046.2
InstructBLIP13Bmerge60.2644.3045.6242.2432.5045.0
CogVLM17Bmerge58.5853.2045.1641.5437.3047.2
OpenFlamingo9Bsequence36.4119.6012.4439.187.9023.1
Otter-Image9Bsequence49.1517.5014.2936.2615.3026.5
Idefics19Bsequence54.6330.6028.1124.6926.4232.9
VideoLLaVA7Bsequence56.4845.7035.9438.9244.3044.3
Emu2-Chat37Bsequence58.1650.0537.7936.2039.7244.4
Vila8Bsequence76.4545.7051.1539.3049.4052.4
Idefics28Bsequence86.8757.0048.8545.1829.6853.5
Mantis-CLIP8Bsequence84.6666.0055.7647.0648.3060.4
Mantis-SIGLIP8Bsequence87.4369.9059.4546.3550.1562.7
Mantis-Flamingo9Bsequence52.9646.8032.7238.0040.8342.3
Mantis-Idefics28Bsequence89.7175.2057.1449.0551.3864.5
$\Delta$ over SOTA--+2.84+18.20+8.30+3.87+1.98+11.0

Single-Image Performance

ModelSizeTextVQAVQAMMBMMMUOKVQASQAMathVistaAvg
OpenFlamingo9B46.358.032.428.751.445.718.640.2
Idefics19B39.368.845.332.550.451.621.144.1
InstructBLIP7B33.675.238.330.645.270.624.445.4
Yi-VL6B44.872.568.439.151.371.729.753.9
Qwen-VL-Chat7B63.878.261.835.956.668.215.554.3
LLaVA-1.57B58.276.664.835.353.470.425.654.9
Emu2-Chat37B66.684.963.636.364.865.330.758.9
CogVLM17B70.482.365.832.164.865.635.059.4
Idefics28B70.479.175.743.053.586.551.465.7
Mantis-CLIP8B56.473.066.038.153.073.831.756.0
Mantis-SigLIP8B59.274.968.740.155.474.934.458.2
Mantis-Idefics28B63.577.675.741.152.681.340.461.7

How to use

Run example inference:


import requests
import torch
from PIL import Image
from io import BytesIO

from transformers import AutoProcessor, AutoModelForVision2Seq
from transformers.image_utils import load_image


processor = AutoProcessor.from_pretrained("TIGER-Lab/Mantis-8B-Idefics2") # do_image_splitting is False by default
model = AutoModelForVision2Seq.from_pretrained(
    "TIGER-Lab/Mantis-8B-Idefics2",
    device_map="auto"
)
generation_kwargs = {
    "max_new_tokens": 1024,
    "num_beams": 1,
    "do_sample": False
}

# Note that passing the image urls (instead of the actual pil images) to the processor is also possible
image1 = load_image("https://cdn.britannica.com/59/94459-050-DBA42467/Skyline-Chicago.jpg")
image2 = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")
image3 = load_image("https://cdn.britannica.com/68/170868-050-8DDE8263/Golden-Gate-Bridge-San-Francisco.jpg")
images = [image1, image2, image3]


query1 = "What cities image 1, image 2, and image 3 belong to respectively? Answer me in order."
query2 = "Which one do you recommend for a visit? and why?"
query3 = "Which picture has most cars in it?"

### Chat
### Round 1
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image"},
            {"type": "image"},
            {"type": "image"},
            {"type": "text", "text": query1},
        ]
    }    
]
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=images, return_tensors="pt")
inputs = {k: v.to(model.device) for k, v in inputs.items()}

# Generate
generated_ids = model.generate(**inputs, **generation_kwargs)
response = processor.batch_decode(generated_ids[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print("User: ", query1)
print("ASSISTANT: ", response[0])

### Round 2
messages.append(
    {
        "role": "assistant",
        "content": [
            {"type": "text", "text": response[0]},
        ]
    }
)
messages.append(
    {
        "role": "user",
        "content": [
            {"type": "text", "text": query2},
        ]
    }
)
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=images, return_tensors="pt")
inputs = {k: v.to(model.device) for k, v in inputs.items()}
generated_ids = model.generate(**inputs, **generation_kwargs)
response = processor.batch_decode(generated_ids[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print("User: ", query2)
print("ASSISTANT: ", response[0])

### Round 3
messages.append(
    {
        "role": "assistant",
        "content": [
            {"type": "text", "text": response[0]},
        ]
    }
)
messages.append(
    {
        "role": "user",
        "content": [
            {"type": "text", "text": query3},
        ]
    }
)

prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=images, return_tensors="pt")
inputs = {k: v.to(model.device) for k, v in inputs.items()}
generated_ids = model.generate(**inputs, **generation_kwargs)
response = processor.batch_decode(generated_ids[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print("User: ", query3)
print("ASSISTANT: ", response[0])


"""
User:  What cities image 1, image 2, and image 3 belong to respectively? Answer me in order.
ASSISTANT:  Chicago, New York, San Francisco
User:  Which one do you recommend for a visit? and why?
ASSISTANT:  New York - because it's a bustling metropolis with iconic landmarks like the Statue of Liberty and the Empire State Building.
User:  Which picture has most cars in it?
ASSISTANT:  Image 3
"""

Training

See mantis/train for details

Evaluation

See mantis/benchmark for details

Please cite our paper or give a star to out Github repo if you find this model useful

Citation

@article{Jiang2024MANTISIM,
  title={MANTIS: Interleaved Multi-Image Instruction Tuning},
  author={Dongfu Jiang and Xuan He and Huaye Zeng and Cong Wei and Max W.F. Ku and Qian Liu and Wenhu Chen},
  journal={Transactions on Machine Learning Research},
  year={2024},
  volume={2024},
  url={https://openreview.net/forum?id=skLtdUVaJa}
}

Contributors

DongfuJiang

10 commits

TIGER-Lab/Mantis-8B-Idefics2

Model

14

stars

10

commits

10

repos using this model

2

linked in READMEs

Nov 15, 2024

updated

conversational
endpoints_compatible
idefics2
image-text-to-text
llama3
llava
lmm
mantis
multimodal
safetensors
siglip
text-generation-inference
transformers
vlm
Browse cluster: Multimodal LLM Vision Architectures

README

🔥 Mantis (TMLR 2024)

Paper | Website | Github | Models | Demo | Wandb

Mantis

Excited to announce Mantis-Idefics2, with enhanced ability in multi-image scenarios! It's fine-tuned on Mantis-Instruct from Idefics2-8b

Summary

  • Mantis-Idefics2 is an LMM with interleaved text and image as inputs, trained on Mantis-Instruct under academic-level resources (i.e. 36 hours on 16xA100-40G).
  • Mantis is trained to have multi-image skills including co-reference, reasoning, comparing, temporal understanding.
  • Mantis reaches the state-of-the-art performance on five multi-image benchmarks (NLVR2, Q-Bench, BLINK, MVBench, Mantis-Eval), and also maintain a strong single-image performance on par with CogVLM and Emu2.

Multi-Image Performance

ModelsSizeFormatNLVR2Q-BenchMantis-EvalBLINKMVBenchAvg
GPT-4V-sequence88.8076.5262.6751.1443.5064.5
Open Source Models
Random--48.9340.2023.0438.0927.3035.5
Kosmos21.6Bmerge49.0035.1030.4137.5021.6234.7
LLaVA-v1.57Bmerge53.8849.3231.3437.1336.0041.5
LLava-V1.67Bmerge58.8854.8045.6239.5540.9048.0
Qwen-VL-Chat7Bmerge58.7245.9039.1731.1742.1543.4
Fuyu8Bmerge51.1049.1527.1936.5930.2038.8
BLIP-213Bmerge59.4251.2049.7739.4531.4046.2
InstructBLIP13Bmerge60.2644.3045.6242.2432.5045.0
CogVLM17Bmerge58.5853.2045.1641.5437.3047.2
OpenFlamingo9Bsequence36.4119.6012.4439.187.9023.1
Otter-Image9Bsequence49.1517.5014.2936.2615.3026.5
Idefics19Bsequence54.6330.6028.1124.6926.4232.9
VideoLLaVA7Bsequence56.4845.7035.9438.9244.3044.3
Emu2-Chat37Bsequence58.1650.0537.7936.2039.7244.4
Vila8Bsequence76.4545.7051.1539.3049.4052.4
Idefics28Bsequence86.8757.0048.8545.1829.6853.5
Mantis-CLIP8Bsequence84.6666.0055.7647.0648.3060.4
Mantis-SIGLIP8Bsequence87.4369.9059.4546.3550.1562.7
Mantis-Flamingo9Bsequence52.9646.8032.7238.0040.8342.3
Mantis-Idefics28Bsequence89.7175.2057.1449.0551.3864.5
$\Delta$ over SOTA--+2.84+18.20+8.30+3.87+1.98+11.0

Single-Image Performance

ModelSizeTextVQAVQAMMBMMMUOKVQASQAMathVistaAvg
OpenFlamingo9B46.358.032.428.751.445.718.640.2
Idefics19B39.368.845.332.550.451.621.144.1
InstructBLIP7B33.675.238.330.645.270.624.445.4
Yi-VL6B44.872.568.439.151.371.729.753.9
Qwen-VL-Chat7B63.878.261.835.956.668.215.554.3
LLaVA-1.57B58.276.664.835.353.470.425.654.9
Emu2-Chat37B66.684.963.636.364.865.330.758.9
CogVLM17B70.482.365.832.164.865.635.059.4
Idefics28B70.479.175.743.053.586.551.465.7
Mantis-CLIP8B56.473.066.038.153.073.831.756.0
Mantis-SigLIP8B59.274.968.740.155.474.934.458.2
Mantis-Idefics28B63.577.675.741.152.681.340.461.7

How to use

Run example inference:


import requests
import torch
from PIL import Image
from io import BytesIO

from transformers import AutoProcessor, AutoModelForVision2Seq
from transformers.image_utils import load_image


processor = AutoProcessor.from_pretrained("TIGER-Lab/Mantis-8B-Idefics2") # do_image_splitting is False by default
model = AutoModelForVision2Seq.from_pretrained(
    "TIGER-Lab/Mantis-8B-Idefics2",
    device_map="auto"
)
generation_kwargs = {
    "max_new_tokens": 1024,
    "num_beams": 1,
    "do_sample": False
}

# Note that passing the image urls (instead of the actual pil images) to the processor is also possible
image1 = load_image("https://cdn.britannica.com/59/94459-050-DBA42467/Skyline-Chicago.jpg")
image2 = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")
image3 = load_image("https://cdn.britannica.com/68/170868-050-8DDE8263/Golden-Gate-Bridge-San-Francisco.jpg")
images = [image1, image2, image3]


query1 = "What cities image 1, image 2, and image 3 belong to respectively? Answer me in order."
query2 = "Which one do you recommend for a visit? and why?"
query3 = "Which picture has most cars in it?"

### Chat
### Round 1
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image"},
            {"type": "image"},
            {"type": "image"},
            {"type": "text", "text": query1},
        ]
    }    
]
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=images, return_tensors="pt")
inputs = {k: v.to(model.device) for k, v in inputs.items()}

# Generate
generated_ids = model.generate(**inputs, **generation_kwargs)
response = processor.batch_decode(generated_ids[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print("User: ", query1)
print("ASSISTANT: ", response[0])

### Round 2
messages.append(
    {
        "role": "assistant",
        "content": [
            {"type": "text", "text": response[0]},
        ]
    }
)
messages.append(
    {
        "role": "user",
        "content": [
            {"type": "text", "text": query2},
        ]
    }
)
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=images, return_tensors="pt")
inputs = {k: v.to(model.device) for k, v in inputs.items()}
generated_ids = model.generate(**inputs, **generation_kwargs)
response = processor.batch_decode(generated_ids[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print("User: ", query2)
print("ASSISTANT: ", response[0])

### Round 3
messages.append(
    {
        "role": "assistant",
        "content": [
            {"type": "text", "text": response[0]},
        ]
    }
)
messages.append(
    {
        "role": "user",
        "content": [
            {"type": "text", "text": query3},
        ]
    }
)

prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=images, return_tensors="pt")
inputs = {k: v.to(model.device) for k, v in inputs.items()}
generated_ids = model.generate(**inputs, **generation_kwargs)
response = processor.batch_decode(generated_ids[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print("User: ", query3)
print("ASSISTANT: ", response[0])


"""
User:  What cities image 1, image 2, and image 3 belong to respectively? Answer me in order.
ASSISTANT:  Chicago, New York, San Francisco
User:  Which one do you recommend for a visit? and why?
ASSISTANT:  New York - because it's a bustling metropolis with iconic landmarks like the Statue of Liberty and the Empire State Building.
User:  Which picture has most cars in it?
ASSISTANT:  Image 3
"""

Training

See mantis/train for details

Evaluation

See mantis/benchmark for details

Please cite our paper or give a star to out Github repo if you find this model useful

Citation

@article{Jiang2024MANTISIM,
  title={MANTIS: Interleaved Multi-Image Instruction Tuning},
  author={Dongfu Jiang and Xuan He and Huaye Zeng and Cong Wei and Max W.F. Ku and Qian Liu and Wenhu Chen},
  journal={Transactions on Machine Learning Research},
  year={2024},
  volume={2024},
  url={https://openreview.net/forum?id=skLtdUVaJa}
}

Contributors

DongfuJiang

10 commits