From 1622059179ee2da36b9c46c3aa32752eb45b4214 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 15 Feb 2023 00:03:19 -0300 Subject: [PATCH] Move BLIP to the CPU It's just as fast --- modules/bot_picture.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/bot_picture.py b/modules/bot_picture.py index f19e398a..f407c379 100644 --- a/modules/bot_picture.py +++ b/modules/bot_picture.py @@ -5,10 +5,9 @@ from transformers import BlipForConditionalGeneration from transformers import BlipProcessor processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") -model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", torch_dtype=torch.float16).to("cuda") +model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", torch_dtype=torch.float32).to("cpu") -# raw_image = Image.open('/tmp/istockphoto-470604022-612x612.jpg').convert('RGB') def caption_image(raw_image): - inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16) + inputs = processor(raw_image.convert('RGB'), return_tensors="pt").to("cpu", torch.float32) out = model.generate(**inputs, max_new_tokens=100) return processor.decode(out[0], skip_special_tokens=True)