Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Profiling and inspecting memory in pytorch
| Date | Stars |
|---|---|
| 2026-07-24 | 1078 |
| 2026-07-25 | 1078 |
| 2026-07-28 | 1078 |
| 2026-07-30 | 1078 |
| 2026-08-06 | 1078 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
pytorch_memlab
======
[](https://github.com/Stonesjtu/pytorch_memlab/actions/workflows/test.yml)
[](https://github.com/Stonesjtu/pytorch_memlab/actions/workflows/pypi-publish.yml)

[](https://github.com/Stonesjtu/pytorch_memlab/actions/workflows/github-code-scanning/codeql)

A simple and accurate **CUDA** memory management laboratory for pytorch,
it consists of different parts about the memory:
- Features:
- Memory Profiler: A `line_profiler` style CUDA memory profiler with simple API.
- Memory Reporter: A reporter to inspect tensors occupying the CUDA memory.
- Courtesy: An interesting feature to temporarily move all the CUDA tensors into
CPU memory for courtesy, and of course the backward transferring.
- IPython support through `%mlrun`/`%%mlrun` line/cell magic
commands.
- Table of Contents
* [Installation](#installation)
* [User-Doc](#user-doc)
+ [Memory Profiler](#memory-profiler)
+ [IPython support](#ipython-support)
+ [Memory Reporter](#memory-reporter)
+ [Courtesy](#courtesy)
+ [ACK](#ack)
* [CHANGES](#changes)
Installation
-----
- Released version:
```bash
pip install pytorch_memlab
```
- Newest version:
```bash
pip install git+https://github.com/stonesjtu/pytorch_memlab
```
What's for
-----
Out-Of-Memory errors in pytorch happen frequently, for new-bees and
experienced programmers. A common reason is that most people don't really
learn the underlying memory management philosophy of pytorch and GPUs.
They wrote memory in-efficient codes and complained about pytorch eating too
much CUDA memory.
In this repo, I'm going to share some useful tools to help debugging OOM, or
to inspect the underlying mechanism if anyone is interested in.
User-Doc
-----
### Memory Profiler
The memory profiler is a modification of python's `line_profiler`, it gives
the memory usage info for each line of code in the specified function/method.
#### Sample:
```python
import torch
from pytorch_memlab import LineProfiler
def inner():
torch.nn.Linear(100, 100).cuda()
def outer():
linear = torch.nn.Linear(100, 100).cuda()
linear2 = torch.nn.Linear(100, 100).cuda()
linear3 = torch.nn.Linear(100, 100).cuda()
work()
```
After the script finishes or interrupted by keyboard, it gives the following
profiling info if you're in a Jupyter notebook:
<p align="center"><img src="readme-output.png" width="640"></p>
or the following info if you're in a text-only terminal:
```
## outer
active_bytes reserved_bytes line code
all all
peak peak
0.00B 0.00B 7 def outer():
40.00K 2.00M 8 linear = torch.nn.Linear(100, 100).cuda()
80.00K 2.00M 9 linear2 = torch.nn.Linear(100, 100).cuda()
120.00K 2.00M 10 inner()
## inner
active_bytes reserved_bytes line code
all all
peak peak
80.00K 2.00M 4 def inner():
120.00K 2.00M 5 torch.nn.Linear(100, 100).cuda()
```
An explanation of what each column means can be found in the [Torch documentation](https://pytorch.org/docs/stable/cuda.html#torch.cuda.memory_stats). The name of any field from `memory_stats()`
can be passed to `display()` to view the corresponding statistic.
If you use `profile` decorator, the memory statistics are collected during
multiple runs and only the maximum one is displayed at the end.
We also provide a more flexible API called `profile_every` which prints the
memory info every *N* Excerpt of 18,108 characters
Read on GitHub75
Yi Wang · Facebook · United States
3
Will Price · United Kingdom
2
1
1
1
1
1
1
Stas Bekman · Stasosphere Online Inc. / · Canada
1
Shantanu · @OpenAI
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:017d9dee6df28032, topic:pytorch