Skip to content

What should I use? (selection guide)

This library offers a lot of options: 20+ architectures × 5 parameterizations × 3 fan-in (N) values × 4 learning rules. You do not need to understand all of them before starting — in practice your task and your deployment constraints settle nearly everything.

This page is the decision table that answers “what should I use?” in a single page.

flowchart LR
T["Task you want to solve"] --> A["1. Architecture<br/>dlgn / conv / seq2seq / …"]
D["Deployment target<br/>FPGA / CPU / validation only"] --> N["2. fan-in N<br/>2 / 4 / 6"]
N --> P["3. Parameterization<br/>softmax / independent / warp / iwp / raw"]
E["Environment constraints<br/>can you use backprop?"] --> L["4. Learning rule<br/>bp / ap / dfa / eggroll"]
A --> M["Model complete"]
P --> M
L --> M
style A fill:#38bdf826,stroke:#38bdf8
style P fill:#eab30826,stroke:#eab308
style L fill:#f9731626,stroke:#f97316
style M fill:#10b98126,stroke:#10b981

The four are orthogonal (see Architecture overview). Changing the architecture does not change how you pick the parameterization, and vice versa, so you can decide them one at a time.


flowchart TD
START["What are you solving?"] --> Q1{"What kind of data?"}
Q1 -->|"Images"| IMG{"What output?"}
Q1 -->|"Sequences / text"| SEQ{"To do what?"}
Q1 -->|"Generation"| GEN{"Which approach?"}
Q1 -->|"You already have a PyTorch model"| HYB["Go hybrid<br/>replace only the MLP with LUTs"]
IMG -->|"Class label"| IMGC{"Scale and goal?"}
IMG -->|"Per-pixel label<br/>(segmentation)"| UNET["Logic U-Net"]
IMG -->|"Object location"| DET["Object detection"]
IMGC -->|"Get it running / baseline"| DLGN["dlgn (fully connected)<br/>Flatten + LutLayer×n + GroupSum"]
IMGC -->|"Accuracy, exploit spatial structure"| CONV["conv-dlgn<br/>LutConv2d + OrPooling2d"]
IMGC -->|"Minimize FPGA area"| DWN["DWN<br/>thermometer encoding + 6-input LUTs"]
IMGC -->|"Stack deep"| RES["Logic ResNet<br/>exact identity residuals"]
SEQ -->|"Next-token prediction / generation"| GPT["Logic GPT<br/>decoder-only"]
SEQ -->|"Sequence-to-sequence"| S2S["RDDLGN seq2seq"]
SEQ -->|"Time series, recurrently"| RNN["Logic LSTM / GRU<br/>WaveNet / reservoir"]
SEQ -->|"Document classification"| TCNN["TextCNN"]
GEN -->|"Diffusion"| DIF["Logic Diffusion"]
GEN -->|"Latent variables"| VAE["Logic VAE (binary latents)"]
GEN -->|"Adversarial"| GAN["Logic GAN"]
style DLGN fill:#10b98126,stroke:#10b981
style CONV fill:#10b98126,stroke:#10b981
style HYB fill:#38bdf826,stroke:#38bdf8
DestinationComponentsPage to read
dlgn (fully connected)LutLayer + GroupSum1. Train on MNIST
conv-dlgnLutConv2d + OrPooling2d5. HDL export for a CNN
DWNThermometerEncoder + DWNLayerDWN (thermometer encoding)
Logic ResNetResidual blocks (exact identity)ResNet (exact identity)
Logic U-NetEncoder/decoder + spatial outputU-Net (dense prediction)
Object detectionDetection headObject detection
Logic GPTLutStack + causal self-attentionLogic-gate GPT
RDDLGNRecurrent encoder-decoderseq2seq (RDDLGN)
Recurrent familyLSTM/GRU, causal conv, reservoirLSTM / GRU · WaveNet · Reservoir
TextCNNCharacter/word convTextCNN
Generative familyDiffusion / VAE / GANDiffusion models · VAE · GAN
Hybridreplace_mlp_with_lut2. Build a hybrid NN
MixerToken mixing in logicMixer

