Skip to main content

Super-lightweight line-by-line memory profiler for numerical Python code. See where those allocations are coming from! Supports NumPy, PyTorch, and more to come.

Project description

MemoryLane 💾🛣️

PyPI License: Apache 2.0

by Peter Sharpe


A super-lightweight line-by-line memory profiler for numerical Python code. See where those pesky allocations are coming from!

  • Supports PyTorch CUDA memory measurement, and more to come.
  • Minimal dependencies (just Rich + your favorite numerical library)

Installation

pip install memorylane[torch]  # For PyTorch support

Usage

To use MemoryLane, just import it and decorate your function with @profile:

import torch
from memorylane import profile

@profile
def my_function():
    x = torch.randn(5120, 5120, device="cuda")
    x = x @ x
    x = x.relu()
    x = x.mean()
    return x

my_function()

This will print your line-by-line memory usage:

terminal

Features

  • For complicated functions, filter the report to only show lines with non-negligible changes in memory usage: @profile(only_show_significant=True)
  • When used from terminal via most editors (e.g., VSCode/Cursor, PyCharm, etc.), the printouts like make_reports.py:11 become clickable links that will take you directly to the offending line in your code
  • Profiling of multiple functions, including nested ones (these will be shown with indentation, to allow you to see where the allocations are coming from)
  • Report generation in HTML and text formats
  • (Work in progress) Support for measuring memory usage of:
    • PyTorch CPU operations
    • NumPy operations
    • JAX operations
    • Python whole-process memory usage
    • ...and more!

Examples

Under construction - for now, see the examples folder!

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

memorylane-0.1.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

memorylane-0.1.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file memorylane-0.1.1.tar.gz.

File metadata

  • Download URL: memorylane-0.1.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for memorylane-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a07729a422a5f6d4048fc7985b511b785aad257b07a44209b027717220fc2dab
MD5 b8e6e1aa85db5ffd26c68564066534d2
BLAKE2b-256 cf29c347be9e39867eb9d983fad1afb31cf8164b90c267f53fc7fafa44661887

See more details on using hashes here.

File details

Details for the file memorylane-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for memorylane-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b4072fc9e2abb374967509d0873cac99a3c0647e5b1537ffc287ca9f618ca84
MD5 6df1c28d86182e1eff43014d534c8ef8
BLAKE2b-256 e5e348c794aae5bc3f0ec9b13b8faea8731901cae10bad72496001080b2f554e

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