Skip to content

metal-flash-attention integration#2808

Open
bghira wants to merge 1 commit into
mainfrom
feature/apple-flash-attn
Open

metal-flash-attention integration#2808
bghira wants to merge 1 commit into
mainfrom
feature/apple-flash-attn

Conversation

@bghira

@bghira bghira commented Jul 8, 2026

Copy link
Copy Markdown
Owner

This pull request updates the documentation for the attention mechanism options in multiple languages to add support for the metal-flash-attention backend. This backend enables the use of Universal Metal Flash Attention (UMFA) on Apple Silicon, and the documentation now describes its installation and usage. All command-line usage examples and option lists are updated accordingly.

The most important changes are:

Addition of metal-flash-attention backend:

  • Added metal-flash-attention as a supported value for the --attention_mechanism option in all language variants of the documentation (OPTIONS.md, OPTIONS.es.md, OPTIONS.pt-BR.md, OPTIONS.ja.md, OPTIONS.zh.md, and their respective usage/option sections). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17]

Documentation details for metal-flash-attention:

  • Provided backend-specific installation and usage instructions for metal-flash-attention in all supported languages, including requirements for Apple Silicon, UMFA package installation, dispatch details, and parity checks with PyTorch SDPA. [1] [2] [3] [4] [5] [6]

These updates ensure that users on Apple Silicon are aware of the new, optimized attention backend and understand how to enable and verify it in their training workflows.

Copilot AI left a comment

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.

Pull request overview

This pull request introduces and documents a new metal-flash-attention attention backend, intended to enable Universal Metal Flash Attention (UMFA) on Apple Silicon, and wires it into CLI/WebUI validation plus the attention backend controller.

Changes:

  • Add a new Metal/UMFA-backed SDPA wrapper (metal-flash-attention) with availability + runtime parity checks.
  • Extend CLI argument normalization and WebUI validation to surface actionable errors when UMFA is unavailable.
  • Update OPTIONS.md (and translations) to include metal-flash-attention in option lists and provide setup/usage guidance.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_attention_backend.py Adds unit tests covering UMFA availability checks, wrapper install/fallback behavior, and runtime-check failure handling.
simpletuner/helpers/training/attention_backend.py Implements UMFA availability probing, runtime parity check, and an SDPA wrapper that dispatches to metal_sdpa_extension on eligible MPS calls.
simpletuner/helpers/configuration/cmd_args.py Updates CLI normalization/validation to allow metal-flash-attention on non-CUDA and to error when UMFA is not usable.
simpletuner/simpletuner_sdk/server/services/validation_service.py Adds WebUI-side validation error messaging when metal-flash-attention is selected but UMFA is unavailable.
simpletuner/simpletuner_sdk/server/services/field_registry/sections/advanced.py Adds metal-flash-attention to the Advanced attention mechanism choices and updates tooltip guidance.
documentation/OPTIONS.md Documents metal-flash-attention behavior, installation, and adds it to usage/option lists.
documentation/OPTIONS.es.md Spanish translation updates for the new backend + option list inclusion.
documentation/OPTIONS.pt-BR.md Portuguese (Brazil) translation updates for the new backend + option list inclusion.
documentation/OPTIONS.ja.md Japanese translation updates for the new backend + option list inclusion.
documentation/OPTIONS.zh.md Chinese translation updates for the new backend + option list inclusion.
documentation/OPTIONS.hi.md Hindi translation updates for the new backend + option list inclusion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +417 to +420
try:
package = importlib.import_module("pytorch_custom_op_ffi")
except ImportError:
return "Could not import the UMFA PyTorch custom-op package."
Comment on lines +432 to +435
try:
extension = importlib.import_module("metal_sdpa_extension")
except ImportError:
return "Could not import metal_sdpa_extension from the UMFA PyTorch custom-op package."
Comment on lines +1333 to 1334
if normalized_attention_mech not in non_cuda_supported_mechanisms and not torch.cuda.is_available():
warning_log("For non-CUDA systems, only Diffusers attention mechanism is officially supported.")
"Install it with: pip install sageattention",
)

if attention_mech.replace("_", "-") == "metal-flash-attention":
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.

2 participants