pip install -e .For development:
pip install -e .[dev]Using uv:
uv sync
uv sync --all-extrasimport torch
from fermigates.gates import FermiGate
from fermigates.models import MLP
model = MLP(
input_dim=32,
hidden_dims=[64, 32],
output_dim=4,
gate=lambda: FermiGate(
mode="weight",
init_mu=-0.05,
init_temperature=1.0,
),
)
x = torch.randn(16, 32)
logits = model(x)
kept, total, fraction_kept = model.compute_sparsity(threshold=0.5)
print(logits.shape) # torch.Size([16, 4])
print(kept, total, fraction_kept)Run the provided examples:
python examples/example_MLP_mnist.py
python examples/example_cnn_fashion_mnist_direct.py
python examples/example_transformer_cifar10.py- Weight gating applies probabilities directly to layer weights; weight-gate sparsity is the primary structural signal.
- Activation gating applies probabilities to layer inputs or outputs; activation sparsity is the primary runtime signal.
- Comparable sparsity in experiments should follow the dominant gate location for the selected mode.
- Gate behavior depends strongly on initialization, especially
init_muand a strictly positiveinit_temperature.
fermigates.gates.FermiGatefermigates.models.MLP,fermigates.models.CNN,fermigates.models.Transformerfermigates.experiments.Experimentfermigates.lossesfor Fermi-informed training termsfermigates.metricsfor occupancy and free-energy trackingfermigates.exportfor hard-masked model export and pruning reports
For full API details, see docs/api.md.
FermiGates/
├── fermigates/ # Library source code
│ ├── base/
│ ├── calibration/
│ ├── datasets/
│ ├── experiments/
│ ├── export/
│ ├── gates/
│ ├── layers/
│ ├── losses/
│ ├── masks/
│ ├── metrics/
│ ├── models/
│ ├── training/
│ └── tests/ # Test suite
├── examples/ # Example scripts and notebooks
├── docs/ # Project documentation
├── data/ # Local dataset artifacts
├── logo/ # Branding assets
├── .github/workflows/ # CI configuration
├── pyproject.toml # Build system and dependencies
├── mkdocs.yml # Documentation site config
└── README.md
- Automated tests with
pytest - Static analysis with
ruff - GitHub Actions CI across Python 3.10, 3.11, and 3.12
Run locally:
ruff check .
pytestCopyright (c) 2026 Raunak Dev. All rights reserved.