How many inputs a single gate reads. This is a knob decided by the deployment target, not a question of which is better.

flowchart TD
Q["Where will inference run?"] --> F{"Target"}
F -->|"Squeeze area on FPGA / ASIC"| N6["N=6<br/>maps directly onto one LUT6 cell"]
F -->|"Run fast on CPU / GPU"| N2["N=2<br/>bit-parallelism pays off. Gradients are exact"]
F -->|"Undecided / want stable training"| N2b["N=2<br/>the default when in doubt"]
F -->|"Balance area against accuracy"| N4["N=4"]
style N2 fill:#10b98126,stroke:#10b981
style N2b fill:#10b98126,stroke:#10b981
style N6 fill:#38bdf826,stroke:#38bdf8
style N4 fill:#eab30826,stroke:#eab308
GoalFavorable N
FPGA implementation area6
CPU / GPU inference speed2
Training stability2

As N grows, parameters per gate grow as 2N2^N and training memory grows with it. difflogic chose 2 inputs not because it is optimal for FPGAs, but for clean training (16 gates with exact gradients) and CPU/GPU speed (see DLGN taxonomy and lineage).


Which continuous space holds the truth table. This choice directly determines your discretization gap.

flowchart TD
S["fan-in N is decided"] --> Q1{"What is N?"}
Q1 -->|"N=2"| SM["softmax<br/>(16-gate mode)<br/>this is the only choice you need"]
Q1 -->|"N=4 / N=6"| Q2{"What matters most?"}
Q2 -->|"hard accuracy / circuit quality"| IND["independent<br/>+ raise lr to 0.1-0.3"]
Q2 -->|"smallest discretization gap / fast training"| WARP["warp<br/>Walsh-Hadamard coefficients"]
Q2 -->|"parameter count / memory"| IWP["iwp<br/>only N values. Gives up XOR"]
Q2 -->|"stay continuous until HW expansion"| RAW["raw"]
Q2 -.->|"do not choose"| BAD["softmax (N>=4)<br/>structurally lacks expressiveness"]
style SM fill:#10b98126,stroke:#10b981
style IND fill:#10b98126,stroke:#10b981
style WARP fill:#38bdf826,stroke:#38bdf8
style IWP fill:#eab30826,stroke:#eab308
style BAD fill:#ef444426,stroke:#ef4444
MethodHow weights are heldParameters/gateRepresentable hard functionsOrigin
softmax (N=2)softmax over 16 gates16all 16 functionsdifflogic (DLGN)
softmax (N≥4)softmax over 2N2^N entries2N2^Na single minterm or FALSE only—
independentsigmoid per entry2N2^Nall 22N2^{2^N} functionsBinaryBrain
iwpproduct of per-input sigmoidsNNproduct-form functions only (no XOR)LDDLGN
rawholds [0,1][0,1] reals directly2N2^Nall 22N2^{2^N} functionsBinaryBrain
warpWalsh–Hadamard coefficients + Gumbel2N2^Nall 22N2^{2^N} functionsWARP

The essential difference is whether the values compete or are independent.

softmax: [0.01, 0.02, 0.07, 0.90] sum=1 "split 100 points across 4 boxes"
independent: [0.10, 0.80, 0.30, 0.95] independent "flip 4 switches separately"

With softmax, raising one lowers the others, so a single backward pass sends coupled gradients to every parameter. With independent, the gradient reaches only the relevant entry, but in exchange any bit pattern is reachable.

Per gate (multiply by 10,000 for a 10,000-gate model).

Nsoftmaxindependent / raw / warpiwp
216 (16-gate table)42
416164
664646

At N=6 with 10,000 gates that is 640K vs. 60K. iwp is more than 10× lighter and trains faster, but the price is that it cannot represent functions where the combination is the point, such as XOR. LDDLGN’s rationale is the observation that most gates in a trained model converge to AND/OR/NOT, betting on the empirical finding that very few gates actually converge to XOR-like functions.

Established finding: never choose softmax with N≥4

Section titled “Established finding: never choose softmax with N≥4”

