Views
No views yet

af, am, ar, az, be, bg, bn, ca, ceb, cs, cy, da, de, el, en, eo, es, et, eu, fa, fi, fil, fr, ga, gd, gl, gu, ha, hi, ht, hu, hy, id, ig, is, it, iw, ja, jv, ka, kk, km, kn, ko, ku, ky, lb, lo, lt, lv, mg, mi, mk, ml, mn, mr, ms, mt, my, ne, nl, no, ny, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sm, sn, so, sq, sr, st, su, sv, sw, ta, te, tg, th, tr, uk, ur, uz, vi, xh, yi, yo, zh, zu1import requests
2from PIL import Image
3from transformers import Blip2Processor, Blip2ForConditionalGeneration
4
5processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
6model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b")
7
8img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
9raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
10
11question = "Describe the image in German."
12inputs = processor(raw_image, question, return_tensors="pt")
13
14out = model.generate(**inputs)
15print(processor.decode(out[0], skip_special_tokens=True))1# pip install accelerate
2import requests
3from PIL import Image
4from transformers import Blip2Processor, Blip2ForConditionalGeneration
5
6processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
7model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b", device_map="auto")
8
9img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
10raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
11
12question = "Describe the image in German."
13inputs = processor(raw_image, question, return_tensors="pt").to("cuda")
14
15out = model.generate(**inputs)
16print(processor.decode(out[0], skip_special_tokens=True))bfloat16)1# pip install accelerate
2import torch
3import requests
4from PIL import Image
5from transformers import Blip2Processor, Blip2ForConditionalGeneration
6
7processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
8model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b", torch_dtype=torch.bfloat16, device_map="auto")
9
10img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
11raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
12
13question = "Describe the image in German."
14inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.bfloat16)
15
16out = model.generate(**inputs)
17print(processor.decode(out[0], skip_special_tokens=True))int8)Important: Paper results only use int8 for the LLM weights while this loads all weights in int8. We see that this gives slightly worse results but currently int8 for only some model parts is not supported by HuggingFace.
1# pip install accelerate bitsandbytes
2import torch
3import requests
4from PIL import Image
5from transformers import Blip2Processor, Blip2ForConditionalGeneration
6
7processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
8model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b", load_in_8bit=True, device_map="auto")
9
10img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
11raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
12
13question = "Describe the image in German."
14inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.bfloat16)
15
16out = model.generate(**inputs)
17print(processor.decode(out[0], skip_special_tokens=True))int4)Important: Paper results only use int4 for the LLM weights while this loads all weights in int8. We see that this gives slightly worse results but currently int4 for only some model parts is not supported by HuggingFace.
1# pip install accelerate bitsandbytes
2import torch
3import requests
4from PIL import Image
5from transformers import Blip2Processor, Blip2ForConditionalGeneration
6
7processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
8model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b",
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_use_double_quant=False,
12 bnb_4bit_compute_dtype=torch.bfloat16,
13 device_map="auto")
14
15img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
16raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
17
18question = "Describe the image in German."
19inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.bfloat16)
20
21out = model.generate(**inputs)
22print(processor.decode(out[0], skip_special_tokens=True))@article{geigle2023mblip,
author = {Gregor Geigle and
Abhay Jain and
Radu Timofte and
Goran Glava\v{s}},
title = {mBLIP: Efficient Bootstrapping of Multilingual Vision-LLMs},
journal = {arXiv},
volume = {abs/2307.06930},
year = {2023},
url = {https://arxiv.org/abs/2307.06930},
eprinttype = {arXiv},
eprint = {2307.06930},
}