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.

Fix auto padding free logic to respect user passed False (#4128)

DoubleMathewa835b266ef6b
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py
index eb5d4be1718..e4f34c908ec 100755
--- a/unsloth/models/rl.py
+++ b/unsloth/models/rl.py
@@ -1037,6 +1037,7 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):
"include_num_input_tokens_seen": False,
"auto_find_batch_size": False, # Auto /2 batch size - too many people complained so removing
"dataloader_pin_memory": True,
+ "padding_free": None, # None = user didn't set it, allows auto-enable detection
# Might fail so disable for now
# "dataloader_persistent_workers" : True, # Keeps dataloader in RAM
# "dataloader_prefetch_factor" : 2,
diff --git a/unsloth/trainer.py b/unsloth/trainer.py
index cb36b8639d2..65abe6801fc 100644
--- a/unsloth/trainer.py
+++ b/unsloth/trainer.py
@@ -73,7 +73,7 @@ def _should_auto_padding_free(config) -> bool:
or getattr(config, "packing", False)
):
return False
- return not getattr(config, "padding_free", False)
+ return getattr(config, "padding_free", None) is None
def _disable_sample_packing(config):
@@ -392,6 +392,7 @@ def _patch_sft_trainer_auto_packing(trl_module):
packing_active = True
logger.info("Unsloth: Sample packing enabled for SFTTrainer instance.")
+ # Resolve padding_free: None (default) = auto-enable unless env-disabled or packing
auto_padding_free_active = False
padding_free_requested = getattr(config_arg, "padding_free", None) is True
if not blocked: