Skip to content

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.

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.

Start here. Seven pages plus an appendix that run along the backbone of this library: training -> discrete circuit -> HDL -> C.

Handling sequences with logic gates. Compare attention, recurrence, causal convolution and reservoirs.

Figure generated by Writing Shakespeare with a Logic Gate GPTWriting 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.about 10 min · examples/07_logic_gpt.pyFigure generated by seq2seq Built from RNNs Alone (RDDLGN)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.about 8 min · examples/08_rddlgn_seq2seq.pyFigure generated by Gating Is a Boolean Operation (LSTM/GRU) — Logifying the RNNGating 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.about 5 min · examples/09_logic_lstm.pyFigure generated by Causal Convolution with Logic Gates (WaveNet)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.about 5 min · examples/10_logic_wavenet.pyFigure generated by Choosing Not to Train the Circuit (Reservoir Computing = an RNN That Does Not Learn)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.about 5 min · examples/11_logic_reservoir.pyFigure generated by The Ladder of Transformer Logification: How Far Can Attention Become a Circuit?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.about 8 min · examples/12_logic_ladder_gpt.py

Handling images with logic gates. From classification to dense prediction, and the craft of residuals, mixing and binarization.

Making images without multiplication. Turn diffusion, VAEs and GANs entirely into Boolean circuits.

Detection, FPGA-oriented LUT networks, text classification — taking the assembled circuits to real tasks.