From 0024bb06aaf124a698c17d4ec3195391b6e05259 Mon Sep 17 00:00:00 2001 From: Elia Zonta Date: Sun, 19 Jul 2026 11:06:10 +0200 Subject: [PATCH 1/2] fix(trainer): warn loudly when requested packing is silently disabled When packing=True is requested but the model is a VLM / processor-based / uses a custom collator, auto-packing is turned off. Previously this only printed a terse 'Sample packing skipped' line and never mentioned the consequence: sequences longer than the max sequence length are truncated rather than split, so long-document datasets (e.g. raw-text CPT) can silently lose a large fraction of their tokens. Escalate to logger.warning, state that overlength samples are TRUNCATED (not split), include the effective max sequence length when available, and point users at pre-splitting/pre-packing. Messaging-only; behaviour unchanged. Fixes #7206 --- unsloth/trainer.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/unsloth/trainer.py b/unsloth/trainer.py index 83cb1758f0..85b91c95c9 100644 --- a/unsloth/trainer.py +++ b/unsloth/trainer.py @@ -541,8 +541,24 @@ def _patch_sft_trainer_auto_packing(trl_module): reason = "vision-language model" elif is_unsupported_model: reason = f"unsupported model type(s): {', '.join(model_types)}" - message = f"Unsloth: Sample packing skipped ({reason} detected)." - print(message) + max_len = ( + getattr(config_arg, "max_seq_length", None) + or getattr(config_arg, "max_length", None) + ) + limit = ( + f"the {max_len}-token max sequence length" + if max_len + else "the max sequence length" + ) + message = ( + f"Unsloth: Sample packing skipped ({reason} detected) even though " + f"packing=True was requested. Sequences longer than {limit} will be " + f"TRUNCATED rather than split into additional sequences, which can silently " + f"drop a large fraction of tokens from long samples. If your dataset has long " + f"documents (e.g. raw-text CPT), pre-split or pre-pack them before training to " + f"avoid data loss." + ) + logger.warning(message) packing_active = False if _should_pack(config_arg) and not blocked: From 7757e91c9e7956f9542f3c297031f6d906deda6b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 Jul 2026 09:08:57 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- unsloth/trainer.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/unsloth/trainer.py b/unsloth/trainer.py index 85b91c95c9..f2893efed7 100644 --- a/unsloth/trainer.py +++ b/unsloth/trainer.py @@ -541,14 +541,11 @@ def _patch_sft_trainer_auto_packing(trl_module): reason = "vision-language model" elif is_unsupported_model: reason = f"unsupported model type(s): {', '.join(model_types)}" - max_len = ( - getattr(config_arg, "max_seq_length", None) - or getattr(config_arg, "max_length", None) + max_len = getattr(config_arg, "max_seq_length", None) or getattr( + config_arg, "max_length", None ) limit = ( - f"the {max_len}-token max sequence length" - if max_len - else "the max sequence length" + f"the {max_len}-token max sequence length" if max_len else "the max sequence length" ) message = ( f"Unsloth: Sample packing skipped ({reason} detected) even though "