A project to build a neural network out of logic gates.
This repository contains a pure C implementation of a Multi-Layer Perceptron (MLP) trained using differentiable logic gates, featuring export via the AIGER format.
This work is directly inspired by the groundbreaking research of Felix Petersen et al. on hardware-efficient neural networks.
This project implements a sparse MLP in which each neuron has fewer than 16 inputs and uses a tempered hyperbolic tangent as an activation function.
Each neuron is converted into a logic circuit using the Quine–McCluskey algorithm on the sign response table for all combinations of 1 and -1 as inputs, producing an AND network.
Finally, all generated circuits are assembled together to build a large AIGER file.
The goal of this project is to train neural networks that can be exported and executed as digital logic circuits.
mlp.c/mlp.h: Contains the implementation of the MLP (this is the core file).qm16.c/qm16.h: Contains an implementation of the Quine–McCluskey algorithm for tables with fewer than 16 inputs.aiger.c/aiger.h: A dependency to help write binary AIGER files.main.c: Contains an example of usage on the MNIST dataset.
- Implement Adam optimizer (currently changing
lrmanually during training). - Test it on other datasets.
- Test it on a larger scale.
- Try to make it output a probability distribution.
On MNIST, the project achieved after a bit of training:
- 87% accuracy
- 54 layers
- Around 84k AND gates
Note: the tested file is mnist_87.aig
make -DAIGSIM_PATH="aigsim"aigsim can be found here: https://github.com/arminbiere/aiger
Training is performed using the primitives defined in problem.h.
An example configuration using MNIST is already provided.
After training, the network can be exported to an AIGER file. (Press the G key in the GUI)
For better results, balance and optimize the generated circuit using ABC (https://github.com/berkeley-abc/abc).
Example:
abc
read out.aig
balance
rewrite
balance
write optimized.aigThis project implements and expands upon the concepts introduced in the following paper:
Felix Petersen, Christian Borgelt, Hilde Kuehne, and Oliver Deussen. "Deep Differentiable Logic Gate Networks." Published at NeurIPS 2022. arXiv:2210.08277
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-nc-sa/4.0/
The pipeline is simple:
- Train a sparse MLP.
- Convert each neuron into boolean logic using the Quine–McCluskey algorithm.
- Generate an AND network.
- Merge all neuron circuits together.
- Export the final network as an AIGER file.
- Optimize the circuit using ABC.
- Use the network to do fun things.
ELLIS UnConference