Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exir/memory_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ def apply_algo(
storage with tensors in the outer module.
TODO: make these optimizations once we have some baseline working.
"""

specs = update_all_tensors_lifetime(graph_module, graph_signature)
bufsizes: List[int] = algo(
graph_module, alignment, graph_signature, alloc_graph_input, alloc_graph_output
Expand Down
23 changes: 15 additions & 8 deletions util/activation_memory_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@
"""
nodes = graph.nodes
memory_timeline: List[Optional[MemoryTimeline]] = [None for _ in range(len(nodes))]
unique_specs = set()

Check failure on line 56 in util/activation_memory_profiler.py

View workflow job for this annotation

GitHub Actions / lintrunner / linux-job

MYPY var-annotated

Need type annotation for "unique_specs" (hint: "unique_specs: set[<type>] = ...") To disable, use ` # type: ignore[var-annotated]`
for _, node in enumerate(nodes):
if node.op == "output":
continue
if node.target == memory.alloc:
if node.target == memory.alloc or node.target == memory.view:
continue
tensor_specs = get_node_tensor_specs(node)
if tensor_specs is None:
Expand All @@ -65,6 +66,9 @@
# TODO: Make use of mem_id in the allocation info
if tensor_spec is None or tensor_spec.mem_id is None or tensor_spec.const:
continue
if tensor_spec in unique_specs:
continue
unique_specs.add(tensor_spec)
start, end = tensor_spec.lifetime
size = num_bytes_from_shape_and_dtype(
typing.cast(torch.Size, tensor_spec.shape), tensor_spec.dtype
Expand All @@ -75,6 +79,7 @@
memory_timeline_j = memory_timeline[j]
if memory_timeline_j is None:
memory_timeline_j = MemoryTimeline()
memory_timeline[j] = memory_timeline_j
assert memory_timeline_j
memory_timeline_j.allocations.append(
Allocation(
Expand Down Expand Up @@ -106,6 +111,7 @@
chrome_trace_filename: str,
enable_memory_offsets: bool = False,
method_name: str = "forward",
ommit_metadata: bool = False,
):
"""
Generate the memory timeline from the given ExecuTorch program.
Expand Down Expand Up @@ -151,13 +157,14 @@
e["pid"] = int(allocation.memory_id)
e["tid"] = tid
e["args"] = {}
e["args"]["op_name"] = f"{allocation.op_name}"
# ID refers to memory space, typically from 1 to N.
# For CPU, everything is allocated on one "space", other backends may have multiple.
e["args"]["Memory ID"] = allocation.memory_id
e["args"]["fqn"] = f"{allocation.fqn}"
e["args"]["source"] = f"{allocation.file_and_line_num}"
e["args"]["bytes"] = allocation.size_bytes
if not ommit_metadata:
e["args"]["op_name"] = f"{allocation.op_name}"
# ID refers to memory space, typically from 1 to N.
# For CPU, everything is allocated on one "space", other backends may have multiple.
e["args"]["Memory ID"] = allocation.memory_id
e["args"]["fqn"] = f"{allocation.fqn}"
e["args"]["source"] = f"{allocation.file_and_line_num}"
e["args"]["bytes"] = allocation.size_bytes
start_time += allocation_size_kb
trace_events.append(e)
tid += 1
Expand Down
Loading