Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ def main():
model.eval()

tokenizer = get_tokenizer(model.cfg.lm_tokenizer, model.cfg.vlm_extra_tokens)
image_processor = get_image_processor(model.cfg.max_img_size, model.cfg.vit_img_size)
# FIXED: Use vit_img_size and splitted_image_size for MPS compatibility
# Original: get_image_processor(model.cfg.max_img_size, model.cfg.vit_img_size)
image_processor = get_image_processor(model.cfg.vit_img_size, model.cfg.splitted_image_size)

img = Image.open(args.image).convert("RGB")
processed_image, splittedimage_count = image_processor(img)
# FIXED: Simplified image processing for MPS compatibility
# Original: processed_image, splittedimage_count = image_processor(img)
img_t = image_processor(img)[0][0].unsqueeze(0).to(device)
vit_patch_size = splittedimage_count[0] * splittedimage_count[1]

messages = [{"role": "user", "content": tokenizer.image_token * model.cfg.mp_image_token_length * vit_patch_size + args.prompt}]
Expand Down
6 changes: 6 additions & 0 deletions models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class VLMConfig:
lm_tokenizer: str = 'HuggingFaceTB/SmolLM2-360M-Instruct'
lm_chat_template: str = "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}"

# Quick fix for MPS compatibility - provides dummy EOS token ID
lm_eos_token_id: str = "Dummy"

# Quick fix for MPS compatibility - defines fixed image split size
splitted_image_size: int = 16 # Quick Fix

mp_pixel_shuffle_factor: int = 4
mp_image_token_length: int = 64

Expand Down