Tutorials
Every page here was produced by actually running examples/*.py (all 27 of them, each running to completion on CPU alone). The figures, numbers and generated text are exactly those run results.
Each page ends with a “What to read next” section, so you can wander across the groups.
To run them locally, the unexecuted notebooks in notebooks/ have the same content.
Intro Course
Section titled “Intro Course”Three pages for readers who have never touched a neural network. Read them in order: PyTorch basics -> a small MLP -> replacing the same model with a DLGN.
Intro 1. Neural Networks and PyTorch BasicsWalk once through tensors, autograd, nn.Module and the training loop by classifying toy data that no straight line can separate (no DLGN here).
Intro 2. Build an MLP in PyTorchSolve MNIST 20x20 with an nn.Linear + ReLU MLP, then lay out the first-layer weights as 20x20 images to actually see the real-valued weights.
Intro 3. Replace the MLP with a DLGNKeep the same data and the same training loop, swap nn.Linear for LutLayer and the softmax head for GroupSum, and compare training curves, weights vs truth tables, and soft vs hard.Basics
Section titled “Basics”Start here. Seven pages plus an appendix that run along the backbone of this library: training -> discrete circuit -> HDL -> C.
1. Train on MNISTTrain MNIST 20x20 with nothing but 4000 logic gates, and reach hard accuracy 0.86 while staying a discrete circuit.
2. Build a Hybrid NNReplace only the MLP of an existing model with LUTs and keep training attention in real numbers.
3. Export to HDLExtract a trained model into the IR, generate Verilog / VHDL, and verify equivalence.
4. DeployExport a trained MNIST circuit to the IR, a distribution bundle and C99 source, build it with cc, check an integer-exact match with PyTorch hard eval, and measure delivery size and inference time.
5. Export a CNN to HDLUnroll a LutConv2d CNN into the IR, generate Verilog / VHDL, and check it against the golden model.
6. Switching Learning Rules (DFA / AP)Annotate learning rules per layer with with_learning and run DFA and Akiho Propagation through HybridTrainer.
7. End-to-End Walkthrough: From Training to FPGATraining, reading the loss log, IR extraction, Verilog generation, and the hand-off to real hardware, in one continuous flow.
Appendix: XOR InternalsTrain XOR with a minimal 16-gate circuit and watch the collapse from soft to hard (a discrete circuit) with every node drawn.Sequence & Language
Section titled “Sequence & Language”Handling sequences with logic gates. Compare attention, recurrence, causal convolution and reservoirs.
Writing Shakespeare with a Logic Gate GPTTrain a decoder-only Transformer whose attention, FFN and output head are all logic gates on Tiny Shakespeare, and look at 3.13 bpc and the discretization gap.
seq2seq Built from RNNs Alone (RDDLGN)Learn copy/reverse with RDDLGN, where every fully connected layer is replaced by LUTs, and measure how far a fixed 384-bit bottleneck can carry a sequence.
Gating Is a Boolean Operation (LSTM/GRU) — Logifying the RNNConfirm on a delayed copy task, against a gate-free Elman network, that the LSTM forget gate becomes a 2:1 multiplexer and the output gate a bitwise AND.
Causal Convolution with Logic Gates (WaveNet)Using the fact that gated activation is isomorphic to a bitwise AND, ablate how the receptive field works on next-token prediction of periodic patterns.
Choosing Not to Train the Circuit (Reservoir Computing = an RNN That Does Not Learn)Train only the readout on a frozen random 512-bit logic circuit, and see that what a reservoir holds is memory rather than nonlinear computation.
The Ladder of Transformer Logification: How Far Can Attention Become a Circuit?Climb from a floating-point Transformer (L0) one rung at a time — gated projections, XNOR scores, a MUX selector — and demonstrate that attention = a learned MUX.Vision
Section titled “Vision”Handling images with logic gates. From classification to dense prediction, and the craft of residuals, mixing and binarization.
Answering Per Pixel with a Logic Gate U-NetRecover region masks from noisy MNIST, and see how OR pooling, nearest upsampling and concat skips make dense prediction work without breaking the bits.
Residual Connections in a Logic NN Can Be “Exactly” the IdentityBuild a perfect identity map with max|y-x| = 0.0 using OR residuals and pass-through initialization, and compare its price — saturation — on OR vs XOR training curves.
LogicMixer (MLP-Mixer) — Mixing Images Without AttentionCut an image into 16 tokens and run a logic gate version of MLP-Mixer on MNIST, alternating token-mixing and channel-mixing with soft-XOR residuals.
DWN — Solving MNIST with Thermometer Encoding and n-input LUTsAssemble a DWN of ThermometerEncoder and 64-entry LUTs, and confirm the exception in the logic NN world: a zero soft/hard discretization gap.Generative Models
Section titled “Generative Models”Making images without multiplication. Turn diffusion, VAEs and GANs entirely into Boolean circuits.
Turning a Diffusion Model Entirely into a Boolean CircuitRun a diffusion model in which the whole generative process closes over multiplication-free Boolean operations: XOR in the forward process, LUTs in the denoiser, and bit reassembly in the reverse process.
Folding an Image into 96 Bits — a Binary Latent VAEDrop the reparameterization of a Gaussian latent and compress 196-pixel digits into 96 bits with a VAE whose latent is a Bernoulli bit string, then reconstruct them.
Making Images from Random Bits, and Breaking Them (LogicGAN)Generate images by pushing random bit strings through a logic circuit, and put a stable version next to an untuned one to show how adversarial training breaks, measured for real.Applications
Section titled “Applications”Detection, FPGA-oriented LUT networks, text classification — taking the assembled circuits to real tasks.
A Tour of Four Logic Gate Attention VariantsCompare four attention variants that replace the dot product and softmax with XNOR similarity and argmax, on small tasks: associative recall, positional lookup and sorting.
Multiplier-Free Object Detection (CenterNet)Follow a minimal CenterNet built only from LutConv2d and OrPooling2d as it finds digits in synthetic Multi-MNIST and draws bounding boxes.
Training FPGA-Oriented LUT Networks with the BinaryBrain-Compatible APITrain MNIST with RealToBinary / DifferentiableLutBlock / BinaryToReal, and measure the discretization gap where the truth tables have not yet settled on 0/1.
Growing “n-gram Detectors” with a Logic Gate TextCNNSolve a bigram XOR classification that counting words alone cannot crack with a logic gate TextCNN, and visualize each filter growing into a detector for a specific pair of words.
Activity Recognition (UCI-HAR, Phone Accelerometer)Thermometer-encode the raw accelerometer / gyroscope signals of a phone, classify six activities with a logic-gate network, and export the trained circuit to C99 with an integer-exact match against PyTorch.