Memory Decomposition
The msLeaks tool adds Python interfaces to allow users to describe code segments.
Usage Method
The msLeaks tool provides Python interfaces and uses describe to mark a tensor, function, or code segment. There are three usage methods.
- Method 1: Use the decorator to wrap a function. The owner attribute of all memory allocation events in the function will be tagged with test1.
1 2 3 4 5
import msleaks.describe as describe @describe.describer(owner="test1") def train1(): pass
- Method 2: Use the with statement to mark the code block. The owner attribute of all memory allocation events in the block will be tagged with test2.Code example 1:
1 2 3 4
import msleaks.describe as describe with describe.describer(owner="test2"): train2()
Code example 2:1 2 3 4 5
import msleaks.describe as describe describe.describer(owner="test3").__enter__() train3() describe.describer(owner="test3").__exit__()
Methods 1 and 2 support a maximum of three tags, and the tags cannot be duplicate.
- Method 3: Mark a tensor. The owner attribute of the memory allocation event corresponding to the tensor is added with a user-specified tag.
1 2 3 4
import msleaks.describe as describe t = torch.randn(10,10).to('npu:0') describe.describer(t, owner="test4")
Result Description
For details about the output file of memory decomposition, see Output Description.
Parent topic: Memory Analysis