Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix idefics3 #133

Merged
merged 3 commits into from
Nov 28, 2024
Merged
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
9 changes: 7 additions & 2 deletions mlx_vlm/models/idefics3/idefics3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ class ModelConfig:
vision_config: VisionConfig
model_type: str
ignore_index: int = -100
image_token_id: int = 128257
vocab_size: int = 128259
scale_factor: int = 2
image_token_id: int = 49153
image_token_index: Optional[int] = None

def __post_init__(self):
if self.image_token_index is None:
self.image_token_index = self.image_token_id

@classmethod
def from_dict(cls, params):
Expand Down Expand Up @@ -111,7 +116,7 @@ def get_input_embeddings(
return final_inputs_embeds

def _prepare_inputs_for_multimodal(self, image_features, inputs_embeds, input_ids):
image_token_index = self.config.image_token_id
image_token_index = self.config.image_token_index
num_images, num_image_patches, embed_dim = image_features.shape

# Positions of <image> tokens in input_ids, assuming batch size is 1
Expand Down
2 changes: 1 addition & 1 deletion mlx_vlm/prompt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def add_image_tokens(message, token_format):
return message
if role == "user" and not skip_image_token:
if isinstance(message["content"], list):
if model_name == "pixtral":
if model_name in ["pixtral", "idefics3"]:
message["content"] = [{"type": "image"}] * num_images + message[
"content"
]
Expand Down