Skip to main content

Generate PyTorch CUDA memory snapshots for torch-memory-visualizer

Project description

Torch Snapkit

This is a light-weight wrapper around PyTorch's memory recording utils, that additionally attaches the source code of your files for later analysis. The snapshots are designed to be visualized with Torch Memory Visualizer, which helps tracking memory usage back to individual lines and shows you how much memory which of your modules used.

Example Usage

import torch
from torch import nn
from torch_snapkit import memory_snapshot

def main():
    model = nn.Sequential(nn.Linear(32, 10), nn.ReLU(), nn.Linear(10, 32))
    model.to(device='cuda')
    x = torch.randn((64, 32)).to(device='cuda')
    y = model(x)
    y.sum().backward()
 

if __name__=='__main__':
    with memory_snapshot('test_run', save_path='.'):
        main()

In addition, the memory_snapshot manager provides some convenient options:

  • on_oom: Configures PyTorch to save memory snapshots after OOM occured.
  • share: Enables you to quickly download the generated snapshots by using croc, a peer-to-peer filesharing tool. This flag is for situations where you generate your snapshots on a cloud instance, but want to inspect the stacktraces on your local machine.

Here is an example usage of the snapshot utility with share=True:

import torch
from torch import nn
from torch_snapkit import memory_snapshot

def main():
    model = nn.Sequential(nn.Linear(32, 10), nn.ReLU(), nn.Linear(10, 32))
    model.to(device='cuda')
    x = torch.randn((64, 32)).to(device='cuda')
    y = model(x)
    y.sum().backward()
 

if __name__=='__main__':
    with memory_snapshot('test_run_shared', share=True, share_code='your_secret_code'):
        main()

Then, on your local machine, you can either run

CROC_SECRET="your_secret_code" croc

after the remote run completed, or you can run

snapkit-receive your_secret_code

which just calls croc in a loop and downloads all files that are being send under that code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_snapkit-0.1.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_snapkit-0.1.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file torch_snapkit-0.1.3.tar.gz.

File metadata

  • Download URL: torch_snapkit-0.1.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for torch_snapkit-0.1.3.tar.gz
Algorithm Hash digest
SHA256 09c95f4601bb0f9290a4e91b34be8b8e5dc6921689c65d74224c0d893c094923
MD5 825983e7fbb605bc37ac2c9863e75b1a
BLAKE2b-256 bd4ceef5b0f83b70ece33acb46cf2cb3200701a037d68ad248e2af9bbb66cede

See more details on using hashes here.

File details

Details for the file torch_snapkit-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: torch_snapkit-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for torch_snapkit-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3eb2fb0b8f145410182c8acbcdd92796899a1981ecfa465204b6e3aff7d674ad
MD5 7f000af2dccd1e5e7721103e758ab554
BLAKE2b-256 dc9512304ec92a889e241c207b0036192d9ee2aea42f150e16723dadfdb35107

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page