Skip to content

Refactor CLI [8/N]: Refactor scripts/utils with delayed imports#5209

Merged
albertvillanova merged 2 commits intohuggingface:mainfrom
albertvillanova:refactor-cli-8
Mar 5, 2026
Merged

Refactor CLI [8/N]: Refactor scripts/utils with delayed imports#5209
albertvillanova merged 2 commits intohuggingface:mainfrom
albertvillanova:refactor-cli-8

Conversation

@albertvillanova
Copy link
Copy Markdown
Member

Refactor scripts/utils with delayed imports

This PR refactors the trl/scripts/utils.py file 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

  • Moved imports for datasets and yaml inside relevant functions to reduce top-level dependencies and speed up module loading.
  • Used string-based type annotation "DatasetDict" in the get_dataset function signature to improve compatibility with static type checkers and avoid runtime import issues.

Dataset handling updates

  • Updated calls to concatenate_datasets and DatasetDict to use the datasets module namespace, ensuring clarity and correctness in dataset operations.

Other minor improvements

  • Moved the import for is_rich_available inside the init_zero_verbose function to further reduce top-level imports and improve modularity.

Copy link
Copy Markdown
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

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

LGTM

@albertvillanova albertvillanova merged commit 6b02b2e into huggingface:main Mar 5, 2026
11 checks passed
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