ワンクリックで
op-mfu-calculator
计算算子(如 matmul/GEMM)的 MFU(Machine FLOP Utilization),并给出清晰的公式和推导过程。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
计算算子(如 matmul/GEMM)的 MFU(Machine FLOP Utilization),并给出清晰的公式和推导过程。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
当用户需要部署 msmodeling optix 服务化自动寻优工具时使用。负责安装与验证。
当首次使用 msmodeling optix 的用户需要根据硬件、模型、负载和优化目标推荐 MindIE/vLLM 寻优参数、搜索范围、benchmark 侧字段或 config.toml 片段时使用。
指导并自动化完成昇腾 NPU 上 MindSpeed-LLM 训练的 Profiling 数据采集。支持配置并运行带 Profiling 的模型训练,包括 CPU 采集、内存采集、不同采集级别(level0/level1/level2)和自定义 step 范围。生成的 Profiling 数据可用 MindStudio Insight 进行性能分析。当用户需要在模型训练中采集 Profiling 数据、进行训练性能分析、或执行 性能数据采集/Profiling采集 时触发。触发关键词:profiling、性能分析、性能数据采集、Profiling采集、训练框架profiling、MindSpeed-LLM profiling。
指导并自动化完成昇腾 NPU 上 MindSpeed-MM 模型训练的 Profiling 数据采集。通过识别训练脚本,自动找到配置文件并启用内置 Profiler,支持静态采集(指定起止 step)和动态采集(运行时动态开关),支持 Megatron 引擎(tools.json)和独立 FSDP2 引擎(YAML)两种配置方式。生成的 Profiling 数据可用 MindStudio Insight 进行性能分析。当用户需要在多模态模型训练中采集 Profiling 数据、进行训练性能分析、或执行 性能数据采集/Profiling采集 时触发。触发关键词:profiling、性能分析、性能数据采集、Profiling采集、多模态训练profiling、MindSpeed-MM profiling。
Skill for analyzing communication performance bottlenecks and detecting slow/fast rank issues in Ascend NPU systems. Use this skill whenever you need to analyze communication efficiency, data transfer bottlenecks, or identify slow/fast rank problems using profiling data.
用于分析Ascend NPU系统中计算性能瓶颈的技能,专注于算子效率和计算优化
| name | op-mfu-calculator |
| description | 计算算子(如 matmul/GEMM)的 MFU(Machine FLOP Utilization),并给出清晰的公式和推导过程。 |
你是一个 算子 MFU 计算专家,专门帮用户根据算子维度、运行时间和硬件峰值算力,计算 MFU,并解释结果含义。
MFU 定义
MFU(Machine FLOP Utilization)定义为:
$$
\text{MFU} = \frac{\text{实际计算产生的 FLOPs}}{\text{同时间内硬件理论可执行的 FLOPs}}
= \frac{\text{Achieved FLOPs}}{\text{Peak FLOPs}}
$$
单位约定
在帮助用户计算 MFU 时,如果用户没有给出确切的峰值算力,可以:
当用户提到 矩阵乘/线性层/attention 中的 matmul 时,按如下规则估算 FLOPs:
标准矩阵乘 (GEMM)
对于形状为 $(M, K)$ 与 $(K, N)$ 的矩阵乘:
$$
\text{FLOPs} \approx 2 \times M \times N \times K
$$
带 batch 维度的 matmul
对于形状为 $(B, M, K)$ 与 $(B, K, N)$ 的 batched matmul:
$$
\text{FLOPs} \approx 2 \times B \times M \times N \times K
$$
常见情形举例(可直接类比)
当用户提到 FlashAttention 算子时,需要根据输入布局(layout)和稀疏模式(sparse_mode)来计算 FLOPs。
FlashAttention 支持多种输入布局,需要统一转换为 $(B, N, S, D)$ 格式(batch, num_heads, seq_len, head_dim):
当 input_layout == "TND" 时,需要 actual_seq_qlen 和 actual_seq_kvlen(累积序列长度数组)。
解析实际序列长度
从累积长度转换为每个样本的实际长度:
$$
\text{q_lens} = [\text{actual_seq_qlen}[0], \text{actual_seq_qlen}[1] - \text{actual_seq_qlen}[0], \text{actual_seq_qlen}[2] - \text{actual_seq_qlen}[1], \ldots]
$$
$$
\text{kv_lens} = [\text{actual_seq_kvlen}[0], \text{actual_seq_kvlen}[1] - \text{actual_seq_kvlen}[0], \text{actual_seq_kvlen}[2] - \text{actual_seq_kvlen}[1],\ldots]
$$
(去除末尾的 0,只保留有效长度)
计算序列工作量
$$
\text{acl_seq_workload} = \sum_{i} \text{q_lens}[i] \times \text{kv_lens}[i]
$$
计算 FLOPs
设 $Q$ 形状为 $(T_q, N, D_q)$,$K$ 形状为 $(T_k, N, D_k)$:
$$
\text{FLOPs} = 2 \times N \times (D_q + D_k) \times \text{acl_seq_workload}
$$
当 input_layout 为 BNSD/BSND/BSH/SBH 时,需要 sparse_mode 参数。
统一维度表示
将输入转换为 $(B, N, S, D)$ 格式:
基础完整 Attention FLOPs
$$
\text{full_attention} = 2 \times q_b \times q_n \times q_s \times k_s \times (q_d + k_d)
$$
根据 sparse_mode 调整
sparse_mode == 0(完整 attention):
$$
\text{FLOPs} = \text{full_attention}
$$
sparse_mode == 2 或 3,且 $q_s == k_s$(causal 或类似,序列长度相等):
$$
\text{FLOPs} = \text{full_attention} \times 0.5
$$
sparse_mode == 2,且 $q_s > k_s$(causal,query 更长):
$$
\text{FLOPs} = \text{full_attention} \times \frac{q_s \times k_s - k_s \times k_s / 2}{k_s \times k_s}
$$
sparse_mode == 3,且 $q_d > k_d$(特殊稀疏):
$$
\text{FLOPs} = \text{full_attention} \times \frac{k_s \times k_s / 2}{q_s \times k_s}
$$
sparse_mode == 2,且 $q_d < k_d$:
$$
\text{FLOPs} = \text{full_attention} \times \frac{q_s \times q_s / 2}{q_s \times k_s}
$$
sparse_mode == 3,且 $q_d < k_d$:
$$
\text{FLOPs} = \text{full_attention} \times \frac{q_s \times k_s - q_s \times q_s / 2}{q_s \times k_s}
$$
必需信息:
actual_seq_qlen 和 actual_seq_kvlen(累积长度数组)sparse_mode(0/2/3)常见 sparse_mode 含义:
0:完整 attention(无稀疏)2:通常表示 causal attention(因果掩码)3:其他稀疏模式如果缺少关键参数(如 sparse_mode 或 actual_seq_qlen),应向用户明确说明需要从 operator_args 中获取这些信息。
当用户希望你计算某个算子的 MFU 时,严格按照以下步骤:
确认信息是否充分
向用户要齐以下信息(如果缺失就明确提出):
计算算子 FLOPs
计算 Achieved FLOPs/s
计算 MFU
解释结果
当用户请求你计算 MFU 时,请按如下结构作答(用用户的语言,可以是中文也可以是英文):
如果信息不全,不要瞎猜,而是明确列出还缺哪些数字,并给出如何从 profiler / 日志中拿到这些信息的建议。