mxflashattn 1.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mxflashattn-1.4.0/CONTRIBUTING.md +22 -0
- mxflashattn-1.4.0/LICENSE +201 -0
- mxflashattn-1.4.0/MANIFEST.in +10 -0
- mxflashattn-1.4.0/PKG-INFO +242 -0
- mxflashattn-1.4.0/README.md +220 -0
- mxflashattn-1.4.0/benchmarks/__init__.py +1 -0
- mxflashattn-1.4.0/benchmarks/compare.py +105 -0
- mxflashattn-1.4.0/benchmarks/configs/c500.yaml +10 -0
- mxflashattn-1.4.0/benchmarks/fair_matrix.py +191 -0
- mxflashattn-1.4.0/benchmarks/fair_report.py +71 -0
- mxflashattn-1.4.0/benchmarks/model_fair_report.py +60 -0
- mxflashattn-1.4.0/benchmarks/plot_summary.py +119 -0
- mxflashattn-1.4.0/benchmarks/report.py +139 -0
- mxflashattn-1.4.0/benchmarks/run.py +328 -0
- mxflashattn-1.4.0/csrc/mxmac/CMakeLists.txt +13 -0
- mxflashattn-1.4.0/csrc/mxmac/attention.h +43 -0
- mxflashattn-1.4.0/csrc/mxmac/attention_forward.cpp +116 -0
- mxflashattn-1.4.0/csrc/mxmac/paged_kv.cpp +126 -0
- mxflashattn-1.4.0/csrc/mxmac/workspace.cpp +11 -0
- mxflashattn-1.4.0/docs/API.md +71 -0
- mxflashattn-1.4.0/docs/C500_MINIMAL_RUNBOOK.md +31 -0
- mxflashattn-1.4.0/docs/C500_V14_EXPERIMENT_PLAN.md +77 -0
- mxflashattn-1.4.0/docs/C500_V14_VALIDATION_20261017.md +142 -0
- mxflashattn-1.4.0/docs/C500_VALIDATION_RUNBOOK.md +169 -0
- mxflashattn-1.4.0/docs/GIT_WORKFLOW.md +59 -0
- mxflashattn-1.4.0/docs/RELEASE_LAYOUT.md +35 -0
- mxflashattn-1.4.0/docs/TECHNICAL_NOTES.md +56 -0
- mxflashattn-1.4.0/docs/V1.4.0_DEV_PLAN.md +80 -0
- mxflashattn-1.4.0/docs/V1.5_OPTIMIZATION_PLAN.md +840 -0
- mxflashattn-1.4.0/docs/gate4/E2E_/345/244/247/346/250/241/345/236/213/344/270/216/345/256/210/345/215/253/351/252/214/350/257/201.md +471 -0
- mxflashattn-1.4.0/docs/gate4/Gate4_/345/217/202/350/200/203/346/226/207/347/214/256/344/270/216/350/260/203/347/240/224/350/256/260/345/275/225.md +95 -0
- mxflashattn-1.4.0/docs/gate4/Gate4_/346/224/266/345/256/230/346/212/245/345/221/212.md +402 -0
- mxflashattn-1.4.0/docs/gate4/M3_VLLM_WIRING.md +142 -0
- mxflashattn-1.4.0/docs/results/c500-2026-10-05.json +8467 -0
- mxflashattn-1.4.0/docs/results/c500-2026-10-05.md +411 -0
- mxflashattn-1.4.0/docs/results/c500-2026-10-13.md +52 -0
- mxflashattn-1.4.0/docs/results/c500-model-level-summary.png +0 -0
- mxflashattn-1.4.0/docs/results/c500-speedup-summary.png +0 -0
- mxflashattn-1.4.0/docs/support-matrix.md +53 -0
- mxflashattn-1.4.0/integrations/__init__.py +1 -0
- mxflashattn-1.4.0/integrations/vllm/README.md +7 -0
- mxflashattn-1.4.0/integrations/vllm/__init__.py +1 -0
- mxflashattn-1.4.0/integrations/vllm/backend.py +158 -0
- mxflashattn-1.4.0/integrations/vllm/compat.py +46 -0
- mxflashattn-1.4.0/integrations/vllm/config.py +11 -0
- mxflashattn-1.4.0/integrations/vllm/decoder_adapter.py +286 -0
- mxflashattn-1.4.0/integrations/vllm/probe_compat.py +22 -0
- mxflashattn-1.4.0/integrations/vllm/probe_decoder_layout.py +91 -0
- mxflashattn-1.4.0/integrations/vllm/probe_registration.py +24 -0
- mxflashattn-1.4.0/integrations/vllm/probe_v017.py +55 -0
- mxflashattn-1.4.0/integrations/vllm/smoke_generate.py +190 -0
- mxflashattn-1.4.0/integrations/vllm/vllm_plugin.py +511 -0
- mxflashattn-1.4.0/mxflashattn/__init__.py +30 -0
- mxflashattn-1.4.0/mxflashattn/accuracy.py +51 -0
- mxflashattn-1.4.0/mxflashattn/api.py +286 -0
- mxflashattn-1.4.0/mxflashattn/dispatch.py +172 -0
- mxflashattn-1.4.0/mxflashattn/policy.py +111 -0
- mxflashattn-1.4.0/mxflashattn/prefill.py +108 -0
- mxflashattn-1.4.0/mxflashattn/reference.py +139 -0
- mxflashattn-1.4.0/mxflashattn/validation.py +100 -0
- mxflashattn-1.4.0/mxflashattn.egg-info/PKG-INFO +242 -0
- mxflashattn-1.4.0/mxflashattn.egg-info/SOURCES.txt +82 -0
- mxflashattn-1.4.0/mxflashattn.egg-info/dependency_links.txt +1 -0
- mxflashattn-1.4.0/mxflashattn.egg-info/requires.txt +12 -0
- mxflashattn-1.4.0/mxflashattn.egg-info/top_level.txt +3 -0
- mxflashattn-1.4.0/pyproject.toml +36 -0
- mxflashattn-1.4.0/requirements-c500.txt +6 -0
- mxflashattn-1.4.0/requirements-vllm.txt +3 -0
- mxflashattn-1.4.0/setup.cfg +4 -0
- mxflashattn-1.4.0/setup.py +33 -0
- mxflashattn-1.4.0/tests/test_accuracy.py +33 -0
- mxflashattn-1.4.0/tests/test_api.py +219 -0
- mxflashattn-1.4.0/tests/test_benchmark.py +202 -0
- mxflashattn-1.4.0/tests/test_c500.py +127 -0
- mxflashattn-1.4.0/tests/test_c500_plan.py +32 -0
- mxflashattn-1.4.0/tests/test_decoder_adapter.py +76 -0
- mxflashattn-1.4.0/tests/test_dispatch.py +85 -0
- mxflashattn-1.4.0/tests/test_long_context_accuracy.py +22 -0
- mxflashattn-1.4.0/tests/test_plot_summary.py +36 -0
- mxflashattn-1.4.0/tests/test_policy.py +60 -0
- mxflashattn-1.4.0/tests/test_prefill.py +54 -0
- mxflashattn-1.4.0/tests/test_vllm_bridge.py +62 -0
- mxflashattn-1.4.0/tests/test_vllm_compat.py +19 -0
- mxflashattn-1.4.0/tests/test_vllm_official_split_fallback.py +37 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Contributions should include focused tests, documentation for new supported behavior, and a clear statement of which backend was exercised.
|
|
4
|
+
|
|
5
|
+
## Local Checks
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python -m pip install -e ".[dev]"
|
|
9
|
+
python -m pytest
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## C500 Results
|
|
13
|
+
|
|
14
|
+
Do not report C500 support or performance from CPU tests. Include the C500 model, driver, MXMACA runtime, vendor PyTorch, compiler, and vLLM versions with native test results. Preserve the generated JSON and Markdown report. Never replace a native failure with an unreported reference fallback.
|
|
15
|
+
|
|
16
|
+
## Scope
|
|
17
|
+
|
|
18
|
+
The initial public surface is forward-only FP16/BF16 attention with head dimensions 64 and 128. Backward, FP8, multi-card execution, rotary embeddings, ALiBi, and local windows are outside the verified support matrix.
|
|
19
|
+
|
|
20
|
+
## Licensing
|
|
21
|
+
|
|
22
|
+
New code is contributed under Apache-2.0. List third-party code, generated assets, model weights, and benchmark datasets with their source and license; do not copy them into the repository without permission.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [MXFlashAttn contributors]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include CONTRIBUTING.md
|
|
4
|
+
include requirements-c500.txt
|
|
5
|
+
include requirements-vllm.txt
|
|
6
|
+
recursive-include csrc/mxmac *.cpp *.h CMakeLists.txt
|
|
7
|
+
recursive-include benchmarks *.py *.yaml
|
|
8
|
+
recursive-include docs *.md *.json *.png
|
|
9
|
+
recursive-include integrations *.py *.md
|
|
10
|
+
recursive-include tests *.py
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mxflashattn
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: FlashAttention-compatible forward APIs and MXMACA bring-up backend
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: torch>=2.4
|
|
13
|
+
Requires-Dist: PyYAML<7,>=6.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest<10,>=8; extra == "dev"
|
|
16
|
+
Requires-Dist: ruff<1,>=0.6; extra == "dev"
|
|
17
|
+
Provides-Extra: vllm
|
|
18
|
+
Requires-Dist: vllm==0.17.0; extra == "vllm"
|
|
19
|
+
Provides-Extra: reports
|
|
20
|
+
Requires-Dist: matplotlib<4,>=3.8; extra == "reports"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# MXFlashAttn
|
|
24
|
+
|
|
25
|
+
> **状态(2026-10-17):v1.4.0 C500 发布候选版本。**
|
|
26
|
+
> 已完成 C500 上的算子、真实 vLLM 0.17.0 生成、dispatch、回退和近 16K 长上下文回归;
|
|
27
|
+
> 生产加速范围仍限定为 M1 Split-KV Decode,不宣称 Prefill 生产加速。
|
|
28
|
+
>
|
|
29
|
+
> **项目边界:**这是面向 MXMACA/MetaX C500 的专项适配与 decode 优化工程,
|
|
30
|
+
> 不是跨硬件 FlashAttention 替代品,也不是 MXAttention(MXFP4)复现。
|
|
31
|
+
|
|
32
|
+
中文说明 · **[English](README.en.md)**
|
|
33
|
+
|
|
34
|
+
MXFlashAttn 是面向 **MXMACA / MetaX C500** 的 FlashAttention 兼容前向算子与推理适配项目。
|
|
35
|
+
v1.3.0 起包含**自研 device kernel**(`csrc_native/m1_kernel.cpp`,split-KV paged decode)。
|
|
36
|
+
v1.4.0 在 v1.3.0 基础上完成了 C500 验证和长上下文回归。2026-10-17 的复测中,
|
|
37
|
+
Qwen3-4B 在 batch=32、max_tokens=1024 的长上下文 decode 场景相对本项目 v7 路径达到约
|
|
38
|
+
**3.66×** 吞吐;Qwen3-8B 在 batch=16、max_tokens=256 时约 **1.37×**。跨模型结果表明收益依赖模型、
|
|
39
|
+
batch 和 KV 长度,短序列或低并发不保证加速。
|
|
40
|
+
|
|
41
|
+
[](https://github.com/leo1852098393-blip/MXFlashAttn/actions/workflows/ci.yml)
|
|
42
|
+
[](LICENSE)
|
|
43
|
+
[](pyproject.toml)
|
|
44
|
+
|
|
45
|
+
## 2026-10-13 C500 复测结果(申报主口径/历史对照)
|
|
46
|
+
|
|
47
|
+
环境:MetaX C500 64G、MACA 3.5.3.20、驱动 3.8.30、PyTorch
|
|
48
|
+
`2.8.0+metax3.5.3.9`、vLLM 0.17.0。所有 M1 结果均由 dispatch 日志确认进入
|
|
49
|
+
`m1_split_decode`。
|
|
50
|
+
|
|
51
|
+
| 模型与场景 | v7 | M1-UM2 | 相对 v7 |
|
|
52
|
+
| --- | ---: | ---: | ---: |
|
|
53
|
+
| Qwen3-4B,batch=128,256 token | 1375.59 tok/s | 4554.69 tok/s | **3.31×** |
|
|
54
|
+
| Qwen3-4B,batch=32,1024 token | 359.82 tok/s | 1293.48 tok/s | **3.59×** |
|
|
55
|
+
| Qwen3-8B,batch=16,256 token | 500.79 tok/s | 703.06 tok/s | **1.40×** |
|
|
56
|
+
| PaddleOCR-VL,batch=16,64 token | 281.73 tok/s | 334.71 tok/s | **1.19×** |
|
|
57
|
+
|
|
58
|
+
本轮最新复测为 Qwen3-4B `v7=357.76`、`M1-UM2=1309.15 tok/s`(约 **3.66×**),
|
|
59
|
+
Qwen3-8B `v7=508.48`、`M1-UM2=695.45 tok/s`(约 **1.37×**)。
|
|
60
|
+
这些数字只描述表中 C500 配置,不外推为所有模型或所有请求形态的固定倍率。
|
|
61
|
+
另已完成 Qwen3-4B 真实 15,000 token prompt、`max_model_len=16384` 的
|
|
62
|
+
vendor prefill + M1 decode 回归,生成 32 token 成功且 M1 dispatch 命中。
|
|
63
|
+
流式 TTFT/P95 采集链路已验证,但 candidate 记录没有 M1 dispatch 事件,
|
|
64
|
+
因此不把它写成 M1 TTFT 性能提升。
|
|
65
|
+
|
|
66
|
+
2026-10-13 的复测表仍作为申报主口径和历史对照保留在
|
|
67
|
+
[`docs/results/c500-2026-10-13.md`](docs/results/c500-2026-10-13.md)。
|
|
68
|
+
|
|
69
|
+
2026-10-07 Gate 4 的更大场景矩阵(包括 3.67×、6.48× 等数字)保留在历史报告中,
|
|
70
|
+
用于说明研发过程与形状覆盖,不与本轮复测混成同一组结果:
|
|
71
|
+
[`docs/gate4/Gate4_收官报告.md`](docs/gate4/Gate4_收官报告.md)。
|
|
72
|
+
|
|
73
|
+
支持形状 `{GQ in {2,4,8} x HD in {64,128}}` 的**全部6 个格子均有真实模型 E2E 证据**;
|
|
74
|
+
M1 不支持的形状不得直接调用 binding。vLLM official-split 路径会把这些形状交还原始
|
|
75
|
+
MetaX/vendor KV-cache 实现。2026-10-13 已用 Qwen3.5-9B(head_dim=256)验证:
|
|
76
|
+
真实生成成功、M1 dispatch=0、M1-UM/M1-UM2 均为 4/4 文本匹配。
|
|
77
|
+
|
|
78
|
+
新一轮原始证据和报告位于申报工作空间的本地目录 `02_evidence/c500_20261013/`;
|
|
79
|
+
公开仓库内的历史 Gate 4 证据见
|
|
80
|
+
[`docs/gate4/E2E_大模型与守卫验证.md`](docs/gate4/E2E_大模型与守卫验证.md)。
|
|
81
|
+
|
|
82
|
+
## 快速复现(需要 C500)
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
export MACA_PATH=/opt/maca # 缺这一行 triton import 会报NoneType
|
|
86
|
+
bash csrc_native/build_m1.sh # mxcc 编译 M1,产出 csrc_native/mxmmain.so
|
|
87
|
+
python csrc_native/patch_plugin.py # 把 M1 接线打进 vLLM 插件(幂等)
|
|
88
|
+
python csrc_native/test_m1.py # 稳健性矩阵:s1~s8192 / GQA 2,4,8 / bf16 / ovf
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
端到端基准(注意四个环境变量,缺任一项会静默全走 vendor 直连,三路对比退化为同一路径跑三遍):
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
export MXFLASHATTN_GRAPH_OFFICIAL_SPLIT=1 MXFA_NATIVE_DECODE=1
|
|
95
|
+
export VLLM_ENABLE_V1_MULTIPROCESSING=0 # EngineCore 是子进程,否则 env 热切换无效
|
|
96
|
+
python csrc_native/bench_e2e.py --model /path/to/Qwen3-4B --batches 128 64 --max-tokens 256 --output artifacts/bench-q4b.json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**判据:先查 `dispatch.jsonl` 里 `m1_split_decode` 的事件计数,再信吞吐数字。**
|
|
100
|
+
计数为 0 说明内核根本没被派发,数据无意义。
|
|
101
|
+
|
|
102
|
+
## 能力矩阵
|
|
103
|
+
|
|
104
|
+
| 能力 | 状态 |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| FP16 / BF16 forward | C500 已验证 |
|
|
107
|
+
| Head dimension 64 / 128 | C500 已验证 |
|
|
108
|
+
| GQA 比率 2 / 4 / 8 | C500 已验证 |
|
|
109
|
+
| M1 不支持的 GQA 比率(历史验证 GQ=5/7) | 不进入 M1;由上层回退,未验证比率不作支持承诺 |
|
|
110
|
+
| vLLM 中 head_dim > 128 | 不进入 M1;official split 回退原始 MetaX/vendor 路径 |
|
|
111
|
+
| 直接调用 MXFlashAttn 公共 API 的 head_dim > 128 | 显式 `ValueError`,不静默计算 |
|
|
112
|
+
| 自研 split-KV decode kernel(M1) | C500 已验证,vLLM 0.17.0 接线 |
|
|
113
|
+
| dense / varlen / paged KV cache | API 已实现;paged KV append 已在 C500 验证 |
|
|
114
|
+
| dispatch 后端 | `m1_split_decode`(M1)→ `native_decode`(v7)→ `vendor_direct` → `reference` |
|
|
115
|
+
| PyTorch reference fallback | 需显式设置 `MXFLASHATTN_ALLOW_FALLBACK=1`,不会静默切换 |
|
|
116
|
+
| TTFT / P95 | 流式采集链路已验证;candidate 未命中 M1,不作为 M1 性能证据 |
|
|
117
|
+
| backward、FP8、多卡 | 首期不支持 |
|
|
118
|
+
| SGLang | 未安装验证 |
|
|
119
|
+
|
|
120
|
+
详细边界见 [`docs/support-matrix.md`](docs/support-matrix.md)。
|
|
121
|
+
|
|
122
|
+
## 项目结构
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
mxflashattn/ Python API、校验、reference 与 dispatch
|
|
126
|
+
csrc/mxmac/ C++/ATen bring-up 扩展(朴素 O(n^2) 实现,正确性对照路径)
|
|
127
|
+
csrc_native/ 自研 M1 split-KV decode 内核 + v7 内核 + 基准/测试/构建脚本
|
|
128
|
+
integrations/vllm/ vLLM 0.17.0 适配桥接、decoder adapter 与 preflight
|
|
129
|
+
benchmarks/ 固定配置、公平矩阵运行器和报告工具
|
|
130
|
+
scripts/ C500 实例运维与 E2E 复现脚本(模型暂存、形状扫描、各模型 E2E 编排)
|
|
131
|
+
docs/gate4/ Gate 4 技术报告(原始实例日志保留在本地工作空间)
|
|
132
|
+
docs/results/ C500 原始结果、报告和图表
|
|
133
|
+
tests/ CPU/reference 与 C500 条件测试
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`csrc/mxmac/` 是 **PyTorch ATen bring-up / 正确性对照路径**,由 `at::matmul` + `softmax`
|
|
137
|
+
组装的朴素实现,不是融合 kernel。自研 device kernel 在 `csrc_native/`。
|
|
138
|
+
|
|
139
|
+
Gate 4 各档E2E 的实例侧复现脚本在 `scripts/`(对应文档各节):
|
|
140
|
+
`run_e2e_q4b.sh` / `run_e2e_q8b.sh`(GQ=4 主场景)、
|
|
141
|
+
`run_e2e_gq7.sh`(GQ=7 守卫拒绝)、`run_e2e_gq8.sh`(GQ=8 PaddleOCR-VL)、
|
|
142
|
+
`run_e2e_hd256.sh`(HD=256 回退验证)、`run_queue.sh`(单卡串行编排)、
|
|
143
|
+
`scan_shapes.sh`(共享模型库形状扫描)和 `probe_paddle_vllm.sh`(架构探测)。
|
|
144
|
+
这些公开脚本面向有 C500 的实例;模型下载与数据盘暂存脚本属于本地申报工作区,
|
|
145
|
+
不随公开仓库发布。项目根目录支持通过 `MXFLASHATTN_ROOT` 覆盖,模型路径由各脚本中的
|
|
146
|
+
`MODEL` 变量或命令行 `--model` 提供。
|
|
147
|
+
|
|
148
|
+
## 前向算子 API
|
|
149
|
+
|
|
150
|
+
公开接口:
|
|
151
|
+
|
|
152
|
+
- `flash_attn_func`
|
|
153
|
+
- `flash_attn_varlen_func`
|
|
154
|
+
- `flash_attn_with_kvcache`
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
import torch
|
|
158
|
+
from mxflashattn import flash_attn_func, get_last_dispatch_info
|
|
159
|
+
|
|
160
|
+
q = torch.randn(1, 32, 8, 64, dtype=torch.float16, device="cuda")
|
|
161
|
+
k = torch.randn(1, 128, 2, 64, dtype=q.dtype, device=q.device)
|
|
162
|
+
v = torch.randn_like(k)
|
|
163
|
+
out = flash_attn_func(q, k, v, causal=True)
|
|
164
|
+
print(get_last_dispatch_info())
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
在没有 MetaX provider 或编译扩展时,调用默认报错。只有主动设置
|
|
168
|
+
`MXFLASHATTN_ALLOW_FALLBACK=1` 才启用 PyTorch reference fallback(会发`RuntimeWarning`)。
|
|
169
|
+
dropout、局部窗口、AliBi、soft-capping、rotary embeddings、backward 和 softmax-LSE
|
|
170
|
+
返回会明确报错,不会静默产生错误结果。
|
|
171
|
+
|
|
172
|
+
## 历史基准(v0.9公平矩阵)
|
|
173
|
+
|
|
174
|
+
v0.9 用固定 seed 覆盖 36 组 batch/seq/head_dim/GQA 比例/layout/dtype/causal 组合,
|
|
175
|
+
在 C500 上做reference、Torch SDPA、MetaX vendor、MXFlashAttn API 四路公平对比:
|
|
176
|
+
|
|
177
|
+
| 指标 | 结果 |
|
|
178
|
+
| --- | --- |
|
|
179
|
+
| 公平矩阵完成度 | C500 36/36 组 |
|
|
180
|
+
| MXFlashAttn vs PyTorch reference | 中位延迟下降 60.52% |
|
|
181
|
+
| MXFlashAttn vs MetaX vendor 直调 | 中位延迟**上升 32.74%** |
|
|
182
|
+
| 最大绝对误差 | 0.00390625 |
|
|
183
|
+
|
|
184
|
+
必须同时说清的口径:算子级基线是**同输入同设备的四路公平矩阵**,不是拿自写 reference
|
|
185
|
+
单独对比得出的加速比;模型级 vendor 与 candidate **分栏列示**,不混入算子级 median。
|
|
186
|
+
仓库早期那组 384 用例 benchmark基线是本项目 PyTorch reference,已被 v0.9 公平矩阵取代,
|
|
187
|
+
仅作历史数据保留在 `docs/results/`。
|
|
188
|
+
|
|
189
|
+
公开仓库提供脱敏结果摘要:[`docs/results/c500-2026-10-05.md`](docs/results/c500-2026-10-05.md)
|
|
190
|
+
和 [`docs/results/c500-2026-10-13.md`](docs/results/c500-2026-10-13.md)。完整原始 JSON、
|
|
191
|
+
dispatch 流和实例环境记录保留在本地申报工作空间,不随公开仓库发布。下面命令的
|
|
192
|
+
`--output` 是**重新生成**时的本地输出目标。
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# 评测输出默认写入被忽略的 artifacts/,只作为本地复现缓存。
|
|
196
|
+
python -m benchmarks.fair_matrix --device cuda --count 36 --repeats 5 \
|
|
197
|
+
--output artifacts/fair-matrix-c500.json
|
|
198
|
+
python benchmarks/fair_report.py artifacts/fair-matrix-c500.json \
|
|
199
|
+
--vendor-model artifacts/vllm-vendor-36.json \
|
|
200
|
+
--candidate-model artifacts/vllm-candidate-36.json \
|
|
201
|
+
--output artifacts/fair-matrix-c500.md
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+

|
|
205
|
+
|
|
206
|
+
## vLLM 集成
|
|
207
|
+
|
|
208
|
+
`integrations/vllm/vllm_plugin.py` 注册 MXFlashAttn backend。v1.3.0 起该插件在
|
|
209
|
+
`MXFA_M1_DECODE=1` 时把 paged decode 派发给 M1 内核,不支持的形状自动落回 v7,
|
|
210
|
+
再不支持则落回 MetaX vendor 直连。接线细节见
|
|
211
|
+
[`docs/gate4/M3_VLLM_WIRING.md`](docs/gate4/M3_VLLM_WIRING.md)。
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
python integrations/vllm/smoke_generate.py --model /mnt/moark-models/Qwen3-0.6B \
|
|
215
|
+
--prompt-count 36 --max-tokens 16 --baseline-only \
|
|
216
|
+
--output artifacts/vllm-vendor-36.json
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## 已知限制
|
|
220
|
+
|
|
221
|
+
- **v7 路径上下文上限 4096**(>4096 启动失败)。
|
|
222
|
+
- **M1 相对硬件上限仍有差距**:IR 分析显示 v7 走硬件融合`llvm.mxc.expadd.f32.i32`
|
|
223
|
+
做 softmax 重缩放,而 M1 走软件 shuffle 归约 + `exp2` 模拟。替换为硬件 intrinsic
|
|
224
|
+
是下一步方向,尚未实施。
|
|
225
|
+
- **text_match 不可在连续批处理下作正确性判据**:batch 组成随调度漂移。文本一致性
|
|
226
|
+
必须在固定 batch 下单独验证(见 `csrc_native/diag_guard_text_match.py`)。
|
|
227
|
+
- **dispatch 事件统计必须按 `(path, operation, fallback)` 三元组**,只按 path取 top-N
|
|
228
|
+
会在 M1 从未成功时误判为"没派发"。
|
|
229
|
+
|
|
230
|
+
## 路线图
|
|
231
|
+
|
|
232
|
+
后续优化与风险收敛路线见 [`docs/V1.5_OPTIMIZATION_PLAN.md`](docs/V1.5_OPTIMIZATION_PLAN.md)。
|
|
233
|
+
其中包括 M1 硬件 intrinsic 评估、C500 Prefill kernel、可复现 TTFT 口径、
|
|
234
|
+
自适应调度、vLLM 新版本兼容性以及 FP8/多卡/SGLang 评估;这些不属于
|
|
235
|
+
v1.4.0 已完成能力。
|
|
236
|
+
|
|
237
|
+
## 许可证
|
|
238
|
+
|
|
239
|
+
本项目采用 [Apache License 2.0](LICENSE)。MXMACA runtime、vendor PyTorch、MetaX wheel、
|
|
240
|
+
vLLM、模型权重和数据集分别遵循各自许可证。
|
|
241
|
+
|
|
242
|
+
欢迎通过 [`CONTRIBUTING.md`](CONTRIBUTING.md) 提交问题和改进。
|