Report a trainer kwarg that neither the trainer nor the config takes - #9944
Open
vineethsaivs wants to merge 2 commits into
Open
Report a trainer kwarg that neither the trainer nor the config takes#9944vineethsaivs wants to merge 2 commits into
vineethsaivs wants to merge 2 commits into
Conversation
`_backwards_compatible_trainer` sorts every keyword into trainer kwargs or config kwargs, but the `elif` and the `else` write to the same dict, so the classification it just made is thrown away. The branch every real call takes then re-tests the same condition and only copies across the keys the config recognises, which leaves everything else on the floor. `max_seq_length` is the case that bites. It is the kwarg the older notebooks pass to `SFTTrainer`, and trl 0.20 removed it from `SFTConfig`, so today it sits on neither side: the wrapper drops it in silence and the run trains at the default length instead of the one that was asked for. Without the wrapper Python reports it, and the other branch here still does, raising `TypeError` out of `config_class(**config_dict)`. Leave those keys on the trainer call so the trainer reports them, which is the distinction the `else` branch was written to make and never made. The test helper now takes `SFTConfig` from `trl.trainer.sft_config` rather than the `trl` top level. On Apple Silicon the `import unsloth` in tests/conftest.py rebinds the top-level name to the MLX training config, which carries none of SFTConfig's fields, and three tests in this file already fail there for that reason.
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
_backwards_compatible_trainer(unsloth/trainer.py) exists to move the keywords trl relocated from the trainer onto the config. It sorts every keyword into one of two dicts:The
elifand theelsewrite to the same dict, so the classification is computed and then discarded. The branch every real call takes re-tests the same condition and copies across only what the config recognises:Anything that fails that test is dropped without a word.
max_seq_lengthis the case that bites. It is the keyword the older notebooks pass straight toSFTTrainer, and trl 0.20 removed it fromSFTConfig, so on current trl it is on neither the trainer signature nor the config:Nothing is printed and training runs at the default length. Every other path reports it: plain trl raises
TypeError: __init__() got an unexpected keyword argument 'max_seq_length', and even the sibling branch here raises it out ofconfig_class(**config_dict).The fix
Leave the unrecognised keys on the trainer call, which is the distinction the
elsebranch was written to make and never made. The trainer then reports them the way an unexpected keyword normally is reported, instead of the value disappearing.No in-repo caller is affected:
unsloth-cli.pyalready passesmax_lengthon the config, and everySFTTrainer(**trainer_kwargs)instudio/backend/core/training/trainer.pybuilds its dict from real trainer parameters only.Test
test_a_kwarg_neither_side_takes_is_reported_not_swallowedintests/test_warnings_issued_guard.py, next to the existing kwargs-moving tests, which use a realSFTConfigbecausenew_initbranches onisinstance(training_args, TrainingArguments).Before the change:
After:
tests/python/test_mlx_public_trainer_api.pyandtests/version_compat/test_trl_grpo_pinned_symbols.pyalso exercise this wrapper: 871 passed, 177 skipped, with one failure (test_mlx_training_arguments_normalize_optim_and_object_aliases) that is present onmainunchanged and unrelated to this.One test-helper change
_sft_config()now importsSFTConfigfromtrl.trainer.sft_configrather than readingtrl.SFTConfig. On Apple Silicon theimport unslothintests/conftest.pyrebinds the top-level name to the MLX training config, which carries none ofSFTConfig's fields, so three tests in this file fail there onmaintoday:The two names are the same object everywhere else, so this is a no-op on CI and makes the helper's own comment ("a real trl config, not a stand-in") true on macOS too.