Try GitHub - Stonesjtu/pytorch_memlab: Profiling and inspecting memory in pytorch 41, though it may be easier to just manually wrap some code blocks and measure usage deltas (of cuda.memory_allocated).