Tensor-Train decomposition in pytorch.
Project description
torchTT
Tensor-Train decomposition in pytorch
Tensor-Train decomposition package written in Python on top of pytorch. Supports GPU acceleration and automatic differentiation.
It also contains routines for solving linear systems in the TT format and performing adaptive cross approximation (the AMEN solver/cross interpolation is inspired form the MATLAB TT-Toolbox).
Some routines are implemented in C++ for an increased execution speed.
Installation
Requirements
Following requirements are needed:
python>=3.8torch>=1.7.0numpy>=1.18opt_einsum
The GPU (if available) version of pytorch is recommended to be installed. Read the official installation guide for further info.
Using pip
You can install the package using the pip command:
pip install torchTT
The latest github version can be installed using:
pip install git+https://github.com/ion-g-ion/torchTT
One can also clone the repository and manually install the package:
git clone https://github.com/ion-g-ion/torchTT
cd torchTT
python setup.py install
Using uv
You can install the package using uv:
uv pip install torchTT
The latest github version can be installed using:
uv pip install git+https://github.com/ion-g-ion/torchTT
One can also clone the repository and install the package using uv:
git clone https://github.com/ion-g-ion/torchTT
cd torchTT
uv sync
Or install in editable mode:
uv pip install -e .
Development Installation
For development, you may want to install the package with additional development dependencies (pytest, sphinx, ipykernel, matplotlib):
Using pip:
pip install -e ".[dev]"
Using uv:
uv sync --extra dev
or
uv pip install -e ".[dev]"
This will install the package in editable mode along with all development tools needed for testing, building documentation, and working with Jupyter notebooks.
Components
The main modules/submodules that can be accessed after importing torchtt are briefly desctibed in the following table.
Detailed description can be found here.
| Component | Description |
|---|---|
torchtt |
Basic TT class and basic linear algebra functions. |
torchtt.solvers |
Implementation of the AMEN solver. |
torchtt.grad |
Wrapper for automatic differentiation. |
torchtt.manifold |
Riemannian gradient and projection onto manifolds of tensors with fixed TT rank. |
torchtt.nn |
Basic TT neural network layer. |
torchtt.interpolate |
Cross approximation routines. |
Tests
The directory tests/ from the root folder contains all the unittests. To run them use the command:
pytest tests/
Documentation and examples
The documentation can be found here. Following example scripts (as well as python notebooks) are also provied provided as part of the documentation:
- basic_tutorial.py / basic_tutorial.ipynp: This contains a basic tutorial on decomposing full tensors in the TT format as well as performing rank rounding, slicing (Try on Google Colab).
- basic_linalg.py / basic_linalg.ipynp: This tutorial presents all the algebra operations that can be performed in the TT format (Try on Google Colab).
- efficient_linalg.py / efficient_linalg.ipynb: contains the DMRG for fast matves and AMEN for elementwise inversion in the TT format (Try on Google Colab).
- automatic_differentiation.py / automatic_differentiation.ipynp: Basic tutorial on AD in
torchtt(Try on Google Colab). - cross_interpolation.py / cross_interpolation.ipynb: In this script, the cross interpolation emthod is exemplified (Try on Google Colab).
- system_solvers.py / system_solvers.ipynb: This contains the bais ussage of the multilinear solvers (Try on Google Colab).
- gpu_acceleration.py / gpu_acceleration.ipynb: This provides an example on how to use the GPU acceleration (Try on Google Colab).
- basic_nn.py / basic_nn.ipynb: This provides an example on how to use the TT neural network layers (Try on Google Colab).
- mnist_nn.py / mnist_nn.ipynb: Example of TT layers used for image classification (Try on Google Colab).
- manifold.py / manifold.ipynb: This demonstrates Riemannian gradient descent on manifolds of tensors with fixed TT rank (Try on Google Colab).
- random_tt.py: This script shows how to generate random TT tensors with different variances (Try on Google Colab).
- tensor_completion.py: This example demonstrates tensor completion using manifold learning with Riemannian gradient descent (Try on Google Colab).
Building Documentation
The documentation is generated using sphinx. To build it locally, you need:
-
Install development dependencies (see Development Installation above)
-
Install pandoc (required for rendering Jupyter notebooks):
- Ubuntu/Debian:
sudo apt install pandoc - macOS:
brew install pandoc - Windows:
choco install pandocor download from https://pandoc.org/installing.html
- Ubuntu/Debian:
-
Build the documentation:
make html
The generated documentation will be in _build/html/.
Author
Ion Gabriel Ion, e-mail: ion.ion.gabriel@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file torchtt-0.4.0.tar.gz.
File metadata
- Download URL: torchtt-0.4.0.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e04e41a6cc6b355b269b17072a0ea5e855026af6ef6bdd5dbfd2e59e731ee291
|
|
| MD5 |
2e99be902a0de10a64de0a516a9b4d93
|
|
| BLAKE2b-256 |
2e5b815c99bee6ea92ef99b8dd4473bb22e369ed91918f34b69f7029d338df89
|
Provenance
The following attestation bundles were made for torchtt-0.4.0.tar.gz:
Publisher:
publish.yml on ion-g-ion/torchTT
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchtt-0.4.0.tar.gz -
Subject digest:
e04e41a6cc6b355b269b17072a0ea5e855026af6ef6bdd5dbfd2e59e731ee291 - Sigstore transparency entry: 1999791968
- Sigstore integration time:
-
Permalink:
ion-g-ion/torchTT@40f0cba360cefcfc3d932c0c263f7306796599df -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ion-g-ion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@40f0cba360cefcfc3d932c0c263f7306796599df -
Trigger Event:
workflow_run
-
Statement type: