mxflashattn 1.4.0__tar.gz → 1.4.1__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 → mxflashattn-1.4.1}/MANIFEST.in +1 -0
- mxflashattn-1.4.1/PKG-INFO +151 -0
- mxflashattn-1.4.1/README_PYPI.md +129 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn/__init__.py +1 -1
- mxflashattn-1.4.1/mxflashattn.egg-info/PKG-INFO +151 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn.egg-info/SOURCES.txt +1 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/pyproject.toml +2 -2
- mxflashattn-1.4.0/PKG-INFO +0 -242
- mxflashattn-1.4.0/mxflashattn.egg-info/PKG-INFO +0 -242
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/CONTRIBUTING.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/LICENSE +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/README.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/__init__.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/compare.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/configs/c500.yaml +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/fair_matrix.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/fair_report.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/model_fair_report.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/plot_summary.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/report.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/benchmarks/run.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/csrc/mxmac/CMakeLists.txt +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/csrc/mxmac/attention.h +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/csrc/mxmac/attention_forward.cpp +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/csrc/mxmac/paged_kv.cpp +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/csrc/mxmac/workspace.cpp +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/API.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/C500_MINIMAL_RUNBOOK.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/C500_V14_EXPERIMENT_PLAN.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/C500_V14_VALIDATION_20261017.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/C500_VALIDATION_RUNBOOK.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/GIT_WORKFLOW.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/RELEASE_LAYOUT.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/TECHNICAL_NOTES.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/V1.4.0_DEV_PLAN.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/V1.5_OPTIMIZATION_PLAN.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/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" +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/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" +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/gate4/Gate4_/346/224/266/345/256/230/346/212/245/345/221/212.md" +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/gate4/M3_VLLM_WIRING.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/results/c500-2026-10-05.json +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/results/c500-2026-10-05.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/results/c500-2026-10-13.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/results/c500-model-level-summary.png +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/results/c500-speedup-summary.png +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/docs/support-matrix.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/__init__.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/README.md +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/__init__.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/backend.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/compat.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/config.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/decoder_adapter.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/probe_compat.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/probe_decoder_layout.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/probe_registration.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/probe_v017.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/smoke_generate.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/integrations/vllm/vllm_plugin.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn/accuracy.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn/api.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn/dispatch.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn/policy.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn/prefill.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn/reference.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn/validation.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn.egg-info/dependency_links.txt +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn.egg-info/requires.txt +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/mxflashattn.egg-info/top_level.txt +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/requirements-c500.txt +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/requirements-vllm.txt +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/setup.cfg +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/setup.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_accuracy.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_api.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_benchmark.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_c500.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_c500_plan.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_decoder_adapter.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_dispatch.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_long_context_accuracy.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_plot_summary.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_policy.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_prefill.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_vllm_bridge.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_vllm_compat.py +0 -0
- {mxflashattn-1.4.0 → mxflashattn-1.4.1}/tests/test_vllm_official_split_fallback.py +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mxflashattn
|
|
3
|
+
Version: 1.4.1
|
|
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
|
+
面向 **MetaX C500 / MXMACA** 的 FlashAttention-compatible 前向 API 与
|
|
26
|
+
vLLM 推理适配组件。
|
|
27
|
+
|
|
28
|
+
`mxflashattn` 提供稳定的 Python 调用入口、参数校验、后端选择和显式回退
|
|
29
|
+
机制。对于已经部署 MetaX 软件栈的 C500 用户,它还提供经过真实模型验证的
|
|
30
|
+
M1 Split-KV Decode 集成路径。
|
|
31
|
+
|
|
32
|
+
> 当前 PyPI 包是 Python API 与适配层。C500 原生 kernel 需要在目标实例上按
|
|
33
|
+
> MetaX/MACA 环境编译,详见“C500 使用”。
|
|
34
|
+
|
|
35
|
+
## 适合什么场景
|
|
36
|
+
|
|
37
|
+
- 在 Python 项目中使用 FlashAttention 风格的前向接口。
|
|
38
|
+
- 为 MXMACA / MetaX C500 推理服务接入 vLLM 0.17.0。
|
|
39
|
+
- 在 C500 上对高并发、长 KV cache 的 Decode 阶段使用 M1 Split-KV kernel。
|
|
40
|
+
- 在没有原生扩展的环境中,显式启用 PyTorch reference 路径进行接口调试和正确性测试。
|
|
41
|
+
|
|
42
|
+
## 安装
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m pip install mxflashattn==1.4.1
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
基础依赖:
|
|
49
|
+
|
|
50
|
+
- Python 3.10+
|
|
51
|
+
- PyTorch 2.4+
|
|
52
|
+
- PyYAML 6.x
|
|
53
|
+
|
|
54
|
+
vLLM 适配依赖需要单独安装:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
python -m pip install "mxflashattn[vllm]==1.4.1"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
当前适配目标是 vLLM 0.17.0,并且需要兼容的 MetaX vLLM/MACA 软件栈。
|
|
61
|
+
|
|
62
|
+
## Python API
|
|
63
|
+
|
|
64
|
+
公开入口:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from mxflashattn import (
|
|
68
|
+
flash_attn_func,
|
|
69
|
+
flash_attn_varlen_func,
|
|
70
|
+
flash_attn_with_kvcache,
|
|
71
|
+
get_last_dispatch_info,
|
|
72
|
+
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
一个最小的显式 reference 调试示例:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import os
|
|
79
|
+
|
|
80
|
+
import torch
|
|
81
|
+
|
|
82
|
+
from mxflashattn import flash_attn_func, get_last_dispatch_info
|
|
83
|
+
|
|
84
|
+
os.environ["MXFLASHATTN_ALLOW_FALLBACK"] = "1"
|
|
85
|
+
|
|
86
|
+
q = torch.randn(1, 32, 8, 64, dtype=torch.float16)
|
|
87
|
+
k = torch.randn(1, 128, 2, 64, dtype=q.dtype)
|
|
88
|
+
v = torch.randn_like(k)
|
|
89
|
+
|
|
90
|
+
out = flash_attn_func(q, k, v, causal=True)
|
|
91
|
+
print(out.shape)
|
|
92
|
+
print(get_last_dispatch_info())
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
reference 路径只用于调试和正确性对照,不是 C500 性能路径。没有显式设置
|
|
96
|
+
`MXFLASHATTN_ALLOW_FALLBACK=1` 时,缺少原生后端会直接报错,避免程序静默降速。
|
|
97
|
+
|
|
98
|
+
## C500 使用
|
|
99
|
+
|
|
100
|
+
PyPI wheel 不包含针对特定 C500/MACA 环境编译的 `.so` 文件。要启用 M1
|
|
101
|
+
Split-KV Decode,需要从源码仓库获取对应版本并在 C500 实例中编译:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
git clone -b dev/v1.4.0 https://github.com/leo1852098393-blip/MXFlashAttn.git
|
|
105
|
+
cd MXFlashAttn
|
|
106
|
+
|
|
107
|
+
export MACA_PATH=/opt/maca
|
|
108
|
+
bash csrc_native/build_m1.sh
|
|
109
|
+
python csrc_native/patch_plugin.py
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
然后按项目中的 vLLM 0.17.0 运行说明启动服务或基准。运行性能测试时,必须
|
|
113
|
+
检查 dispatch 日志中是否出现 `m1_split_decode`,否则不能把结果归因于 M1。
|
|
114
|
+
|
|
115
|
+
## 已验证能力
|
|
116
|
+
|
|
117
|
+
在 MetaX C500、MACA 3.5.3.20、MetaX PyTorch
|
|
118
|
+
`2.8.0+metax3.5.3.9` 和 vLLM 0.17.0 环境中,项目已验证:
|
|
119
|
+
|
|
120
|
+
- FP16 / BF16 前向;
|
|
121
|
+
- `head_dim` 64 / 128;
|
|
122
|
+
- GQA 比率 2 / 4 / 8;
|
|
123
|
+
- vLLM 真实模型生成和 M1 dispatch;
|
|
124
|
+
- 不支持形状的安全回退;
|
|
125
|
+
- 15,000 token prompt、`max_model_len=16384` 的 vendor Prefill + M1 Decode 回归。
|
|
126
|
+
|
|
127
|
+
在一组 Qwen3-4B C500 长上下文 Decode 配置中,M1-UM2 相对项目 v7 路径
|
|
128
|
+
达到约 3.66x;Qwen3-8B 的对应测试约 1.37x。数字只适用于记录中的模型、
|
|
129
|
+
batch、KV 长度、软件栈和基线,不代表所有请求都有固定加速。
|
|
130
|
+
|
|
131
|
+
## 重要边界
|
|
132
|
+
|
|
133
|
+
- 项目面向 MetaX C500,不是跨硬件 FlashAttention 替代品。
|
|
134
|
+
- M1 的生产验证重点是 Decode;Prefill 仍交给 MetaX vendor。
|
|
135
|
+
- `prefill_chunked_reference` 是 correctness-first 研究原型,不是生产 Prefill kernel。
|
|
136
|
+
- 短序列、低并发和不支持的 GQA/head dimension 可能回退或没有收益。
|
|
137
|
+
- 当前没有对 vLLM 0.30.x、FP8、多卡和 SGLang 做支持承诺。
|
|
138
|
+
- backward、dropout、局部窗口、soft-capping、rotary embeddings 等未实现能力
|
|
139
|
+
会显式报错,不会静默返回不可靠结果。
|
|
140
|
+
|
|
141
|
+
## 文档与源码
|
|
142
|
+
|
|
143
|
+
- GitHub:[leo1852098393-blip/MXFlashAttn](https://github.com/leo1852098393-blip/MXFlashAttn)
|
|
144
|
+
- GitLink:[Leo77/MXFlashAttn](https://gitlink.org.cn/Leo77/MXFlashAttn)
|
|
145
|
+
- API 说明:[docs/API.md](https://github.com/leo1852098393-blip/MXFlashAttn/blob/dev/v1.4.0/docs/API.md)
|
|
146
|
+
- C500 支持矩阵:[docs/support-matrix.md](https://github.com/leo1852098393-blip/MXFlashAttn/blob/dev/v1.4.0/docs/support-matrix.md)
|
|
147
|
+
|
|
148
|
+
## 许可证
|
|
149
|
+
|
|
150
|
+
Apache License 2.0。
|
|
151
|
+
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# MXFlashAttn
|
|
2
|
+
|
|
3
|
+
面向 **MetaX C500 / MXMACA** 的 FlashAttention-compatible 前向 API 与
|
|
4
|
+
vLLM 推理适配组件。
|
|
5
|
+
|
|
6
|
+
`mxflashattn` 提供稳定的 Python 调用入口、参数校验、后端选择和显式回退
|
|
7
|
+
机制。对于已经部署 MetaX 软件栈的 C500 用户,它还提供经过真实模型验证的
|
|
8
|
+
M1 Split-KV Decode 集成路径。
|
|
9
|
+
|
|
10
|
+
> 当前 PyPI 包是 Python API 与适配层。C500 原生 kernel 需要在目标实例上按
|
|
11
|
+
> MetaX/MACA 环境编译,详见“C500 使用”。
|
|
12
|
+
|
|
13
|
+
## 适合什么场景
|
|
14
|
+
|
|
15
|
+
- 在 Python 项目中使用 FlashAttention 风格的前向接口。
|
|
16
|
+
- 为 MXMACA / MetaX C500 推理服务接入 vLLM 0.17.0。
|
|
17
|
+
- 在 C500 上对高并发、长 KV cache 的 Decode 阶段使用 M1 Split-KV kernel。
|
|
18
|
+
- 在没有原生扩展的环境中,显式启用 PyTorch reference 路径进行接口调试和正确性测试。
|
|
19
|
+
|
|
20
|
+
## 安装
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
python -m pip install mxflashattn==1.4.1
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
基础依赖:
|
|
27
|
+
|
|
28
|
+
- Python 3.10+
|
|
29
|
+
- PyTorch 2.4+
|
|
30
|
+
- PyYAML 6.x
|
|
31
|
+
|
|
32
|
+
vLLM 适配依赖需要单独安装:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
python -m pip install "mxflashattn[vllm]==1.4.1"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
当前适配目标是 vLLM 0.17.0,并且需要兼容的 MetaX vLLM/MACA 软件栈。
|
|
39
|
+
|
|
40
|
+
## Python API
|
|
41
|
+
|
|
42
|
+
公开入口:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from mxflashattn import (
|
|
46
|
+
flash_attn_func,
|
|
47
|
+
flash_attn_varlen_func,
|
|
48
|
+
flash_attn_with_kvcache,
|
|
49
|
+
get_last_dispatch_info,
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
一个最小的显式 reference 调试示例:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import os
|
|
57
|
+
|
|
58
|
+
import torch
|
|
59
|
+
|
|
60
|
+
from mxflashattn import flash_attn_func, get_last_dispatch_info
|
|
61
|
+
|
|
62
|
+
os.environ["MXFLASHATTN_ALLOW_FALLBACK"] = "1"
|
|
63
|
+
|
|
64
|
+
q = torch.randn(1, 32, 8, 64, dtype=torch.float16)
|
|
65
|
+
k = torch.randn(1, 128, 2, 64, dtype=q.dtype)
|
|
66
|
+
v = torch.randn_like(k)
|
|
67
|
+
|
|
68
|
+
out = flash_attn_func(q, k, v, causal=True)
|
|
69
|
+
print(out.shape)
|
|
70
|
+
print(get_last_dispatch_info())
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
reference 路径只用于调试和正确性对照,不是 C500 性能路径。没有显式设置
|
|
74
|
+
`MXFLASHATTN_ALLOW_FALLBACK=1` 时,缺少原生后端会直接报错,避免程序静默降速。
|
|
75
|
+
|
|
76
|
+
## C500 使用
|
|
77
|
+
|
|
78
|
+
PyPI wheel 不包含针对特定 C500/MACA 环境编译的 `.so` 文件。要启用 M1
|
|
79
|
+
Split-KV Decode,需要从源码仓库获取对应版本并在 C500 实例中编译:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
git clone -b dev/v1.4.0 https://github.com/leo1852098393-blip/MXFlashAttn.git
|
|
83
|
+
cd MXFlashAttn
|
|
84
|
+
|
|
85
|
+
export MACA_PATH=/opt/maca
|
|
86
|
+
bash csrc_native/build_m1.sh
|
|
87
|
+
python csrc_native/patch_plugin.py
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
然后按项目中的 vLLM 0.17.0 运行说明启动服务或基准。运行性能测试时,必须
|
|
91
|
+
检查 dispatch 日志中是否出现 `m1_split_decode`,否则不能把结果归因于 M1。
|
|
92
|
+
|
|
93
|
+
## 已验证能力
|
|
94
|
+
|
|
95
|
+
在 MetaX C500、MACA 3.5.3.20、MetaX PyTorch
|
|
96
|
+
`2.8.0+metax3.5.3.9` 和 vLLM 0.17.0 环境中,项目已验证:
|
|
97
|
+
|
|
98
|
+
- FP16 / BF16 前向;
|
|
99
|
+
- `head_dim` 64 / 128;
|
|
100
|
+
- GQA 比率 2 / 4 / 8;
|
|
101
|
+
- vLLM 真实模型生成和 M1 dispatch;
|
|
102
|
+
- 不支持形状的安全回退;
|
|
103
|
+
- 15,000 token prompt、`max_model_len=16384` 的 vendor Prefill + M1 Decode 回归。
|
|
104
|
+
|
|
105
|
+
在一组 Qwen3-4B C500 长上下文 Decode 配置中,M1-UM2 相对项目 v7 路径
|
|
106
|
+
达到约 3.66x;Qwen3-8B 的对应测试约 1.37x。数字只适用于记录中的模型、
|
|
107
|
+
batch、KV 长度、软件栈和基线,不代表所有请求都有固定加速。
|
|
108
|
+
|
|
109
|
+
## 重要边界
|
|
110
|
+
|
|
111
|
+
- 项目面向 MetaX C500,不是跨硬件 FlashAttention 替代品。
|
|
112
|
+
- M1 的生产验证重点是 Decode;Prefill 仍交给 MetaX vendor。
|
|
113
|
+
- `prefill_chunked_reference` 是 correctness-first 研究原型,不是生产 Prefill kernel。
|
|
114
|
+
- 短序列、低并发和不支持的 GQA/head dimension 可能回退或没有收益。
|
|
115
|
+
- 当前没有对 vLLM 0.30.x、FP8、多卡和 SGLang 做支持承诺。
|
|
116
|
+
- backward、dropout、局部窗口、soft-capping、rotary embeddings 等未实现能力
|
|
117
|
+
会显式报错,不会静默返回不可靠结果。
|
|
118
|
+
|
|
119
|
+
## 文档与源码
|
|
120
|
+
|
|
121
|
+
- GitHub:[leo1852098393-blip/MXFlashAttn](https://github.com/leo1852098393-blip/MXFlashAttn)
|
|
122
|
+
- GitLink:[Leo77/MXFlashAttn](https://gitlink.org.cn/Leo77/MXFlashAttn)
|
|
123
|
+
- API 说明:[docs/API.md](https://github.com/leo1852098393-blip/MXFlashAttn/blob/dev/v1.4.0/docs/API.md)
|
|
124
|
+
- C500 支持矩阵:[docs/support-matrix.md](https://github.com/leo1852098393-blip/MXFlashAttn/blob/dev/v1.4.0/docs/support-matrix.md)
|
|
125
|
+
|
|
126
|
+
## 许可证
|
|
127
|
+
|
|
128
|
+
Apache License 2.0。
|
|
129
|
+
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mxflashattn
|
|
3
|
+
Version: 1.4.1
|
|
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
|
+
面向 **MetaX C500 / MXMACA** 的 FlashAttention-compatible 前向 API 与
|
|
26
|
+
vLLM 推理适配组件。
|
|
27
|
+
|
|
28
|
+
`mxflashattn` 提供稳定的 Python 调用入口、参数校验、后端选择和显式回退
|
|
29
|
+
机制。对于已经部署 MetaX 软件栈的 C500 用户,它还提供经过真实模型验证的
|
|
30
|
+
M1 Split-KV Decode 集成路径。
|
|
31
|
+
|
|
32
|
+
> 当前 PyPI 包是 Python API 与适配层。C500 原生 kernel 需要在目标实例上按
|
|
33
|
+
> MetaX/MACA 环境编译,详见“C500 使用”。
|
|
34
|
+
|
|
35
|
+
## 适合什么场景
|
|
36
|
+
|
|
37
|
+
- 在 Python 项目中使用 FlashAttention 风格的前向接口。
|
|
38
|
+
- 为 MXMACA / MetaX C500 推理服务接入 vLLM 0.17.0。
|
|
39
|
+
- 在 C500 上对高并发、长 KV cache 的 Decode 阶段使用 M1 Split-KV kernel。
|
|
40
|
+
- 在没有原生扩展的环境中,显式启用 PyTorch reference 路径进行接口调试和正确性测试。
|
|
41
|
+
|
|
42
|
+
## 安装
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m pip install mxflashattn==1.4.1
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
基础依赖:
|
|
49
|
+
|
|
50
|
+
- Python 3.10+
|
|
51
|
+
- PyTorch 2.4+
|
|
52
|
+
- PyYAML 6.x
|
|
53
|
+
|
|
54
|
+
vLLM 适配依赖需要单独安装:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
python -m pip install "mxflashattn[vllm]==1.4.1"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
当前适配目标是 vLLM 0.17.0,并且需要兼容的 MetaX vLLM/MACA 软件栈。
|
|
61
|
+
|
|
62
|
+
## Python API
|
|
63
|
+
|
|
64
|
+
公开入口:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from mxflashattn import (
|
|
68
|
+
flash_attn_func,
|
|
69
|
+
flash_attn_varlen_func,
|
|
70
|
+
flash_attn_with_kvcache,
|
|
71
|
+
get_last_dispatch_info,
|
|
72
|
+
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
一个最小的显式 reference 调试示例:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import os
|
|
79
|
+
|
|
80
|
+
import torch
|
|
81
|
+
|
|
82
|
+
from mxflashattn import flash_attn_func, get_last_dispatch_info
|
|
83
|
+
|
|
84
|
+
os.environ["MXFLASHATTN_ALLOW_FALLBACK"] = "1"
|
|
85
|
+
|
|
86
|
+
q = torch.randn(1, 32, 8, 64, dtype=torch.float16)
|
|
87
|
+
k = torch.randn(1, 128, 2, 64, dtype=q.dtype)
|
|
88
|
+
v = torch.randn_like(k)
|
|
89
|
+
|
|
90
|
+
out = flash_attn_func(q, k, v, causal=True)
|
|
91
|
+
print(out.shape)
|
|
92
|
+
print(get_last_dispatch_info())
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
reference 路径只用于调试和正确性对照,不是 C500 性能路径。没有显式设置
|
|
96
|
+
`MXFLASHATTN_ALLOW_FALLBACK=1` 时,缺少原生后端会直接报错,避免程序静默降速。
|
|
97
|
+
|
|
98
|
+
## C500 使用
|
|
99
|
+
|
|
100
|
+
PyPI wheel 不包含针对特定 C500/MACA 环境编译的 `.so` 文件。要启用 M1
|
|
101
|
+
Split-KV Decode,需要从源码仓库获取对应版本并在 C500 实例中编译:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
git clone -b dev/v1.4.0 https://github.com/leo1852098393-blip/MXFlashAttn.git
|
|
105
|
+
cd MXFlashAttn
|
|
106
|
+
|
|
107
|
+
export MACA_PATH=/opt/maca
|
|
108
|
+
bash csrc_native/build_m1.sh
|
|
109
|
+
python csrc_native/patch_plugin.py
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
然后按项目中的 vLLM 0.17.0 运行说明启动服务或基准。运行性能测试时,必须
|
|
113
|
+
检查 dispatch 日志中是否出现 `m1_split_decode`,否则不能把结果归因于 M1。
|
|
114
|
+
|
|
115
|
+
## 已验证能力
|
|
116
|
+
|
|
117
|
+
在 MetaX C500、MACA 3.5.3.20、MetaX PyTorch
|
|
118
|
+
`2.8.0+metax3.5.3.9` 和 vLLM 0.17.0 环境中,项目已验证:
|
|
119
|
+
|
|
120
|
+
- FP16 / BF16 前向;
|
|
121
|
+
- `head_dim` 64 / 128;
|
|
122
|
+
- GQA 比率 2 / 4 / 8;
|
|
123
|
+
- vLLM 真实模型生成和 M1 dispatch;
|
|
124
|
+
- 不支持形状的安全回退;
|
|
125
|
+
- 15,000 token prompt、`max_model_len=16384` 的 vendor Prefill + M1 Decode 回归。
|
|
126
|
+
|
|
127
|
+
在一组 Qwen3-4B C500 长上下文 Decode 配置中,M1-UM2 相对项目 v7 路径
|
|
128
|
+
达到约 3.66x;Qwen3-8B 的对应测试约 1.37x。数字只适用于记录中的模型、
|
|
129
|
+
batch、KV 长度、软件栈和基线,不代表所有请求都有固定加速。
|
|
130
|
+
|
|
131
|
+
## 重要边界
|
|
132
|
+
|
|
133
|
+
- 项目面向 MetaX C500,不是跨硬件 FlashAttention 替代品。
|
|
134
|
+
- M1 的生产验证重点是 Decode;Prefill 仍交给 MetaX vendor。
|
|
135
|
+
- `prefill_chunked_reference` 是 correctness-first 研究原型,不是生产 Prefill kernel。
|
|
136
|
+
- 短序列、低并发和不支持的 GQA/head dimension 可能回退或没有收益。
|
|
137
|
+
- 当前没有对 vLLM 0.30.x、FP8、多卡和 SGLang 做支持承诺。
|
|
138
|
+
- backward、dropout、局部窗口、soft-capping、rotary embeddings 等未实现能力
|
|
139
|
+
会显式报错,不会静默返回不可靠结果。
|
|
140
|
+
|
|
141
|
+
## 文档与源码
|
|
142
|
+
|
|
143
|
+
- GitHub:[leo1852098393-blip/MXFlashAttn](https://github.com/leo1852098393-blip/MXFlashAttn)
|
|
144
|
+
- GitLink:[Leo77/MXFlashAttn](https://gitlink.org.cn/Leo77/MXFlashAttn)
|
|
145
|
+
- API 说明:[docs/API.md](https://github.com/leo1852098393-blip/MXFlashAttn/blob/dev/v1.4.0/docs/API.md)
|
|
146
|
+
- C500 支持矩阵:[docs/support-matrix.md](https://github.com/leo1852098393-blip/MXFlashAttn/blob/dev/v1.4.0/docs/support-matrix.md)
|
|
147
|
+
|
|
148
|
+
## 许可证
|
|
149
|
+
|
|
150
|
+
Apache License 2.0。
|
|
151
|
+
|
|
@@ -4,9 +4,9 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mxflashattn"
|
|
7
|
-
version = "1.4.
|
|
7
|
+
version = "1.4.1"
|
|
8
8
|
description = "FlashAttention-compatible forward APIs and MXMACA bring-up backend"
|
|
9
|
-
readme = "
|
|
9
|
+
readme = "README_PYPI.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = "Apache-2.0"
|
|
12
12
|
dependencies = [
|
mxflashattn-1.4.0/PKG-INFO
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
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) 提交问题和改进。
|
|
@@ -1,242 +0,0 @@
|
|
|
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) 提交问题和改进。
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|