Skip to main content
Just Relax It

Just Relax It

Discrete Variables Relaxation

Compatible with PyTorch Inspired by Pyro

Coverage_2 Coverage Docs

License GitHub Contributors Issues GitHub Pull Requests

"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

  1. Technical Meeting 1 - Presentation
  2. Technical Meeting 2 - Jupyter Notebook
  3. Technical Meeting 3 - Jupyter Notebook
  4. Blog Post 1
  5. Blog Post 2
  6. Documentation
  7. Tests
  8. 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

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

Open In Colab

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
Laplace Bridge REINFORCE VAE
Open In Colab Open In Colab Open In Colab

For demonstration purposes, we divide our algorithms in three1 different groups. Each group relates to the particular demo code:

We describe our demo experiments here.

📚 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

  1. 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. ↩

Metadata

Release files for relaxit 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for relaxit 1.2.1
File Size Uploaded
relaxit-1.2.1.tar.gz 25.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for relaxit 1.2.1
File Interpreter ABI Platform
relaxit-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 62.2 kB

Release files / relaxit-1.2.1.tar.gz

Download URL relaxit-1.2.1.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
05a53e2fe69b5d576ebe96e89856ed4d37e9c57543c9af6d19137e422ed60aca
BLAKE2b-256 checksum
How to use checksums
5b075357b449ea8ef54d4ac44db282098477b9954d1f1f795ea3811d19ffada3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 27, 2025.

Transparency log

Release files / relaxit-1.2.1-py3-none-any.whl

Download URL relaxit-1.2.1-py3-none-any.whl
Size 36.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91e2bf1522abb8060bbe6f41ac3ffe198d4c54ed52d23e0d5532b7c087c1430d
BLAKE2b-256 checksum
How to use checksums
393e6505b4440e04aaa15f0e886212eb32622a0a9f121f1b84bf3c38c023de1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 27, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page