mirror of https://github.com/hpcaitech/ColossalAI
[zero] refactor memstats collector (#706)
* refactor memstats collector * fix disposable * polish codepull/710/head
parent
3fc8a204dc
commit
ab8c6b4a0e
@ -1,16 +0,0 @@
|
||||
from async_memtracer import AsyncMemoryMonitor
|
||||
import torch
|
||||
|
||||
if __name__ == '__main__':
|
||||
async_mem_monitor = AsyncMemoryMonitor()
|
||||
input = torch.randn(2, 20).cuda()
|
||||
OP1 = torch.nn.Linear(20, 30).cuda()
|
||||
OP2 = torch.nn.Linear(30, 40).cuda()
|
||||
|
||||
async_mem_monitor.start()
|
||||
output = OP1(input)
|
||||
async_mem_monitor.finish()
|
||||
async_mem_monitor.start()
|
||||
output = OP2(output)
|
||||
async_mem_monitor.finish()
|
||||
async_mem_monitor.save('log.pkl')
|
@ -1,37 +0,0 @@
|
||||
from colossalai.utils.memory_tracer.memstats_collector import MemStatsCollector
|
||||
import torch
|
||||
|
||||
|
||||
def test_mem_collector():
|
||||
collector = MemStatsCollector()
|
||||
|
||||
collector.start_collection()
|
||||
|
||||
a = torch.randn(10).cuda()
|
||||
|
||||
# sampling at time 0
|
||||
collector.sample_memstats()
|
||||
|
||||
m_a = torch.randn(10).cuda()
|
||||
b = torch.randn(10).cuda()
|
||||
|
||||
# sampling at time 1
|
||||
collector.sample_memstats()
|
||||
|
||||
a = b
|
||||
|
||||
# sampling at time 2
|
||||
collector.sample_memstats()
|
||||
|
||||
collector.finish_collection()
|
||||
collector.reset_sampling_cnter()
|
||||
|
||||
# do nothing after collection, just advance sampling cnter
|
||||
collector.sample_memstats()
|
||||
collector.sample_memstats()
|
||||
|
||||
print(collector.overall_mem_stats('cuda'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_mem_collector()
|
Loading…
Reference in new issue