Refactor CLI [9/N]: Replace HfArgumentParser from transformers with local#5210
Merged
albertvillanova merged 8 commits intohuggingface:mainfrom Mar 5, 2026
Merged
Conversation
Member
|
does it mean that when huggingface/transformers#44273 is solved, we could just revert this commit? |
Member
Author
|
Thanks for your review, @qgallouedec. Not exactly, because we still support older versions of transformers where the import latency is not fixed. Instead, we could make a conditional import depending on the transformers version. |
Member
|
I'd recommend at least a comment explaining that it's copied from transformers and modified because of the latency (you already did it) +
up to you |
qgallouedec
approved these changes
Mar 5, 2026
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
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.
Replace HfArgumentParser from transformers with local.
This PR updates the import statements in
trl/scripts/utils.pyto use local versions of argument parsing utilities instead of those from the externaltransformerslibrary. This change helps improving latency within the codebase.The latency of
import trl.scripts.utilschanges from7.5sto<0.5safter the merge of:See upstream issue:
Dependency management:
HfArgumentParser,DataClass, andDataClassTypefrom thetransformerslibrary with imports from the localtrl.scripts._hf_argparsermodule.Note
Medium Risk
Although intended as a drop-in copy, vendoring core CLI argument parsing code can subtly change parsing behavior and may drift from upstream fixes, impacting script configuration/flag handling.
Overview
Introduces a vendored copy of
transformers’hf_argparserastrl/scripts/_hf_argparser.py, withyamlimported lazily inparse_yaml_fileto avoid the upstream import-time latency.Updates
trl/scripts/utils.pyto importHfArgumentParser/DataClass/DataClassTypefrom the local module instead oftransformers, keeping CLI parsing behavior local and reducing startup overhead.Written by Cursor Bugbot for commit 2e15b40. This will update automatically on new commits. Configure here.