Skip to main content

Explore polyhedral complexes associated with the activation states of ReLU neural networks.

Project description

Usable Latest Release

Relucent

Explore polyhedral complexes associated with the activation states of ReLU neural networks

Environment Setup

  1. Install Python 3.13
  2. Install PyTorch >= 2.3.0
  3. Run pip install relucent

Getting Started

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

from relucent import Complex, get_mlp_model

network = get_mlp_model(widths=[2, 10, 5, 1])
cplx = Complex(network)
cplx.bfs()
fig = cplx.plot(bound=10000)
fig.show()

The "NN" object returned by get_mlp_model inherits from torch.nn.Module, so you can train and manipulate it just like you're used to :)

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

import numpy as np

input_point = np.random.random(network.input_shape)
p = cplx.point2poly(input_point)
print(p.halfspaces[p.shis, :])

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

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

Or, get the adjacency graph of top-dimensional cells in the complex as a NetworkX Graph with:

print(cplx.get_dual_graph())

View the documentation for this library at https://bl-ake.github.io/relucent/

Source Code Structure

  • model.py: PyTorch Module that acts as an interface between the model and the rest of the code
  • poly.py: Class for calculations involving individual polyhedrons (e.g. computing boundaries, neighbors, volume)
  • complex.py: Class for calculations involving the polyhedral cplx (e.g. polyhedron search, connectivity graph calculation)
  • convert_model.py: Utilities for converting various PyTorch.nn layers to Linear layers
  • bvs.py: Data structures for storing large numbers of sign vectors

Obtaining a Gurobi License

Without a license, 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:

  1. Install the Gurobi Python library, for example using pip install gurobipy
  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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

relucent-0.2.1.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relucent-0.2.1-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file relucent-0.2.1.tar.gz.

File metadata

  • Download URL: relucent-0.2.1.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for relucent-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9bf532dfac6a61df4d70de9d95d16913d181e9fcf04b07078f2f862ed8351808
MD5 149f274b5f9a53851919b67415d6f88b
BLAKE2b-256 83e97f985656ed697d09fe59c47b9a345e588705637671770033f7d3801b7c53

See more details on using hashes here.

Provenance

The following attestation bundles were made for relucent-0.2.1.tar.gz:

Publisher: publish.yml on bl-ake/relucent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file relucent-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: relucent-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for relucent-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e82b1772348113a4f9e1222ad1ba121860089c50a5ed5d8b506fc0cb7db459f0
MD5 fa3e36b6e3b7ff0a33c78fe34cd80a44
BLAKE2b-256 4806e80aef31353145d40f55a1bb29fdaeb1bce32463390ff164195703d6c0dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for relucent-0.2.1-py3-none-any.whl:

Publisher: publish.yml on bl-ake/relucent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page