With N≥4, softmax is not a 16-gate table but a simplex over 2N2^N entries. Since the entries sum to 1, discretization (probability > 0.5) can set at most one bit — so the only hard tables it can produce are a single minterm or the constant FALSE. Everyday functions such as pass-through, OR, and XOR are structurally unreachable.

Experiments agree: in a convolutional configuration, simply swapping softmax for independent gave +3.2pt accuracy despite running only half as many epochs. On fully connected MNIST, softmax N=4 reaches only hard 94.54% with a 1.12pp gap, losing to warp N=4 under identical conditions (95.50% / 0.14pp). The point of this finding is that missing expressiveness cannot be compensated by more training.

Established finding: raise the learning rate for independent

Section titled “Established finding: raise the learning rate for independent”

independent goes through a sigmoid, and combined with a saturation-prone initialization, gradients decay rapidly through deep serial composition. In measurements the gradient norm dropped to around 10−510^{-5}, and at the default lr=0.02 soft accuracy did not move even after 10 epochs. Training progresses at lr ≥ 0.3.

ターミナルウィンドウ
uv run griffith train configs/recipes/dlgn_mnist_quick.yaml \
model.n_inputs=6 model.k=4000 model.parameterization=independent optim.lr=0.3
ChoiceMeasured gapNotes
warp N=2−0.06pphard beats soft
warp N=40.14pp11-48% of the FLOPs of softmax
softmax N=20.56ppBest accuracy (hard 97.74%)
softmax N=41.12ppNot recommended, for the reason above
DWN0.0Structurally has no gap
selection='hard_st'0forward=argmax / backward=STE (the CAGE approach)

Details and the full comparison are in Choosing a parameterization.


4. Environment constraints → learning rule

Section titled “4. Environment constraints → learning rule”

To learn “which gate this becomes”, you must decide how error is distributed to each gate’s weights. The default is bp, and the sole motivation for anything else is not wanting to implement the backward path in the circuit too.

flowchart TD
Q["Choosing a learning rule"] --> Q1{"Is backprop allowed?"}
Q1 -->|"Yes (normal case)"| BP["bp<br/>default. Runs on the shared runner"]
Q1 -->|"Only cut backprop between layers"| DFA["dfa<br/>direct feedback via fixed random projections"]
Q1 -->|"Demonstrate full independence from backprop"| Q2{"What is the structure?"}
Q1 -->|"Directly optimize an objective with no defined gradient"| ES["eggroll<br/>low-rank perturbation + fitness"]
Q2 -->|"Fully connected only"| AP["ap<br/>Akiho Propagation"]
Q2 -->|"Includes conv / recurrence"| NG["currently collapses<br/>-> use bp or dfa"]
style BP fill:#10b98126,stroke:#10b981
style DFA fill:#38bdf826,stroke:#38bdf8
style ES fill:#eab30826,stroke:#eab308
style NG fill:#ef444426,stroke:#ef4444
Learning ruleNeeds differentiation?ConstraintsWhen to use
bpYes (all paths)None. The only rule the shared runner run_training handlesDefault. When accuracy comes first
dfaLocally only2D/3D outputs, block_upstream=True onlyWhen you want to cut backprop between layers. Within-layer gradients stay exact
apNoRequires parameterization='independent'. Serial fully connected onlyDemonstrating independence from backprop
eggrollNo (forward only)2D parameters only. Evaluation count is the costWhen you want to optimize hard accuracy itself directly

The learning rule is specified per layer, not for the whole model, so with_learning + HybridTrainer lets you mix them — “bp for feature extraction, dfa for the output head only” (see Learning rules (BP/AP/DFA/ES)).


TaskPage
Typical hyperparameter ranges (lr / τ / k / depth / epochs)Run training
How to read the soft and hard curvesReading training curves
Dump the trained result into IR (JSON) and validate itWorking with IR
Generate Verilog / VHDL and check equivalenceHDL export and equivalence checking
Flash it onto a real FPGADeploying to an FPGA
Send large training jobs to the cloudCloud GPU
Rearrange the structure in the browser and experimentVisual editor