tensorgrad  by thomasahle

Symbolic tensor manipulation for deep learning

Created 2 years ago
366 stars

Top 76.8% on SourcePulse

GitHubView on GitHub
Project Summary

A Python package for symbolic tensor manipulation, Tensorgrad merges PyTorch's machine learning framework capabilities with SymPy's symbolic computation strengths. It automatically simplifies complex tensor expressions and compiles symbolic derivatives into highly optimized, fused PyTorch programs. This framework is designed for researchers and engineers seeking precise control over machine learning computations, enabling novel approaches to gradient computation and performance optimization.

How It Works

The core of Tensorgrad lies in its symbolic graph representation of tensor operations. It allows users to define tensor computations and their derivatives symbolically, which are then automatically simplified and compiled into efficient, straight-line PyTorch code. This approach bypasses traditional automatic differentiation for specific operations, leading to fused kernels that can offer significant performance gains and reduced memory overhead, particularly for complex models like Transformers.

Quick Start & Requirements

Installation is straightforward via pip: uv pip install tensorgrad. For diagram visualizations, LaTeX/TikZ and poppler-utils are required (apt-get install texlive-luatex texlive-latex-extra texlive-fonts-extra poppler-utils). macOS users encountering PyTorch compilation errors may need to use Homebrew's LLVM compiler (brew install llvm, export CXX=/opt/homebrew/opt/llvm/bin/clang++). Examples are available via a playground or notebook. Further documentation and the Tensor Cookbook can be found at https://tensorcookbook.com, with API details at https://tensorcookbook.com/docs/api.

Highlighted Details

  • Symbolic Differentiation & Compilation: Generates fused PyTorch programs from symbolic gradients, enabling ahead-of-time optimization.
  • Named Tensors: Simplifies complex operations like multi-head attention by allowing named tensor edges instead of view/transpose gymnastics.
  • Optimized Kernels: Primitives like LayerNorm and Gelu gradients, as well as convolutions, are claimed to be faster than standard PyTorch autograd (convolutions 2-5x faster).
  • Advanced Operations: Supports symbolic computation of Hessians and expectations of functions with respect to Gaussian tensors.
  • Memory Efficiency: Compiles large gradient graphs that would naively require exabytes of intermediates into megabyte-scale nodes.

Maintenance & Community

No specific details regarding maintainers, community channels (e.g., Discord, Slack), or roadmap were found in the provided README.

Licensing & Compatibility

The license type and compatibility notes for commercial use were not explicitly stated in the provided README.

Limitations & Caveats

A specific workaround involving LLVM is necessary for PyTorch's torch.compile feature on macOS due to missing standard library headers in the default clang++. The project's documentation references a "draft" Tensor Cookbook, suggesting it may still be under active development.

Health Check
Last Commit

1 day ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
4 stars in the last 30 days

Explore Similar Projects

Starred by Awni Hannun Awni Hannun(Author of MLX; Research Scientist at Apple), Patrick Kidger Patrick Kidger(Core Contributor to JAX ecosystem), and
4 more.

einx by fferflo

0.6%
518
Tensor operation library using Einstein-inspired notation
Created 3 years ago
Updated 1 month ago
Starred by Sasha Rush Sasha Rush(Research Scientist at Cursor; Professor at Cornell Tech), Jeremy Howard Jeremy Howard(Cofounder of fast.ai), and
3 more.

tensordict by pytorch

0.2%
1k
PyTorch tensor container for efficient ML data handling
Created 3 years ago
Updated 16 hours ago
Starred by Travis Addair Travis Addair(Cofounder of Predibase), Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), and
10 more.

hummingbird by microsoft

0.0%
4k
Compiler for trained ML models into tensor computation
Created 6 years ago
Updated 11 months ago
Starred by Nat Friedman Nat Friedman(Former CEO of GitHub), Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), and
15 more.

FasterTransformer by NVIDIA

0.1%
6k
Optimized transformer library for inference
Created 5 years ago
Updated 2 years ago
Feedback? Help us improve.