Fix TrainingArguments to config conversion in _backwards_compatible_trainer
The isinstance guard checked against TrainingArguments, but all TRL config classes (DPOConfig, GRPOConfig, SFTConfig, etc.) inherit from it, so the check was always True and the conversion branch was never reached. When a user passed plain TrainingArguments to DPOTrainer, it was forwarded as-is, causing AttributeError on config-specific attributes like padding_value. Check against config_class instead so plain TrainingArguments is properly converted while already-correct configs pass through unchanged. This preserves the GRPO/RLOO mutual-exclusivity guard since those configs are not re-initialized. Fixes #4155
This commit is contained in:
parent
11449208f4
commit
962e0f0d35
1 changed files with 7 additions and 4 deletions
|
|
@ -302,11 +302,14 @@ def _backwards_compatible_trainer(trainer_class, config_class):
|
|||
# Reinitialising config class with parameters (that were none initially but populated on first init)
|
||||
# causes the 2nd init to fail as there are mutual exclusive checks on pairs of parameters.
|
||||
# Refer: https://github.com/huggingface/trl/blob/main/trl/trainer/grpo_config.py#L499-L502 for example
|
||||
# So we only create config class if the previous init was not TrainingArguments
|
||||
if not isinstance(training_args, TrainingArguments):
|
||||
config = config_class(**config_dict)
|
||||
else:
|
||||
# So we only create config class if training_args is not already the correct type.
|
||||
# We check against config_class (not TrainingArguments) because all TRL configs
|
||||
# (DPOConfig, GRPOConfig, etc.) are subclasses of TrainingArguments, so isinstance
|
||||
# against TrainingArguments is always True and never triggers conversion.
|
||||
if isinstance(training_args, config_class):
|
||||
config = training_args
|
||||
else:
|
||||
config = config_class(**config_dict)
|
||||
|
||||
# Reconstruct kwargs for Trainer
|
||||
kwargs = trainer_kwargs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue