Fix num_train_epochs=None causing TypeError in GRPOConfig (#3972)
When users pass `num_train_epochs=None` to GRPOConfig (relying on
max_steps to control training duration), Trainer.__init__ fails with:
TypeError: '>' not supported between instances of 'NoneType' and 'int'
This happens because transformers.Trainer does `args.num_train_epochs > 0`
in its __init__ which fails when the value is None.
This fix converts None to 3.0 (the default) before Trainer initialization.
The actual training duration is still controlled by max_steps since it
takes precedence when both are set.
Example that now works:
```python
config = GRPOConfig(
num_train_epochs=None, # Previously caused TypeError
max_steps=500, # This controls actual duration
...
)
```
This commit is contained in:
parent
586a5b046d
commit
9cc8417465
1 changed files with 9 additions and 0 deletions
|
|
@ -891,6 +891,15 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):
|
|||
)
|
||||
extra_args += learning_rate_check
|
||||
|
||||
# Fix num_train_epochs = None causing TypeError in Trainer.__init__
|
||||
# Trainer does `args.num_train_epochs > 0` which fails when None
|
||||
if "num_train_epochs" in call_args:
|
||||
num_train_epochs_check = (
|
||||
"if num_train_epochs is None:\n"
|
||||
" num_train_epochs = 3.0 # Default to 3 epochs if None, max_steps will override\n"
|
||||
)
|
||||
extra_args += num_train_epochs_check
|
||||
|
||||
# Check if max_seq_length is NOT defined (max_length is now default)
|
||||
if "max_seq_length" not in call_args and "max_length" in call_args:
|
||||
max_seq_length_pre = """max_seq_length : Optional[int] = field(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue