Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

Refactor suppression of warning at experimental import#4629

Merged
qgallouedec merged 2 commits intohuggingface:mainfrom
albertvillanova:refactor-experimental-access-warning
Dec 5, 2025
Merged

Refactor suppression of warning at experimental import#4629
qgallouedec merged 2 commits intohuggingface:mainfrom
albertvillanova:refactor-experimental-access-warning

Conversation

@albertvillanova
Copy link
Member

@albertvillanova albertvillanova commented Dec 5, 2025

Refactor experimental warning suppression,

This PR refactors how to suppress warnings during imports from trl.experimental: instead of setting a temporary environment variable, it uses a localized warning filter.

Why this is better:

  • Scoped suppression: warnings.catch_warnings() confines changes to the import block, avoiding global or process-wide side effects.
  • No environment coupling: Avoids manipulating env variables that can leak into subprocesses, tests, or other modules unintentionally.
  • Precision: Filters a specific warning category instead of implicitly affecting code paths that read env variables.
  • Thread-safety and reentrancy: Context-manager based filters are safer in concurrent scenarios than shared env state.

Experimental warning handling improvements:

  • Added a custom warning class TRLExperimentalWarning in trl/import_utils.py to distinguish experimental API warnings from generic user warnings.
  • Replaced the use of the temporary_env context manager (resetting the environment variable TRL_EXPERIMENTAL_SILENCE) with a new suppress_experimental_warning context manager throughout the codebase, including all trainer and config modules.
  • Updated the warning issued in trl/experimental/__init__.py to use the new TRLExperimentalWarning class instead of the generic UserWarning.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
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.

better!

@qgallouedec
Copy link
Member

I'm merging this one so that I can use it in #4575

@qgallouedec qgallouedec merged commit 937b64e into huggingface:main Dec 5, 2025
10 of 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.

3 participants