thuml/depyf is an AI-powered project on GitHub with 813 stars, written primarily in Python. depyf is a tool to help you understand and adapt to PyTorch compiler torch.compile.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
depyf is proud to be a PyTorch ecosystem project. Check out the announcement blog https://pytorch.org/blog/introducing-depyf/ for more details.
Have you ever felt overwhelmed by the complexities of torch.compile? Diving into its workings can feel like black magic, with bytecode and Python internal details that many users fail to understand, hindering them from understanding and adapting to torch.compile.
If you also face the problem, then you might be interested in depyf. As the logo suggests, depyf is a software tool to leverage advanced Python features (the Python snake symbol) to open up internal details (the internal gears symbol) of PyTorch's compiler torch.compile (the PyTorch logo), so that users can understand it, adapt to it, and tune their code (the debugger symbol) to get maximum performance benefit out of it.
:warning: This project is developed under close collaborations with the PyTorch team. Therefore, it requires very new features from PyTorch to support better understanding of torch.compile. Please use this project along with PyTorch>=2.2.0 (PyTorch nightly is recommended). Visit the PyTorch website for how to install different versions of PyTorch.
:warning: During development, we seek suggestions from the community quite a lot. You may find some early usage examples from some discussion forums or social media platforms. Please follow the latest documentation for how to use this tool.
Why depyf?
If you want to understand bytecode generated by torch.compile, then depyf might be the only choice for you. Below we tested several existing decompilers, they struggle to decompile simple Python bytecode across versions, and have poor support for PyTorch.
Decompiler
Python 3.8
Python 3.9
Python 3.10
Python 3.11
PyTorch
decompyle3
90.6% (77/85)
×
×
×
×
uncompyle6
91.8% (78/85)
×
×
×
×
pycdc
74.1% (63/85)
74.1% (63/85)
74.1% (63/85)
67.1% (57/85)
19.3% (27/140)
depyf
100% (85/85)
100% (85/85)
100% (85/85)
100% (85/85)
100% (140/140)
Installation
Stable release: pip install depyf
Nightly version (recommended): pip install git+https://github.com/thuml/depyf.git
Usage
The main usage is quite simple: just wrap your code within a context manager:
import torch
from torch import _dynamo as torchdynamo
from typing import List
@torch.compile
def toy_example(a, b):
x = a / (torch.abs(a) + 1)
if b.sum() < 0:
b = b * -1
return x * b
def main():
for _ in range(100):
toy_example(torch.randn(10), torch.randn(10))
if __name__ == "__main__":
# main()
# surround the code you want to run inside `with depyf.prepare_debug`
import depyf
with depyf.prepare_debug("./dump_src_dir"):
main()
Then you can see all the details of torch.compile inside the directory ./dump_src_dir. The details are organized into the following:
full_code_for_xxx.py for each function using torch.compile
__transformed_code_for_xxx.py for Python code associated with each graph.
__transformed_code_for_xxx.py.xxx_bytecode for Python bytecode, dumped code object, can be loaded via dill.load(open("/path/to/file", "wb")). Note that the load function might import some modules like transformers. Make sure you have these modules installed.
__compiled_fn_xxx.py for each computation graph and its optimization:
Captured Graph: a plain forward computation graph
Joint Graph: joint forward-backward graph from AOTAutograd
Forward Graph: forward graph from AOTAutograd
Backward Graph: backward graph from AOTAutograd
kernel xxx: compiled CPU/GPU kernel wrapper from Inductor.
We collect all the compilation artifacts when testing over 100 deep learning models. You can take a look to learn how the PyTorch compiler works.
If you want to use debugger to step through the above code, just add another context manager (and launch the script through debuggers):
import torch
from torch import _dynamo as torchdynamo
from typing import List
@torch.compile
def toy_example(a, b):
x = a / (torch.abs(a) + 1)
if b.sum() < 0:
b = b * -1
return x * b
def main():
for _ in range(100):
toy_example(torch.randn(10), torch.randn(10))
if __name__ == "__main__":
import depyf
with depyf.prepare_debug("./dump_src_dir"):
main()
# surround the code you want to debug inside `with depyf.debug()`
with depyf.debug():
main()
Calling depyf.debug() will pause the program for you to set breakpoints, and then you can use debuggers to hit breakpoints in these files under the ./dump_src_dir directory you specified above.
Contact
If you have any question about depyf, feel free to open issues to reach out! Any discussion/issue report/PR is welcome. Or contact [email protected] if you have any other questions.
Citing depyf
If you find depyf useful, please cite it in your publications.
@article{you2024depyf,
title={depyf: Open the Opaque Box of PyTorch Compiler for Machine Learning Researchers},
author={Kaichao You and Runsheng Bai and Meng Cao and Jianmin Wang and Ion Stoica and Mingsheng Long},
year={2024},
eprint={2403.13839},
journal={arXiv},
primaryClass={cs.LG},
url={https://github.com/thuml/depyf}
}
The most recent commit recorded on thuml/depyf was 1.0 years ago, based on the GitHub push timestamp. The repository has 30 forks — one of the better signals of community interest.
How many stars does thuml/depyf have?
thuml/depyf has 813 GitHub stars — refresh the page for the live number, or check github.com/thuml/depyf. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is thuml/depyf open source?
Yes — thuml/depyf ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/thuml/depyf.
What else is in the AI Tools space?
thuml/depyf is tracked by TopGit under the AI Tools category, alongside 3 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What is thuml/depyf?
thuml/depyf (thuml/depyf) is a Python project on GitHub. From the project's own README: depyf is a tool to help you understand and adapt to PyTorch compiler torch.compile.
What language is thuml/depyf written in?
thuml/depyf is written primarily in Python. GitHub's language field is based on the largest share of bytes in the default branch.
What license does thuml/depyf use?
thuml/depyf is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
Where do I read more about thuml/depyf?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/thuml/depyf is the definitive source.
Read full README in the tab above.
Is depyf worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of depyf.