Using AutoModelForImageTextToText to load model

#47
by adriantd3 - opened

Hi! I have implemented an abstrac method to load and use different models. However, it does not seem to work with this model.
This is how I load my models:

quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16
)
processor = AutoProcessor.from_pretrained(model_id, device_map="auto")
model = AutoModelForImageTextToText.from_pretrained(
model_id,
quantization_config=quantization_config,
device_map="auto"
)

And this is how I use the models:

def generate_text_with_images(self, prompt: str, images: list[str], params: dict):
"""Generates text based on a text prompt and input images."""
inputs = self.processor(
text=prompt,
images=list(map(self.base64_to_PIL, images)),
padding=True,
return_tensors="pt"
)
output = self._model.generate(**inputs, max_new_tokens=200)
return self.processor.batch_decode(output, skip_special_tokens=True)[-1]

Is there any way I can addapt it to work fine with MiniCPM and any other model? The provided code in the README uses AutoModel and a tokenizer, instead of a processor.

I am currently using transformers==4.48.2, as downgrading to older versions does not work for me.

Thanks beforehand!

Sign up or log in to comment