Skip to content

Refactor CLI [7/N]: Move patching to compat and import transformers conditionally#5208

Merged
albertvillanova merged 3 commits intohuggingface:mainfrom
albertvillanova:refactor-cli-7
Mar 3, 2026
Merged

Refactor CLI [7/N]: Move patching to compat and import transformers conditionally#5208
albertvillanova merged 3 commits intohuggingface:mainfrom
albertvillanova:refactor-cli-7

Conversation

@albertvillanova
Copy link
Copy Markdown
Member

@albertvillanova albertvillanova commented Mar 3, 2026

Move patching to _compat and import transformers conditionally:

Note that currently, importing transformers unconditionally, increases latency even if the patch is not necessary. See upstream issue:

This PR refactors the way compatibility with older versions of the transformers and accelerate libraries is handled, specifically regarding the ParallelismConfig symbol. The patch moves the compatibility workaround for ParallelismConfig from trl/scripts/utils.py to a more appropriate location in trl/_compat.py, and improves its implementation by adding version checks and error handling.

Transformers/Accelerate Compatibility Improvements:

  • Added a new function _patch_transformers_parallelism_config in trl/_compat.py to ensure transformers.training_args.ParallelismConfig is defined only when both transformers<4.57.0 and accelerate<1.10.1 are installed, preventing NameError during type hint resolution. The function includes error handling and a detailed docstring explaining its purpose and upstream context.
  • Removed the previous unconditional workaround function _ensure_transformers_parallelism_config from trl/scripts/utils.py, as this logic is now handled (with improvements) in trl/_compat.py.

@albertvillanova albertvillanova merged commit d24ec77 into huggingface:main Mar 3, 2026
11 checks passed
catherinelee274 pushed a commit to catherinelee274/trl that referenced this pull request Apr 17, 2026
songhappy pushed a commit to songhappy/trl that referenced this pull request Apr 20, 2026
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.

2 participants