Skip to content

cleanup: remove dead SDPA patches#3488

Open
OnePunchMonk wants to merge 1 commit intoaxolotl-ai-cloud:mainfrom
OnePunchMonk:cleanup/remove-dead-sdpa-patches
Open

cleanup: remove dead SDPA patches#3488
OnePunchMonk wants to merge 1 commit intoaxolotl-ai-cloud:mainfrom
OnePunchMonk:cleanup/remove-dead-sdpa-patches

Conversation

@OnePunchMonk
Copy link

@OnePunchMonk OnePunchMonk commented Mar 11, 2026

Transformers 5.x routes attention through sdpa_attention.py and no longer calls the _prepare_4d_causal_attention_mask* or _expand_mask functions that these patches targeted. This makes the following patches dead code:

  • llama_patch_multipack.py (patched _prepare_4d_causal_attention_mask*)
  • llama_expand_mask.py (patched _expand_mask, never called)
  • Related utility functions in monkeypatch/utils.py

Closes #3331

Description

Motivation and Context

How has this been tested?

AI Usage Disclaimer

Claude

Screenshots (if appropriate)

Types of changes

Social Handles (Optional)

Summary by CodeRabbit

  • Refactor
    • Removed Llama model-specific attention mask patches and related utility functions.
    • Removed expand_mask test suite and configuration entries.

Transformers 5.x routes attention through sdpa_attention.py and no longer
calls the _prepare_4d_causal_attention_mask* or _expand_mask functions that
these patches targeted. This makes the following patches dead code:

- llama_patch_multipack.py (patched _prepare_4d_causal_attention_mask*)
- llama_expand_mask.py (patched _expand_mask, never called)
- Related utility functions in monkeypatch/utils.py

Closes axolotl-ai-cloud#3331
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 02e7f832-499a-41b6-a9fe-0396d0a791b8

📥 Commits

Reviewing files that changed from the base of the PR and between 23ad40b and 3118b1a.

📒 Files selected for processing (6)
  • _quarto.yml
  • src/axolotl/loaders/patch_manager.py
  • src/axolotl/monkeypatch/llama_expand_mask.py
  • src/axolotl/monkeypatch/llama_patch_multipack.py
  • src/axolotl/monkeypatch/utils.py
  • tests/test_expand_mask.py
💤 Files with no reviewable changes (5)
  • _quarto.yml
  • tests/test_expand_mask.py
  • src/axolotl/loaders/patch_manager.py
  • src/axolotl/monkeypatch/llama_expand_mask.py
  • src/axolotl/monkeypatch/llama_patch_multipack.py

📝 Walkthrough

Walkthrough

This PR removes deprecated Llama monkeypatch utilities and sample-packing logic that are no longer used by Transformers. The changes include deletion of llama_expand_mask.py and llama_patch_multipack.py modules, removal of related helper functions from utils.py, removal of sample-packing invocation from PatchManager, and deletion of associated tests.

Changes

Cohort / File(s) Summary
Configuration
_quarto.yml
Removed two monkeypatch entries (llama_expand_mask and llama_patch_multipack) from documentation.
Patch Manager
src/axolotl/loaders/patch_manager.py
Removed _patch_llama_sample_packing method and its invocation in _patch_llama_derived_model, eliminating sample-packing-specific patching logic for llama-derived models.
Monkeypatch Modules
src/axolotl/monkeypatch/llama_expand_mask.py, src/axolotl/monkeypatch/llama_patch_multipack.py, src/axolotl/monkeypatch/utils.py
Deleted llama_expand_mask.py and llama_patch_multipack.py entirely. Removed three utility functions from utils.py: mask_2d_to_4d, patched_prepare_4d_causal_attention_mask, and patched_prepare_4d_causal_attention_mask_for_sdpa.
Tests
tests/test_expand_mask.py
Deleted test file for _expand_mask function including TestExpandMask test class and related test methods.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • SalmanMohammadi
  • NanoCode012
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'cleanup: remove dead SDPA patches' is concise and directly describes the main change: removing obsolete monkeypatch code related to SDPA.
Linked Issues check ✅ Passed All code changes align with issue #3331 requirements: removed llama_patch_multipack.py, llama_expand_mask.py, and related utility functions from monkeypatch/utils.py as dead code no longer called by Transformers 5.x.
Out of Scope Changes check ✅ Passed All changes are in-scope cleanups directly addressing the removal of dead SDPA patches identified in the linked issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@OnePunchMonk
Copy link
Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@OnePunchMonk OnePunchMonk marked this pull request as ready for review March 15, 2026 08:28
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.

[ Cleanup ] Remove dead sdpa patches

1 participant