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.4.tar.gz (5.0 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.4-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torch_snapkit-0.1.4.tar.gz
  • Upload date:
  • Size: 5.0 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.4.tar.gz
Algorithm Hash digest
SHA256 9d5798afe9ebce20f2ca295b61b140e76fc1ab80f06fdf1404293eb1f13a416c
MD5 7e16bb8397e8bf8f9977731e119e027a
BLAKE2b-256 4b101394a8604073f983e8e52836939462970393273a1464af6321cfd73ed35a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torch_snapkit-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 83f77e557e05beb3e0e3cf2682ab4dbd2c4b5be8c5d685c34eb1308b96e4dad4
MD5 7b4ff3d447154910ee9e112b5b8157f6
BLAKE2b-256 b5a5783a1be2863c81db630ff960b8a4fbbc608b52675a6126088e79e1d09924

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