MemoryLane 💾🛣️
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:
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:11become 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!
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a07729a422a5f6d4048fc7985b511b785aad257b07a44209b027717220fc2dab
|
|
| MD5 |
b8e6e1aa85db5ffd26c68564066534d2
|
|
| BLAKE2b-256 |
cf29c347be9e39867eb9d983fad1afb31cf8164b90c267f53fc7fafa44661887
|
File details
Details for the file memorylane-0.1.1-py3-none-any.whl.
File metadata
- Download URL: memorylane-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b4072fc9e2abb374967509d0873cac99a3c0647e5b1537ffc287ca9f618ca84
|
|
| MD5 |
6df1c28d86182e1eff43014d534c8ef8
|
|
| BLAKE2b-256 |
e5e348c794aae5bc3f0ec9b13b8faea8731901cae10bad72496001080b2f554e
|