depyf
Decompile python functions, from bytecode to source code!
What it is and what it does
depyf is a debugging and introspection tool for PyTorch's torch.compile compiler. It intercepts the bytecode and intermediate representations generated during compilation and writes them to disk in human-readable form, letting you see what torch.compile is actually doing to your code. The tool outputs the original source, transformed Python code, raw bytecode (loadable via dill), and the computation graphs at each optimization stage (captured graph, joint graph, forward/backward graphs, and compiled kernels).
The package is designed for machine learning researchers and practitioners who need to understand, debug, or optimize code compiled with torch.compile. It wraps your code in context managers that intercept compilation artifacts, and optionally integrates with debuggers so you can step through the compiled code. It requires PyTorch 2.2.0 or newer and depends on astor and dill for code generation and bytecode serialization.
Use it for:
- Debug why torch.compile is not optimizing a function as expected by inspecting the captured and optimized graphs.
- Understand the bytecode transformations torch.compile applies to your code to identify performance bottlenecks.
- Inspect forward and backward graphs generated by AOTAutograd to verify gradient computation correctness.
- Step through compiled code in a debugger to trace execution flow and set breakpoints in generated functions.
- Analyze compiled CPU/GPU kernels produced by Inductor to understand hardware-level optimizations.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Decompile and inspect the internal bytecode and optimization graphs generated by PyTorch's torch.compile, converting compiled code back to readable Python source and intermediate representations.
Yes, if you use torch.compile and need to understand or debug its behavior. The tool fills a genuine gap—existing decompilers fail on PyTorch bytecode—and is backed by the PyTorch team. The aging maintenance status (305 days since last release) is a minor concern, but the repository is not archived and remains active. Install only if you have PyTorch>=2.2.0 available.
Install
depyf on PyPI
pip
pip install depyfuv
uv add depyfpoetry
poetry add depyfInstalling depyf
Before you install
Low friction: pure Python wheel with only two runtime dependencies (astor, dill). Maintenance status is aging—last release was 305 days ago—but the repository remains active with 815 stars and backed by PyTorch team collaboration.
License in practice
MIT license is permissive; you can use, modify, and distribute depyf freely in commercial and private projects without restriction.
Quickstart
pip install depyf
import depyf
with depyf.prepare_debug("./debug_output"):
# wrap your torch.compile code here
pass
Requires PyTorch>=2.2.0 (PyTorch nightly recommended). The package inspects internal torch.compile artifacts that depend on very recent PyTorch features.
Verify before relying
- Whether depyf works reliably with PyTorch versions between 2.2.0 and the current stable release, or if nightly is truly necessary for most use cases.
- Performance overhead or memory impact when running code under depyf.prepare_debug() or depyf.debug() context managers.
- Compatibility with custom torch.compile backends or non-standard compilation configurations.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — astor, dill |
| Maintenance | aging — 305 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,386,060/month — #2,640 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: depyf-0.20.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
decompyle3Decompyle3 translates Python bytecode back into…
copyleft · top 15,000 on PyPI
tlparsetlparse parses structured PyTorch torch.compile…
permissive · top 15,000 on PyPI
opt-einsum-fxOptimizes PyTorch einsum operations and…
permissive · top 15,000 on PyPI
torch-c-dlpack-extProvides an ahead-of-time compiled module for…
permissive · top 5,000 on PyPI
uncompyle6uncompyle6 translates Python bytecode back into…
copyleft · top 15,000 on PyPI
ast-decompilerConverts Python abstract syntax trees (ASTs)…
permissive · top 15,000 on PyPI
torchvisionTorchvision provides pre-built datasets, model…
permissive · top 1,000 on PyPI
modulegraph2Modulegraph2 builds and introspects a…
permissive · top 15,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
hoptorchProvides a safe wrapper around PyTorch's scan…
permissive · top 15,000 on PyPI