Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Read supervision from labels or the mask column in the padding-free filter tests (#12452)

Daniel Han7f6e682b0131
diff --git a/tests/version_compat/test_trl_padding_free_max_length.py b/tests/version_compat/test_trl_padding_free_max_length.py
index 0883d09aef4..21804618aef 100644
--- a/tests/version_compat/test_trl_padding_free_max_length.py
+++ b/tests/version_compat/test_trl_padding_free_max_length.py
@@ -1087,6 +1087,19 @@ def _mask_supervised_dataset(tok):
)
+def _has_supervised_token(row, mask_column):
+ """Whether a prepared row still trains on at least one token, in either form it can take.
+
+ Before TRL 1.7 the collator applies the mask, so the row keeps its mask column. From 1.7
+ TRL's _prepare_dataset turns the masks into `labels` and drops them, and unsloth-zoo's
+ sft_prepare_dataset does the same since unslothai/unsloth-zoo#1508, so the row carries
+ `labels` with -100 on every unsupervised token instead."""
+ if mask_column in row:
+ return any(m != 0 for m in row[mask_column])
+ assert "labels" in row, f"the row carries neither {mask_column} nor labels: {sorted(row)}"
+ return any(label != -100 for label in row["labels"])
+
+
def test_rows_whose_mask_is_truncated_away_are_dropped(tmp_path, trl_has_guard):
"""Same rule the `labels` filter already applies, for the other two spellings."""
if not trl_has_guard:
@@ -1098,8 +1111,8 @@ def test_rows_whose_mask_is_truncated_away_are_dropped(tmp_path, trl_has_guard):
trainer = _build(tmp_path, dataset = _mask_supervised_dataset, completion_only_loss = True)
assert len(trainer.train_dataset) == 2, "the rows that kept their completion were dropped too"
for row in trainer.train_dataset:
- assert any(
- m != 0 for m in row["completion_mask"]
+ assert _has_supervised_token(
+ row, "completion_mask"
), "a row with no supervised token survived truncation"
@@ -1128,8 +1141,8 @@ def test_assistant_masks_are_filtered_even_with_the_loss_mode_off(tmp_path, trl_
trainer = _build(tmp_path, dataset = _assistant_mask_dataset, assistant_only_loss = False)
assert len(trainer.train_dataset) == 2, "the rows that kept their completion were dropped too"
for row in trainer.train_dataset:
- assert any(
- m != 0 for m in row["assistant_masks"]
+ assert _has_supervised_token(
+ row, "assistant_masks"
), "a row TRL will label all -100 survived truncation"