Relaxit: A Python Library for Optimizing Discrete Probability Distributions in Neural Networks
Project description
Just Relax It
Discrete Variables Relaxation
"Just Relax It" is a cutting-edge Python library designed to streamline the optimization of discrete probability distributions in neural networks, offering a suite of advanced relaxation techniques compatible with PyTorch.
📬 Assets
- Technical Meeting 1 - Presentation
- Technical Meeting 2 - Jupyter Notebook
- Technical Meeting 3 - Jupyter Notebook
- Blog Post 1
- Blog Post 2
- Documentation
- Tests
- Technical Report
💡 Motivation
For lots of mathematical problems we need an ability to sample discrete random variables. The problem is that due to continuous nature of deep learning optimization, the usage of truly discrete random variables is infeasible. Thus we use different relaxation methods. One of them, Concrete distribution or Gumbel-Softmax (this is one distribution proposed in parallel by two research groups) is implemented in different DL packages. In this project we implement different alternatives to it.
🗃 Algorithms
- Relaxed Bernoulli, also see 📝 paper
- Correlated relaxed Bernoulli, also see 📝 paper
- Gumbel-Softmax TOP-K, also see 📝 paper
- Straight-Through Bernoulli, also see 📝 paper
- Stochastic Times Smooth, also see 📝 paper
- Invertible Gaussian with KL implemented, also see 📝 paper
- Hard Concrete, also see 📝 paper
- Logistic-Normal and Laplace-form approximation of Dirichlet, also see ℹ️ wiki and 💻 stackexchange
- Generalized Gumbel-Softmax, also see 📝 paper
- REBAR, also see 📝 paper
- Decoupled Straight-Through Gumbel-Softmax, also see 📝 paper
- RELAX, also see 📝 paper
🛠️ Install Using uv (Recommended)
For Production
uv pip install relaxit
For Development
git clone https://github.com/intsystems/relaxit
cd relaxit
uv venv # create venv
source .venv/bin/activate # activate venv
uv sync # install all the dependencies
uv pip install -e . # make the relaxit package editable
To run tests:
uv run pytest tests/
To run Python scripts:
uv run python demo/vae_hard_concrete.py
To run notebooks:
uv run jupyter lab
⚒️ Install Using pip
For Production
pip install -r requirements.txt
For Development
pip install -r requirements-dev.txt
🚀 Quickstart
import torch
from relaxit.distributions import InvertibleGaussian
# initialize distribution parameters
loc = torch.zeros(3, 4, 5, requires_grad=True)
scale = torch.ones(3, 4, 5, requires_grad=True)
temperature = torch.tensor([1e-0])
# initialize distribution
distribution = InvertibleGaussian(loc, scale, temperature)
# sample with reparameterization
sample = distribution.rsample()
print('sample.shape:', sample.shape)
print('sample.requires_grad:', sample.requires_grad)
🎮 Demo
| Laplace Bridge | REINFORCE in Acrobot environment | VAE with discrete latents |
|---|---|---|
For demonstration purposes, we divide our algorithms in three[^*] different groups. Each group relates to the particular demo code:
- Laplace bridge between Dirichlet and LogisticNormal distributions
- REINFORCE
- RELAX
- Other relaxation methods
We describe our demo experiments here.
[^*]: We also implement REINFORCE algorithm as a score function estimator alternative for our relaxation methods that are inherently pathwise derivative estimators. This one is implemented only for demo experiments and is not included into the source code of package.
📚 Stack
Some of the alternatives for GS were implemented in pyro, so we base our library on their codebase.
🧩 Some details
To make to library consistent, we integrate imports of distributions from pyro and torch into the library, so that all the categorical distributions can be imported from one entrypoint.
👥 Contributors
- Daniil Dorin (Basic code writing, Final demo, Algorithms)
- Igor Ignashin (Project wrapping, Documentation writing, Algorithms)
- Nikita Kiselev (Project planning, Blog post, Algorithms)
- Andrey Veprikov (Tests writing, Documentation writing, Algorithms)
- Vladislav Minashkin (Project planning, Visualizations, Algorithms)
- Papay Ivan (Documentation writing, Blog post, Algorithms)
- Meshkov Vlad (Benchmarking, Demo, Algorithms)
- Stepanov Ilya (Tech. report, Code writing, Algorithms)
- You are welcome to contribute to our project!
🔗 Useful links
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file relaxit-1.2.1.tar.gz.
File metadata
- Download URL: relaxit-1.2.1.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05a53e2fe69b5d576ebe96e89856ed4d37e9c57543c9af6d19137e422ed60aca
|
|
| MD5 |
d13f546edc9cfd312606008fbfb012cd
|
|
| BLAKE2b-256 |
5b075357b449ea8ef54d4ac44db282098477b9954d1f1f795ea3811d19ffada3
|
Provenance
The following attestation bundles were made for relaxit-1.2.1.tar.gz:
Publisher:
pypi.yml on intsystems/relaxit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
relaxit-1.2.1.tar.gz -
Subject digest:
05a53e2fe69b5d576ebe96e89856ed4d37e9c57543c9af6d19137e422ed60aca - Sigstore transparency entry: 780537771
- Sigstore integration time:
-
Permalink:
intsystems/relaxit@bf7fa50d0916f950b375ca67e82e2c7879de0b61 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/intsystems
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@bf7fa50d0916f950b375ca67e82e2c7879de0b61 -
Trigger Event:
push
-
Statement type:
File details
Details for the file relaxit-1.2.1-py3-none-any.whl.
File metadata
- Download URL: relaxit-1.2.1-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91e2bf1522abb8060bbe6f41ac3ffe198d4c54ed52d23e0d5532b7c087c1430d
|
|
| MD5 |
f727390820263d7512891d1171793aa0
|
|
| BLAKE2b-256 |
393e6505b4440e04aaa15f0e886212eb32622a0a9f121f1b84bf3c38c023de1c
|
Provenance
The following attestation bundles were made for relaxit-1.2.1-py3-none-any.whl:
Publisher:
pypi.yml on intsystems/relaxit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
relaxit-1.2.1-py3-none-any.whl -
Subject digest:
91e2bf1522abb8060bbe6f41ac3ffe198d4c54ed52d23e0d5532b7c087c1430d - Sigstore transparency entry: 780537772
- Sigstore integration time:
-
Permalink:
intsystems/relaxit@bf7fa50d0916f950b375ca67e82e2c7879de0b61 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/intsystems
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@bf7fa50d0916f950b375ca67e82e2c7879de0b61 -
Trigger Event:
push
-
Statement type: