-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
matatonic
committed
May 4, 2024
1 parent
1338426
commit c8d0fe3
Showing
5 changed files
with
56 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from mantis.models.mllava import chat_mllava, MLlavaProcessor, LlavaForConditionalGeneration | ||
from mantis.models.mfuyu import MFuyuForCausalLM, MFuyuProcessor | ||
|
||
from vision_qna import * | ||
|
||
class VisionQnA(VisionQnABase): | ||
model_name: str = "mantis" | ||
|
||
def __init__(self, model_id: str, device: str, device_map: str = 'auto', extra_params = {}, format = None): | ||
super().__init__(model_id, device, device_map, extra_params, format) | ||
|
||
del self.params['trust_remote_code'] | ||
|
||
if '-fuyu' in model_id.lower(): | ||
self.processor = MFuyuProcessor.from_pretrained(model_id) | ||
self.model = MFuyuForCausalLM.from_pretrained(**self.params) | ||
else: | ||
self.processor = MLlavaProcessor.from_pretrained(model_id) | ||
self.model = LlavaForConditionalGeneration.from_pretrained(**self.params) | ||
|
||
print(f"Loaded on device: {self.model.device} with dtype: {self.model.dtype}") | ||
|
||
async def chat_with_images(self, request: ImageChatRequest) -> str: | ||
prompt, history, images, system = await prompt_history_images_system_from_messages(request.messages, img_tok = "<image>", url_handler = url_to_image) | ||
|
||
default_params = { | ||
'num_beams': 1, | ||
'do_sample': False, | ||
} | ||
|
||
params = self.get_generation_params(request, default_params) | ||
|
||
response, history = chat_mllava(prompt, images, self.model, self.processor, history=history, **params) | ||
|
||
return response | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters