A Python library for automatic differentiation that generates readable Python source code as its derivative output.
Tangent is a Python library for automatic differentiation that generates human-readable Python source code as its derivative output. It performs ahead-of-time autodiff directly on the Python source code, unlike runtime tracing or graph-based approaches, solving the problem of opaque and hard-to-debug derivative computations in machine learning.
Researchers and students in machine learning who want to write models in Python and need to read, debug, or manipulate automatically generated derivative code without sacrificing speed or flexibility.
Developers choose Tangent for its unique source-to-source approach, which produces debuggable and transparent derivative code, supports custom gradients and control flow, and integrates with TensorFlow and NumPy while offering both reverse-mode and forward-mode autodiff.
Source-to-Source Debuggable Derivatives in Pure Python
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Tangent generates derivative code as Python source, allowing developers to read and debug autodiff output directly, unlike opaque runtime tracing or graph-based methods.
It handles if-statements, loops, and subroutines with proper bookkeeping, enabling autodiff on complex Python logic without sacrificing transparency.
Users can define and register custom gradients using a template-based system, providing fine-grained control for advanced research or specific function derivatives.
Supports inserting breakpoints or custom code like gradient clipping into backward passes, making it easier to debug issues or implement derivative tweaks.
The project is an experimental release with active development, leading to potential API changes and bugs, which risks stability for production use.
Tangent does not support closures and has limited class support, restricting its use with advanced Python paradigms and object-oriented code.
Registering custom gradients requires understanding a non-standard template system with syntax like d[x], which can be less intuitive than other libraries' approaches.