Skip to content

Commit

Permalink
fix glm4v images (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jintao-Huang authored Jun 21, 2024
1 parent f2da35c commit 2956815
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions swift/llm/utils/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,10 @@ def encode(self, example: Dict[str, Any]) -> Tuple[Dict[str, Any], Dict[str, Any
placeholder_id = self.tokenizer.encode(placeholder, add_special_tokens=False)
input_ids = (input_ids[:idx] + placeholder_id + input_ids[idx + 1:])
if labels is not None:
labels = (labels[:idx] + [-100] * len(placeholder_id) + labels[idx + 1:])
image_size: int = self.model.config.vision_config['image_size']
patch_size: int = self.model.config.vision_config['patch_size']
num_patches = (image_size // patch_size // 2)**2
labels = (labels[:idx] + [-100] * (len(placeholder_id) + num_patches - 1) + labels[idx + 1:])
messages = history_to_messages(example.get('history', []), example['query'], example.get('system', None))
messages[0]['image'] = image
inputs2: Dict[str, Any] = self.tokenizer.apply_chat_template(messages, return_dict=True)
Expand All @@ -957,7 +960,7 @@ def data_collator(self, batch: List[Dict[str, Any]], padding_to: Optional[int] =
return res


register_template(TemplateType.glm4v, GLM4VTemplate(), infer_media_type='dialogue', lazy_tokenize=True)
register_template(TemplateType.glm4v, GLM4VTemplate(), infer_media_type='dialogue', lazy_tokenize=True, use_model=True)

register_template(
TemplateType.yi_vl,
Expand Down

1 comment on commit 2956815

@demoninpiano
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问下是不是这个commit之前的sft不会用到image, 只用到text进行微调?

Please sign in to comment.