Refactor CLI [8/N]: Refactor scripts/utils with delayed imports#5209
Merged
albertvillanova merged 2 commits intohuggingface:mainfrom Mar 5, 2026
Merged
Refactor CLI [8/N]: Refactor scripts/utils with delayed imports#5209albertvillanova merged 2 commits intohuggingface:mainfrom
albertvillanova merged 2 commits intohuggingface:mainfrom
Conversation
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.
Refactor scripts/utils with delayed imports
This PR refactors the
trl/scripts/utils.pyfile to improve import management and ensure compatibility with type checking and dataset handling. The main focus is on moving imports inside functions to reduce unnecessary dependencies during module load, using string-based type annotations for better type checking, and updating dataset-related code for clarity and correctness.Import management and type checking improvements
datasetsandyamlinside relevant functions to reduce top-level dependencies and speed up module loading."DatasetDict"in theget_datasetfunction signature to improve compatibility with static type checkers and avoid runtime import issues.Dataset handling updates
concatenate_datasetsandDatasetDictto use thedatasetsmodule namespace, ensuring clarity and correctness in dataset operations.Other minor improvements
is_rich_availableinside theinit_zero_verbosefunction to further reduce top-level imports and improve modularity.