Skip to content

Conversation

fsndzomga
Copy link
Contributor

Fixes compatibility issue with TRL >= 0.16.0 where SFTConfig parameter changed from max_seq_length to max_length.

Added dynamic parameter detection to support both old and new TRL versions.

Fixes #8762

- Add compatibility layer for TRL versions >= 0.16.0 that use 'max_length' instead of 'max_seq_length'
- Dynamically detect which parameter is supported by inspecting SFTConfig signature
- Maintains backward compatibility with older TRL versions
- Fixes TypeError: SFTConfig.__init__() got an unexpected keyword argument 'max_seq_length'

Resolves stanfordnlp#8762
- Remove trailing whitespace
- Fix line spacing consistency
Copy link
Collaborator

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

# Add the sequence length parameter using the appropriate name for the TRL version
if "max_seq_length" in sft_config_params:
# Older TRL versions (< 0.16.0)
config_kwargs["max_seq_length"] = train_kwargs["max_seq_length"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that the user is setting max_length instead of max_seq_length, then max_length will go nowhere.

Instead of this silent transformation, can we raise an error on detecting mismatch between train_kwargs and SFTConfig on the name of max length? The error can be something like "max_seq_length is replaced by max_length in trl>=0.16.0, but you set ... on trl={the_detected_version}"

Copy link
Contributor Author

@fsndzomga fsndzomga Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thank you for the feedback. After thinking about this, I’ve come to the conclusion that it’s probably better to just let the code fail as it currently does, and let the user either install the correct version of trl or update the current implementation in DSPy to work only with the latest trl API and fail otherwise. In both cases, we should specify which version of trl is recommended and perhaps include a check for it. Otherwise it becomes a maintenance mess if trl API changes again in the future ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] TypeError: SFTConfig.__init__() got an unexpected keyword argument 'max_seq_length'
2 participants