metal-flash-attention integration#2808
Open
bghira wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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 includemetal-flash-attentionin 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": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request updates the documentation for the attention mechanism options in multiple languages to add support for the
metal-flash-attentionbackend. 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-attentionbackend:metal-flash-attentionas a supported value for the--attention_mechanismoption 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:metal-flash-attentionin 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.