Skip to content

Commit

Permalink
memory annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
t-vi committed Dec 20, 2024
1 parent ddc779d commit 05a2a66
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion thunder/examine/memory_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def clear_mutable_collection_argument_memory(
return memory_size


def get_alloc_memory(trc: TraceCtx) -> tuple[int, dict[str, int]]:
def get_alloc_memory(trc: TraceCtx, *, annotate=False) -> tuple[int, dict[str, int]]:
"""
Calculate the memory usage based on the executable trace.
The memory calculation is based only on the compile-time trace, i.e. the input and output shape
Expand Down Expand Up @@ -189,6 +189,10 @@ def get_alloc_memory(trc: TraceCtx) -> tuple[int, dict[str, int]]:
impl = partial(impl, is_argument=is_argument)

allocated += impl(bsym, tensor_to_memory_data, name_to_alloc_memory)
if annotate:
if bsym.header:
bsym.header += ' '
bsym.header += f'mem after next op: ~{allocated/(2**30):2f}GB'
max_allocated = max(max_allocated, allocated)

return max_allocated, name_to_alloc_memory

0 comments on commit 05a2a66

Please sign in to comment.