Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/llamafactory/data/collator.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,19 @@ def __call__(self, features: list[dict[str, Any]]) -> dict[str, "torch.Tensor"]:
for i, feature in enumerate(features):
feature["token_type_ids"] = token_type_ids[i]

if "mm_token_type_ids" in mm_inputs: # need tensor-like for gemma4
mm_token_type_ids = mm_inputs.pop("mm_token_type_ids")
max_len = max(len(ids) for ids in mm_token_type_ids)
padded = []
for ids in mm_token_type_ids:
pad_len = max_len - len(ids)
if self.tokenizer.padding_side == "right":
padded.append(ids + [0] * pad_len)
else:
padded.append([0] * pad_len + ids)
Comment thread
Kuangdd01 marked this conversation as resolved.

mm_inputs["mm_token_type_ids"] = torch.tensor(padded, dtype=torch.long)

features: dict[str, torch.Tensor] = super().__call__(features)

bsz, seq_len = features["input_ids"].shape[:2]
Expand Down
Loading