diff --git a/llmc/models/llava_hf.py b/llmc/models/llava_hf.py index 6a794a3b..f1a53f9e 100644 --- a/llmc/models/llava_hf.py +++ b/llmc/models/llava_hf.py @@ -27,12 +27,22 @@ def build_model(self): if not self.use_cache: self.vlm_model_config.text_config.use_cache = False logger.info(f'self.vlm_model_config : {self.vlm_model_config}') - self.vlm_model = LlavaForConditionalGeneration.from_pretrained( - self.model_path, - config=self.vlm_model_config, - torch_dtype=self.torch_dtype, - low_cpu_mem_usage=True, - ) + try: + # transformers >= 4.56: `dtype` is the replacement for `torch_dtype` + self.vlm_model = LlavaForConditionalGeneration.from_pretrained( + self.model_path, + config=self.vlm_model_config, + dtype=self.torch_dtype, + low_cpu_mem_usage=True, + ) + except TypeError: + # transformers < 4.56: `dtype` is not accepted yet + self.vlm_model = LlavaForConditionalGeneration.from_pretrained( + self.model_path, + config=self.vlm_model_config, + torch_dtype=self.torch_dtype, + low_cpu_mem_usage=True, + ) self.eval_name = 'LlavaHfEval' self.mm_model = self.vlm_model logger.info(f'self.vlm_model : {self.vlm_model}')