分析Profiler Timeline中的算子序列,通过寻找频繁项集的办法,得到TOPK可融合的算子序列

devtools/2024/9/22 23:49:34/

分析Profiler Timeline中的算子序列,通过寻找频繁项集的办法,得到TOPK可融合的算子序列

  • 1.相关链接
  • 2.代码【仅分析带通信算子的Pattern】
  • 3.在实际工程中发现 ['all_gather', 'matrix_mm_out']频率最高
  • 4.[Ascend MC2](https://gitee.com/ascend/MindSpeed/blob/master/docs/features/mc2.md)
  • 5.torch_npu.npu_all_gather_base_mm

本文尝试分析Profiler Timeline中的算子序列,通过寻找频繁项集的办法,得到TOPK可融合的算子序列

1.相关链接

  • Ascend C 2.0新特性详解,支撑大模型融合算子高效开发

2.代码【仅分析带通信算子的Pattern】

python">from collections import defaultdict, dequedef rolling_hash(s, base=257, mod=10**9 + 7):h = 0for ch in s:h = (h * base + ord(ch)) % modreturn hdef find_top_n_fixed_length_sequences(arr, length, top_n):# 创建一个字典来存储子序列及其出现次数和偏移位置sequence_data = defaultdict(lambda: {"count": 0, "positions": []})base, mod = 257, 10**9 + 7# 滑动窗口计算固定长度子序列for i in range(len(arr) - length + 1):window = arr[i:i + length]if "all_gather" in window or "reduce_scatter" in window:  #只处理函通信算子的patternflat_window = ''.join(window)h = rolling_hash(flat_window, base, mod)sequence_data[h]['count'] += 1sequence_data[h]['positions'].append(i)# 按照出现频率排序,并获取前N个子序列sorted_sequences = sorted(sequence_data.items(), key=lambda item: item[1]['count'], reverse=True)top_sequences = sorted_sequences[:top_n]return top_sequences, sequence_data# 加载profiler生成的timeline,提取出算子名列表及偏移未知,这里构造了一个简单的数据
operators=["mm","all_gather","binary_add","dropout_backward","fill","eltwise_silu","mm","all_gather","fill"]
offsets=range(0,len(operators))# 要求最少两个元素的子序列,且取前3个出现频率最高的长度为2的子序列
length = 2
top_n = 1# 获取前N个频繁的长度为固定长度的子序列
top_sequences, sequence_data = find_top_n_fixed_length_sequences(operators, length, top_n)# 反向查找实际的序列值
reverse_lookup = {}
for i in range(len(operators) - length + 1):window = operators[i:i + length]flat_window = ''.join(window)h = rolling_hash(flat_window)if h not in reverse_lookup:reverse_lookup[h] = window# 输出结果并去重
unique_sequences = set()  # 用来跟踪已经输出的序列
for seq_hash, data in top_sequences:seq = reverse_lookup[seq_hash]seq_tuple = tuple(seq)if seq_tuple not in unique_sequences:unique_sequences.add(seq_tuple)positions = sequence_data[seq_hash]['positions']print(f'序列: {seq}, 出现频率: {data["count"]}')for pos in positions:beg=posend=pos+lengthts_beg=offsets[beg]ts_end=offsets[end]print(ts_beg,ts_end,operators[ts_beg:ts_end])

DEMO 输出

序列: ['mm', 'all_gather'], 出现频率: 2
0 2 ['mm', 'all_gather']
6 8 ['mm', 'all_gather']

3.在实际工程中发现 [‘all_gather’, ‘matrix_mm_out’]频率最高

4.Ascend MC2

在这里插入图片描述

5.torch_npu.npu_all_gather_base_mm

在这里插入图片描述


http://www.ppmy.cn/devtools/57186.html

相关文章

Excel+vue+java实现批量处理功能

需求背景: 产品创建流程比较复杂,有时候需要一次性创建多至10个,所以做了Excel维护产品信息,直接导入创建的功能。能极大提高效率。 简要概括实现: 一、参考单个创建,设计创建模板,表头对应填写字段名&…

详解 HTTP 中间人攻击

什么是中间人攻击? 攻击者将自己插入通信过程中,以窃取,篡改数据。通信的两端不知道中间人的存在,他们以为在与对方直接通信,实际上他们的通信已经被监听或干扰。WIFI 路由器被破解之后就能进行中间人攻击。 中间人攻…

基于Java的微信记账小程序【附源码】

摘 要 随着我国经济迅速发展,人们对手机的需求越来越大,各种手机软件也都在被广泛应用,但是对于手机进行数据信息管理,对于手机的各种软件也是备受用户的喜爱,记账微信小程序被用户普遍使用,为方便用户能够…

介绍几种 MySQL 官方高可用方案

前言: MySQL 官方提供了多种高可用部署方案,从最基础的主从复制到组复制再到 InnoDB Cluster 等等。本篇文章以 MySQL 8.0 版本为准,介绍下不同高可用方案架构原理及使用场景。 1.MySQL Replication MySQL Replication 是官方提供的主从同…

【力扣】有效的字母异位词

🔥博客主页: 我要成为C领域大神🎥系列专栏:【C核心编程】 【计算机网络】 【Linux编程】 【操作系统】 ❤️感谢大家点赞👍收藏⭐评论✍️ 本博客致力于知识分享,与更多的人进行学习交流 给定两个字符串 s …

高性价比模块:LSYT201B语音模块学习使用

最近打算做个语音的项目,找到了深圳雷龙发展的LSY201B这款语音模块,写出来安利一下 程序源码:SuiXinSc/Speech-Module (github.com) 或者进入Q群找我获取 目录 一,简要介绍: 硬件参数: 1,处理…

【pearcmd】通过pearcmd.php 进行GetShell

https://cloud.tencent.com/developer/article/2204400 关于PHP 配置 register_argc_argv 小结 的一些研究文章。 应用例题 [NewStarCTF 2023 公开赛道]Include &#x1f350; <?phperror_reporting(0);if(isset($_GET[file])) {$file $_GET[file];if(preg_match(/flag|l…

力扣第218题“天际线问题”

在本篇文章中&#xff0c;我们将详细解读力扣第218题“天际线问题”。通过学习本篇文章&#xff0c;读者将掌握如何使用扫描线算法和堆来解决这一问题&#xff0c;并了解相关的复杂度分析和模拟面试问答。每种方法都将配以详细的解释&#xff0c;以便于理解。 问题描述 力扣第…