目录

使用整体追踪分析追踪差异

创建日期: 2024年1月2日 | 最后更新日期: 2024年1月5日 | 最后验证: 未验证

作者: 阿努帕姆·巴特纳加

偶尔,用户需要识别由于代码更改导致的PyTorch操作符和CUDA内核的变化。为了支持这一需求,HTA 提供了跟踪比较功能。此功能允许用户输入两组跟踪文件,第一组可以视为对照组,第二组可以视为测试组,类似于A/B测试。TraceDiff类提供了比较跟踪差异的功能,并且能够可视化这些差异。特别是,用户可以找到每组中新增和移除的操作符和内核,以及每个操作符/内核出现的频率和累计时间。

The TraceDiff 类 具有以下方法:

  • compare_traces: 比较两组跟踪数据中CPU操作和GPU内核的频率和总持续时间。

  • ops_diff: 获取已更改的操作符和内核。

    1. added to the test trace and are absent in the control trace

    2. deleted from the test trace and are present in the control trace

    3. increased in frequency in the test trace and exist in the control trace

    4. decreased in frequency in the test trace and exist in the control trace

    5. unchanged between the two sets of traces

  • visualize_counts_diff

  • visualize_duration_diff

最后两种方法可以用于可视化CPU操作和GPU内核的各种频率和持续时间的变化,使用的是 compare_traces 方法的输出。

例如,可以按频率计算出使用次数增加的前十个操作符,如下所示:

df = compare_traces_output.sort_values(by="diff_counts", ascending=False).head(10)
TraceDiff.visualize_counts_diff(df)
../_images/counts_diff.png

同样,可以按照以下方式计算出持续时间变化最大的前十个操作符:

df = compare_traces_output.sort_values(by="diff_duration", ascending=False)
# The duration differerence can be overshadowed by the "ProfilerStep",
# so we can filter it out to show the trend of other operators.
df = df.loc[~df.index.str.startswith("ProfilerStep")].head(10)
TraceDiff.visualize_duration_diff(df)
../_images/duration_diff.png

有关此功能的详细示例,请参阅存储库示例文件夹中的trace_diff_demo 笔记本

文档

访问 PyTorch 的全面开发人员文档

查看文档

教程

获取面向初学者和高级开发人员的深入教程

查看教程

资源

查找开发资源并解答您的问题

查看资源