Skip to content

Deprecated modeling_attn_mask_utils imports break on transformers v5.10 #6860

Closed

Description

@Exile404

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 in transformers.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

  1. added
    feature request
    on Jul 4, 2026
  2. Taranum01 commented on Jul 4, 2026

    @Taranum01
    Contributor

    I'd like to work on this — opened PR #6880 with a local _attn_mask_compat module that replaces all direct transformers.modeling_attn_mask_utils imports 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_utils instead of the compat shim.

  3. Exile404 commented on Jul 5, 2026

    @Exile404
    Author

    Let's work together if they approve it

  4. added a commit that references this issue on Jul 31, 2026
    7367955
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions