Skip to content

Commit 5830460

Browse files
committed
fix
1 parent 2651686 commit 5830460

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/twinkle/template/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ def tokenize_with_assistant_labels(
127127
"Placeholder might appear in original content."
128128
)
129129

130-
labels = build_labels(full_ids, template_parts)
130+
try:
131+
labels = build_labels(full_ids, template_parts)
132+
except ValueError as e:
133+
newline_placeholder_ids = tokenizer.encode("\n" + placeholder, **extra_kwargs)
134+
template_parts = split_by_subsequence(template_ids, newline_placeholder_ids)
135+
if len(template_parts) == assistant_count + 1:
136+
labels = build_labels(full_ids, template_parts)
137+
else:
138+
raise e
131139
if labels and labels[-1] == -100:
132140
end_idx = len(labels)
133141
start_idx = end_idx - 1

0 commit comments

Comments
 (0)