Skip to main content

Relucent

Usable Latest Release

Relucent is a Python package for computing the polyhedra of ReLU networks! Its main features include:

  • Distributed calculation of the activation regions of ReLU networks via local search
  • Visualization of ReLU complexes in two or three dimensions with Plotly
  • Conversion of PyTorch networks built from Linear, ReLU, Conv2d, AvgPool2d, Flatten and Dropout layers, checked against the network's own forward pass
  • Computation of the complex's dual as a NetworkX Graph
  • Topology of the complex and of decision boundaries over GF(2): Betti numbers, persistent homology, and PL Morse critical points
  • Various calculations for individual activation regions, decision boundaries, and affine splines

Environment Setup

  • Core package only (without PyTorch): pip install relucent
  • With PyTorch support: pip install "relucent[torch]"

Development Check Modes

  • With torch (full checks): pip install ".[dev,torch]" && pytest
  • Without torch (optional-dependency compatibility): pip install ".[dev]" && pytest tests/test_no_torch.py

Getting Started

To see if the installation has been successful, try plotting the complex of a randomly initialized network in 2 dimensions like this:

import numpy as np
import torch.nn as nn
import relucent

if __name__ == "__main__":
    # Create Model
    network = nn.Sequential(
        nn.Linear(2, 10),
        nn.ReLU(),
        nn.Linear(10, 5),
        nn.ReLU(),
        nn.Linear(5, 1),
    )  ## or conveniently, relucent.mlp(widths=[2, 10, 5, 1])

    ## Initialize a Complex to track calculations
    cplx = relucent.Complex(network)

    ## Calculate the activation regions via local search
    cplx.bfs()

    ## Plotting functions return Plotly figures
    fig = cplx.plot()
    fig.show()

Given some input point, you could get a minimal H-representation of the polyhedral region containing it like this:

input_point = np.random.random((1, 2))
p = cplx.point2poly(input_point)
print(p.halfspaces[p.shis])

Attributes like p.halfspaces (halfspaces of the form Ax + b <= 0, in format [A; b], induced by each neuron), p.shis (the indices of the non-redundant halfspaces), and p.center (the Chebyshev center) are computed lazily.

You could also check the average number of faces of all polyhedra with:

sum(len(p.shis) for p in cplx) / len(cplx)

Or, get the adjacency graph of top-dimensional cells in the complex with:

print(cplx.dual_graph())

You can view the full documentation for this library at https://bl-ake.github.io/relucent/.

Obtaining a Gurobi License

pip install relucent installs the Gurobi Python library, which works for most applications without a license. However, without one, Gurobi will only work with a limited feature set. This includes a limit on the number of decision variables in the models it can solve, which limits the size of the networks this code is able to analyze. There are multiple ways to install the software, but we recommend the following steps to those eligible for an academic license: 0. Create a fresh Python environment using a distribution of Anaconda.

  1. Install the Gurobi Python library using conda install -c gurobi gurobi, before installing relucent, so that pip uses this copy.
  2. Obtain a Gurobi license (Note: a WLS license will limit the number of concurrent sessions across multiple devices, which can result in slowdowns when using this library on different machines simultaneously.)
  3. In your Conda environment, run grbgetkey followed by your license key
  4. Install relucent and complete the remaining steps in Getting Started

Citing this Package

If you run into any problems or have any feature requests, please create an issue on the project's Github. If you want to credit its use in your research, please cite our paper.

@inproceedings{
  gaines2026characterizing,
  title={Characterizing the Discrete Geometry of Re{LU} Networks},
  author={Blake B. Gaines and Jinbo Bi},
  booktitle={The Fourteenth International Conference on Learning Representations},
  year={2026},
  url={https://openreview.net/forum?id=TgLW2DiRDG}
}

Please check out the amazing software created by others working in this area. Depending on your goal, some of these could be even better!

Bibliography

This package was made possible by the following work:

Metadata

Release files for relucent 1.0.2

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

Source distribution (sdist)

Source distribution for relucent 1.0.2
File Size Uploaded Provenance Actions
relucent-1.0.2.tar.gz 219.1 kB With provenance Details for relucent-1.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 463.1 kB

Release files / relucent-1.0.2.tar.gz

Download URL relucent-1.0.2.tar.gz
Size 219.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2c3f8e5a020a185a0afd6d152c6b65b653d2d3f0298907d3902dedccce2d2792
BLAKE2b-256 checksum
How to use checksums
efc4b886157111bdf12243fb37e6bdcf05f27c8cdffa73b9cb88172a7cc8d16a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 27, 2026.

Transparency log

Release files / relucent-1.0.2-py3-none-any.whl

Download URL relucent-1.0.2-py3-none-any.whl
Size 244.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2f96690caa1ec1d5e11fda17807c2c35218949e95378a273016cd53f420164b
BLAKE2b-256 checksum
How to use checksums
44902b247fd956d82eb148eae9084ac3f3621c63324dd030a5d757aca46e2b44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 27, 2026.

Transparency log

Security for relucent 1.0.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for relucent-1.0.2.tar.gz

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 Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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