Skip to content

Added the TraceDiff API to TraceLens#241

Merged
ajassani merged 7 commits intomainfrom
spanmore/TraceDiff/sandbox
Aug 12, 2025
Merged

Added the TraceDiff API to TraceLens#241
ajassani merged 7 commits intomainfrom
spanmore/TraceDiff/sandbox

Conversation

@spandoesai
Copy link
Copy Markdown
Collaborator

TraceDiff is a standalone tool that allows in-depth structural comparison of execution traces across different backend engines and hardware platforms. This tool is now available as an API in TraceLens.

Features:

  • Print differences in tree structures in text format
  • Visualize differences in performance statistics more efficiently

(Closes #23)

@spandoesai spandoesai marked this pull request as ready for review July 29, 2025 00:09
@ajassani ajassani self-requested a review August 4, 2025 14:56
@ajassani ajassani requested a review from Copilot August 12, 2025 19:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates the TraceDiff API into TraceLens, enabling in-depth structural comparison of execution traces across different backend engines and hardware platforms. TraceDiff provides automated tree comparison, detailed diff visualization, and comprehensive statistical reporting.

Key changes:

  • Added TraceDiff as a new module with core diff algorithm implementation
  • Provided comprehensive documentation explaining API usage and output interpretation
  • Created example notebook demonstrating practical usage with real traces

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
TraceLens/TraceDiff/trace_diff.py Core TraceDiff implementation with tree merging, diff boundaries calculation, and statistical reporting
TraceLens/TraceDiff/init.py Module initialization exporting TraceDiff class
TraceLens/init.py Updated main package imports to include TraceDiff
docs/TraceDiff.md Comprehensive documentation with API usage examples and output interpretation
examples/trace_diff_example.ipynb Complete notebook example demonstrating TraceDiff functionality
Comments suppressed due to low confidence (2)

TraceLens/TraceDiff/trace_diff.py:59

  • Variables 'path1' and 'path2' are used but 'trace_file1' and 'trace_file2' are defined. This will cause a NameError at runtime.
        pod.update(uid)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


def get_kernel_info_subtree(root_uid, tree_uid2node):
node = tree_uid2node.get(root_uid)
gpu_event_uids = node['gpu_events']
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing 'gpu_events' key without checking if it exists will cause a KeyError if the key is missing from the node dictionary.

Suggested change
gpu_event_uids = node['gpu_events']
gpu_event_uids = node.get('gpu_events', [])

Copilot uses AI. Check for mistakes.
def get_kernel_info_subtree(root_uid, tree_uid2node):
node = tree_uid2node.get(root_uid)
gpu_event_uids = node['gpu_events']
gpu_events = [tree_uid2node.get(uid) for uid in gpu_event_uids]
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list comprehension can include None values if UIDs are not found in tree_uid2node, which will cause errors in subsequent operations.

Suggested change
gpu_events = [tree_uid2node.get(uid) for uid in gpu_event_uids]
gpu_events = [tree_uid2node.get(uid) for uid in gpu_event_uids if tree_uid2node.get(uid) is not None]

Copilot uses AI. Check for mistakes.
node = tree_uid2node.get(root_uid)
gpu_event_uids = node['gpu_events']
gpu_events = [tree_uid2node.get(uid) for uid in gpu_event_uids]
kernel_names = [gpu_event['name'] for gpu_event in gpu_events]
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will raise a TypeError if any gpu_event is None (from the previous line) or a KeyError if 'name' key doesn't exist in the gpu_event dictionary.

Suggested change
kernel_names = [gpu_event['name'] for gpu_event in gpu_events]
kernel_names = [gpu_event['name'] for gpu_event in gpu_events if gpu_event is not None and 'name' in gpu_event]

Copilot uses AI. Check for mistakes.
"trace_file2 = \"/path/to/trace2.json\"\n",
"\n",
"perf_analyzer1 = TreePerfAnalyzer.from_file(path1)\n",
"perf_analyzer2 = TreePerfAnalyzer.from_file(path2)\n",
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example uses placeholder paths that won't work. Consider adding a note about updating these paths or providing sample trace files.

Suggested change
"perf_analyzer2 = TreePerfAnalyzer.from_file(path2)\n",
"perf_analyzer1 = TreePerfAnalyzer.from_file(trace_file1)\n",
"perf_analyzer2 = TreePerfAnalyzer.from_file(trace_file2)\n",

Copilot uses AI. Check for mistakes.
"trace_file2 = \"/path/to/trace2.json\"\n",
"\n",
"perf_analyzer1 = TreePerfAnalyzer.from_file(path1)\n",
"perf_analyzer2 = TreePerfAnalyzer.from_file(path2)\n",
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example uses placeholder paths that won't work. Consider adding a note about updating these paths or providing sample trace files.

Suggested change
"perf_analyzer2 = TreePerfAnalyzer.from_file(path2)\n",
"# TODO: Update the paths above to your actual trace files before running this cell.\n",
"\n",
"perf_analyzer1 = TreePerfAnalyzer.from_file(trace_file1)\n",
"perf_analyzer2 = TreePerfAnalyzer.from_file(trace_file2)\n",

Copilot uses AI. Check for mistakes.
@ajassani ajassani merged commit 1f944be into main Aug 12, 2025
1 check passed
@ajassani ajassani deleted the spanmore/TraceDiff/sandbox branch August 12, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tracediff into iLoveTrace [medium term]

3 participants