Access GPU memory usage in Pytorch

Hi, thank you!
I found these functions later, but find that they did not match the nvidia-smi output. And what’s the difference between max_memory_allocated/cached V.S. memory_allocated/cached?

I raised these questions in Memory_cached and memory_allocated does not nvidia-smi result