Skip to content

fix(modeling_attn_mask_utils): remove FutureWarning from logger.warning_once()#44307

Merged
vasqu merged 2 commits intohuggingface:mainfrom
imstevenpmwork:fix/logger_modeling_attn_mask_utils
Feb 26, 2026
Merged

fix(modeling_attn_mask_utils): remove FutureWarning from logger.warning_once()#44307
vasqu merged 2 commits intohuggingface:mainfrom
imstevenpmwork:fix/logger_modeling_attn_mask_utils

Conversation

@imstevenpmwork
Copy link
Copy Markdown
Contributor

@imstevenpmwork imstevenpmwork commented Feb 26, 2026

What does this PR do?

This PR fixes a TypeError: not all arguments converted during string formatting caused by incorrectly passing FutureWarning as a second argument to logger.warning_once() in this file, introduced in #42848. Because Python's logging module expects string formatting arguments (like %s) rather than warning categories, passing FutureWarning without a placeholder triggered a crash when the warning evaluated.

I prioritized the use of logger.warning_once() instead of warnings.warn(msg, FutureWarning) to align with the logging patterns in similar transformers modeling_ utils files. -> This was later changed to prefer warnings for sake of preserving the FutureWarning: #44307 (comment)

I didn't test this locally, but here's a small snippet for reproduction:

>>> import logging
>>> DEPRECATION_MESSAGE = "test"
>>> logging.warning(DEPRECATION_MESSAGE)
WARNING:root:test
>>> logging.warning(DEPRECATION_MESSAGE,FutureWarning)
--- Logging error ---
Traceback (most recent call last):
  File "/Users/steven.palma/miniforge3/lib/python3.12/logging/__init__.py", line 1160, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/steven.palma/miniforge3/lib/python3.12/logging/__init__.py", line 999, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/steven.palma/miniforge3/lib/python3.12/logging/__init__.py", line 703, in format
    record.message = record.getMessage()
                     ^^^^^^^^^^^^^^^^^^^
  File "/Users/steven.palma/miniforge3/lib/python3.12/logging/__init__.py", line 392, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
TypeError: not all arguments converted during string formatting
Call stack:
  File "<stdin>", line 1, in <module>
Message: 'test'
Arguments: (<class 'FutureWarning'>,)
>>>

Here's an example of this happening in downstream libraries: https://github.com/huggingface/lerobot/actions/runs/22455225460/job/65035766998

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

  • Anyone in the community is free to review the PR once the tests have passed.
  • @vasqu @ArthurZucker

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.


def __init__(self, is_causal: bool, sliding_window: int | None = None):
logger.warning_once(DEPRECATION_MESSAGE, FutureWarning)
logger.warning_once(DEPRECATION_MESSAGE)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oops, that's on me #42848 😬

Let's use warnings.warn instead, would like to keep the future warning type in this case - we can safely remove the logger in this file then iirc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in commit: 15b3afa

Copy link
Copy Markdown
Contributor

@vasqu vasqu left a comment

Choose a reason for hiding this comment

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

Perfect, thank you

@vasqu vasqu enabled auto-merge (squash) February 26, 2026 21:27
@vasqu vasqu merged commit 98fc02e into huggingface:main Feb 26, 2026
15 checks passed
zvik pushed a commit to zvik/transformers that referenced this pull request Mar 1, 2026
…ng_once() (huggingface#44307)

* fix(modeling_attn_mask_utils): remove FutureWarning from logger.warning_once()

* refactor(modeling_attn_mask_utils): use warnings instead of logger
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