Skip to content

Commit 58a8ffb

Browse files
authored
[bugfix] fix agent_template (#6723)
1 parent 032993c commit 58a8ffb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

swift/llm/template/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,10 +980,10 @@ def _add_dynamic_eos(input_ids: List[int], labels: List[int], loss_scale: Option
980980
suffix_tokens_id: List[int]) -> None:
981981
suffix_len = len(suffix_tokens_id)
982982
start = 0
983-
for i in range(1, len(labels)):
984-
if labels[i - 1] >= 0 and labels[i] == -100:
983+
for i in range(1, len(labels) + 1):
984+
if labels[i - 1] >= 0 and i < len(labels) and labels[i] == -100:
985985
start = i
986-
if start > 0 and labels[i - 1] == -100 and labels[i] >= 0:
986+
elif start > 0 and labels[i - 1] == -100 and (i == len(labels) or labels[i] >= 0):
987987
# [0, 1, 2, -100(start), -100, 3(i), 4]
988988
length = i - start
989989
if length >= suffix_len and input_ids[start:start + suffix_len] == suffix_tokens_id:

0 commit comments

Comments
 (0)