@@ -53,10 +53,11 @@ def create_tensor_allocation_info(graph: torch.fx.Graph) -> List[MemoryTimeline]
53
53
"""
54
54
nodes = graph .nodes
55
55
memory_timeline : List [Optional [MemoryTimeline ]] = [None for _ in range (len (nodes ))]
56
+ unique_specs = set ()
56
57
for _ , node in enumerate (nodes ):
57
58
if node .op == "output" :
58
59
continue
59
- if node .target == memory .alloc :
60
+ if node .target == memory .alloc or node . target == memory . view :
60
61
continue
61
62
tensor_specs = get_node_tensor_specs (node )
62
63
if tensor_specs is None :
@@ -65,6 +66,9 @@ def create_tensor_allocation_info(graph: torch.fx.Graph) -> List[MemoryTimeline]
65
66
# TODO: Make use of mem_id in the allocation info
66
67
if tensor_spec is None or tensor_spec .mem_id is None or tensor_spec .const :
67
68
continue
69
+ if tensor_spec in unique_specs :
70
+ continue
71
+ unique_specs .add (tensor_spec )
68
72
start , end = tensor_spec .lifetime
69
73
size = num_bytes_from_shape_and_dtype (
70
74
typing .cast (torch .Size , tensor_spec .shape ), tensor_spec .dtype
@@ -75,6 +79,7 @@ def create_tensor_allocation_info(graph: torch.fx.Graph) -> List[MemoryTimeline]
75
79
memory_timeline_j = memory_timeline [j ]
76
80
if memory_timeline_j is None :
77
81
memory_timeline_j = MemoryTimeline ()
82
+ memory_timeline [j ] = memory_timeline_j
78
83
assert memory_timeline_j
79
84
memory_timeline_j .allocations .append (
80
85
Allocation (
@@ -106,6 +111,7 @@ def generate_memory_trace(
106
111
chrome_trace_filename : str ,
107
112
enable_memory_offsets : bool = False ,
108
113
method_name : str = "forward" ,
114
+ ommit_metadata : bool = False ,
109
115
):
110
116
"""
111
117
Generate the memory timeline from the given ExecuTorch program.
@@ -151,13 +157,14 @@ def generate_memory_trace(
151
157
e ["pid" ] = int (allocation .memory_id )
152
158
e ["tid" ] = tid
153
159
e ["args" ] = {}
154
- e ["args" ]["op_name" ] = f"{ allocation .op_name } "
155
- # ID refers to memory space, typically from 1 to N.
156
- # For CPU, everything is allocated on one "space", other backends may have multiple.
157
- e ["args" ]["Memory ID" ] = allocation .memory_id
158
- e ["args" ]["fqn" ] = f"{ allocation .fqn } "
159
- e ["args" ]["source" ] = f"{ allocation .file_and_line_num } "
160
- e ["args" ]["bytes" ] = allocation .size_bytes
160
+ if not ommit_metadata :
161
+ e ["args" ]["op_name" ] = f"{ allocation .op_name } "
162
+ # ID refers to memory space, typically from 1 to N.
163
+ # For CPU, everything is allocated on one "space", other backends may have multiple.
164
+ e ["args" ]["Memory ID" ] = allocation .memory_id
165
+ e ["args" ]["fqn" ] = f"{ allocation .fqn } "
166
+ e ["args" ]["source" ] = f"{ allocation .file_and_line_num } "
167
+ e ["args" ]["bytes" ] = allocation .size_bytes
161
168
start_time += allocation_size_kb
162
169
trace_events .append (e )
163
170
tid += 1
0 commit comments