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
6 changes: 3 additions & 3 deletions swift/llm/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,10 @@ def _add_dynamic_eos(input_ids: List[int], labels: List[int], loss_scale: Option
suffix_tokens_id: List[int]) -> None:
suffix_len = len(suffix_tokens_id)
start = 0
for i in range(1, len(labels)):
if labels[i - 1] >= 0 and labels[i] == -100:
for i in range(1, len(labels) + 1):
if labels[i - 1] >= 0 and i < len(labels) and labels[i] == -100:
start = i
if start > 0 and labels[i - 1] == -100 and labels[i] >= 0:
elif start > 0 and labels[i - 1] == -100 and (i == len(labels) or labels[i] >= 0):
# [0, 1, 2, -100(start), -100, 3(i), 4]
length = i - start
if length >= suffix_len and input_ids[start:start + suffix_len] == suffix_tokens_id:
Expand Down
Loading