Skip to content

Commit

Permalink
fill self_host_duration for backward node (#496)
Browse files Browse the repository at this point in the history
* fill self_host_duration for backward node

* use triple double quote for documentation of method
  • Loading branch information
guotuofeng committed Dec 20, 2021
1 parent eea0d25 commit 7c727cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 16 additions & 0 deletions tb_plugin/torch_tb_profiler/profiler/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@ class BackwardNode(OperatorNode):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def fill_stats(self):
"""Override the timestamps and duration for BackwardNode only
"""
self.children.sort(key=lambda x: (x.start_time, -x.end_time))
self.start_time = self.children[0].start_time
self.end_time = self.children[-1].end_time

self.self_host_duration = self.end_time - self.start_time
for child in self.children:
self.device_duration += child.device_duration
self.self_host_duration -= (child.end_time - child.start_time)
self.tc_total_duration += child.tc_total_duration
# Mark TC eligible as True if any child operator is TC eligible.
if not self.tc_eligible and child.tc_eligible:
self.tc_eligible = True


class RuntimeNode(HostNode):
def __init__(self, device_nodes: Optional[List['DeviceNode']] = None, **kwargs):
Expand Down
4 changes: 1 addition & 3 deletions tb_plugin/torch_tb_profiler/profiler/op_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,7 @@ def _build_backward_module(node: ModuleNode,
OpTreeBuilder._build_backward_module(child, parent, fwd_bwd_map, result)

if isinstance(node, ModuleNode) and parent and parent.children:
parent.children.sort(key=lambda x: (x.start_time, -x.end_time))
parent.start_time = parent.children[0].start_time
parent.end_time = parent.children[-1].end_time
parent.fill_stats()
parent.tid = parent.children[0].tid

@staticmethod
Expand Down

0 comments on commit 7c727cc

Please sign in to comment.