Repository navigation
Description
Environment: unsloth 2026.6.9 · transformers 5.5.0 · torch 2.12.1+cu130 · Python 3.11 · Linux
Summary
transformers has deprecated the whole modeling_attn_mask_utils module in favor of masking_utils, with removal scheduled for v5.10 per the FutureWarning:
The attention mask API under
transformers.modeling_attn_mask_utils(AttentionMaskConverter) is deprecated and will be removed in Transformers v5.10. Please use the new API intransformers.masking_utils.
transformers 5.5.0 itself no longer references AttentionMaskConverter outside the shim module: its own models have migrated. unsloth still imports the deprecated module in 9 files / 10 sites, and these are live code paths, not dead imports: the FutureWarnings fire from inside the forward pass during a standard QLoRA training run. Today that is warning noise in every training log; when v5.10 lands, the 8 top-level imports raise at import time. unsloth/models/llama.py is one of them, so FastLanguageModel would break outright on that transformers version.
Affected imports (line numbers as of current main)
| File | Symbol | Style |
|---|---|---|
unsloth/models/llama.py:74 |
_prepare_4d_causal_attention_mask_for_sdpa |
top-level |
unsloth/models/qwen3.py:49 |
_prepare_4d_causal_attention_mask_for_sdpa |
top-level |
unsloth/models/gemma.py:47 |
_prepare_4d_causal_attention_mask_for_sdpa |
top-level |
unsloth/models/gemma2.py:53 |
_prepare_4d_causal_attention_mask_for_sdpa |
top-level |
unsloth/models/granite.py:53 |
_prepare_4d_causal_attention_mask_for_sdpa |
top-level |
unsloth/models/cohere.py:47 |
_prepare_4d_causal_attention_mask_for_sdpa |
top-level |
unsloth/models/falcon_h1.py:53 |
_prepare_4d_causal_attention_mask_for_sdpa |
top-level |
unsloth/models/sentence_transformer.py:34 |
_prepare_4d_attention_mask_for_sdpa |
top-level |
unsloth/models/llama.py:1094 |
AttentionMaskConverter (SWA mask construction) |
inline |
unsloth/models/_utils.py:2421 |
AttentionMaskConverter (mask verification sweep) |
inline |
Verify with grep -rn "modeling_attn_mask_utils" unsloth/ from the repo root.
Why not pin transformers below 5.10
Works as a stopgap, but it permanently caps the supported transformers range, and the deprecated surface is small and well defined right now.
Proposed fix (happy to PR)
A single version-gated compat module, e.g. unsloth/models/_attn_mask_compat.py, exporting the three symbols: use masking_utils where available, fall back to the old module on older transformers. The 9 files then import from the compat module, so behavior on currently supported transformers versions is unchanged and there is one place to test.
Note the new API is not signature-compatible (create_causal_mask takes config / input embeds / cache position rather than mask + input shape + past length), so the compat layer adapts signatures rather than aliasing names. Since a wrong attention mask fails silently, the PR would include an equivalence test comparing old vs new mask outputs across a grid of sequence lengths, past lengths, and sliding-window sizes (same spirit as the existing sweep in _utils.py).
Question for maintainers
Is this migration already on your roadmap as part of a larger attention refactor? If so, close away. If you would take an outside PR, does the compat-shim approach work for you, or would you prefer a direct per-file migration to masking_utils?
Activity
Taranum01 commentedon Jul 4, 2026
I'd like to work on this — opened PR #6880 with a local
_attn_mask_compatmodule that replaces all directtransformers.modeling_attn_mask_utilsimports and adds equivalence tests against the legacy Transformers implementation (25/25 passing locally on transformers 5.13.0).Happy to adjust the approach if maintainers prefer a direct migration to
masking_utilsinstead of the compat shim.Exile404 commentedon Jul 5, 2026
Let's work together if they approve it
fix: replace deprecated transformers attention mask imports (#6880)