tsalib  by ofnote

Tensor Shape Annotation Library (tsalib) enables named tensor dimensions

created 6 years ago
267 stars

Top 96.7% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This library provides Tensor Shape Annotations (TSA) for popular deep learning frameworks like NumPy, TensorFlow, and PyTorch, enabling users to name tensor dimensions for improved code clarity and debugging. It targets researchers and engineers working with complex tensor manipulations, offering a way to manage and verify tensor shapes more intuitively.

How It Works

tsalib leverages Python's type annotations and a custom shorthand notation (TSN) to associate names with tensor dimensions. It allows users to declare dimension variables (e.g., B, C, H, W = dvs('Batch(b):32 ...')) and use these names directly in tensor creation and shape assertions. A key feature is the warp operator, which composes multiple shape transformations (like reshape, permute) into a single, readable line using TSN. This approach simplifies complex tensor operations and enhances code maintainability.

Quick Start & Requirements

  • Install: pip install tsalib
  • Dependencies: sympy
  • Python version: >= 3.5 for type annotations, tested with 3.6, 3.7.
  • Documentation: Working documentation notebook

Highlighted Details

  • Supports NumPy, TensorFlow, PyTorch, Keras, MXNet backends.
  • warp operator for composing multiple shape transformations inline.
  • join, alignto, reduce_dims, and dot operators for tensor manipulation.
  • Enables symbolic shape assertions that remain valid even if dimension sizes change.
  • Annotated BERT and OpenAI Transformer models available for demonstration.

Maintenance & Community

  • Author: Nishant Sinha, OffNote Labs.
  • Contributions and feedback are welcome.
  • Last update mentioned: May 2020 (for update_dim_vars_len).

Licensing & Compatibility

  • License: Not explicitly stated in the README. (Requires clarification for commercial use).
  • Compatibility: Designed for progressive adoption with minimal code changes.

Limitations & Caveats

The library's last update was in May 2020, indicating potential staleness. While it mentions support for multiple backends, the warp operator is backend-dependent, and the README does not specify which backends are currently fully maintained or tested. The license is not clearly stated, which could be a barrier for commercial adoption.

Health Check
Last commit

5 years ago

Responsiveness

Inactive

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

Explore Similar Projects

Starred by Dominik Moritz Dominik Moritz(Professor at CMU; ML Researcher at Apple), Stas Bekman Stas Bekman(Author of Machine Learning Engineering Open Book; Research Engineer at Snowflake), and
2 more.

ecco by jalammar

0%
2k
Python library for interactive NLP model visualization in Jupyter notebooks
created 4 years ago
updated 11 months ago
Feedback? Help us improve.