Models API¶
Ready-to-train reference architectures built on the bitlogic primitives.
These are plain nn.Sequential subclasses you can drop into your own
training loop.
FeedForward¶
Canonical stack: DistributiveThermometer → Flatten → N ×
LogicDense → GroupSum. Every LogicDense layer has the same
width, parametrization, LUT rank, and connection kind.
import torch
from bitlogic import FeedForward
fit_samples = torch.randn(128, 1, 28, 28)
model = FeedForward(
fit_samples=fit_samples,
num_classes=10,
layer_width=64_000,
num_layers=2,
num_bits=8,
lut_rank=4,
parametrization="light",
connections="learnable",
forward_sampling="hard", # extra kwargs forwarded to LogicDense
)
models ¶
Ready-to-train reference architectures built on bitlogic primitives.
FeedForward ¶
FeedForward(*, fit_samples: Tensor, num_classes: int, layer_width: int = 64000, num_layers: int = 2, num_bits: int = 8, lut_rank: int = 4, num_candidates: int = 8, parametrization: str = 'light', connections: str = 'learnable', tau: float = 150.0, encoder: str = 'distributive_thermometer', head: str = 'groupsum', head_wbits: int = 8, **layer_kwargs: Any)
Bases: Sequential
Encoder → Flatten → N×LogicDense → Head.
The canonical reference architecture for image classification. Every
LogicDense layer has the same width, parametrization, LUT rank, and
connection kind. Encoder and head are selected by string so the same
builder drives the encoder and head sweeps in §4 of the paper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit_samples
|
Tensor
|
|
required |
num_classes
|
int
|
Number of output classes (last dim of the head). |
required |
layer_width
|
int
|
Neuron count per |
64000
|
num_layers
|
int
|
Number of |
2
|
num_bits
|
int
|
Thermometer bits per input feature. |
8
|
lut_rank
|
int
|
Inputs per LUT. |
4
|
num_candidates
|
int
|
Candidate pool size for |
8
|
parametrization
|
str
|
Parametrization name; see
:mod: |
'light'
|
connections
|
str
|
|
'learnable'
|
tau
|
float
|
Temperature applied by the head. |
150.0
|
encoder
|
str
|
Input-encoder name. One of |
'distributive_thermometer'
|
head
|
str
|
Output-head name. One of |
'groupsum'
|
head_wbits
|
int
|
Weight bit-width used by |
8
|
**layer_kwargs
|
Any
|
Extra kwargs forwarded to every |
{}
|
Example
fit = torch.randn(128, 1, 28, 28) model = FeedForward(fit_samples=fit, num_classes=10)