Trace Diff using Holistic Trace Analysis — PyTorch Tutorials 2.7.0+cu126 documentation (original) (raw)

beginner/hta_trace_diff_tutorial

Run in Google Colab

Colab

Download Notebook

Notebook

View on GitHub

GitHub

Created On: Jan 02, 2024 | Last Updated: Jan 05, 2024 | Last Verified: Not Verified

Author: Anupam Bhatnagar

Occasionally, users need to identify the changes in PyTorch operators and CUDA kernels resulting from a code change. To support this requirement, HTA provides a trace comparison feature. This feature allows the user to input two sets of trace files where the first can be thought of as the _control group_and the second as the test group, similar to an A/B test. The TraceDiff class provides functions to compare the differences between traces and functionality to visualize these differences. In particular, users can find operators and kernels that were added and removed from each group, along with the frequency of each operator/kernel and the cumulative time taken by the operator/kernel.

The TraceDiff class has the following methods:

The last two methods can be used to visualize various changes in frequency and duration of CPU operators and GPU kernels, using the output of thecompare_traces method.

For example, the top ten operators with increase in frequency can be computed as follows:

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

../_images/counts_diff.png

Similarly, the top ten operators with the largest change in duration can be computed as follows:

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

For a detailed example of this feature see the trace_diff_demo notebookin the examples folder of the repository.