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.0.tar.gz (4.3 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.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torch_snapkit-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","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.0.tar.gz
Algorithm Hash digest
SHA256 141012d30aef66c7eae9b64ec426e96cc7a9e6c7afda0c9673079e149064adc2
MD5 7b53ea36600efeb735e6c00014a45c8c
BLAKE2b-256 7c5f82be7dfbced310acbb9a6e4eb6c556960aabf98eca775733fd8ad6608ea8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torch_snapkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 830db830a3380a343b9914a180882d0b2792def39fe140481a6a13e70aabafd3
MD5 cf1fcf23105986a84649a6ca0635b5f0
BLAKE2b-256 4f8c3da9b64fa2bff60baec15ff3328d6f404328f4dc2290cfa5175c51e460a4

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