Skip to content

Griffith

Build fast, low-power AI chips in Python

Train logic-gate networks and deploy them straight to FPGAs

Named after Griffith Observatory, whose mission is to bring astronomy to everyone — we want differentiable logic to be just as accessible.

Make logic gates learnable

Train with a continuous relaxation, infer as a pure Boolean circuit. An IR (intermediate representation) bridges the two.

◧

Learnable logic gates

N-input LUTs (N=2/4/6) relaxed into differentiable form — from difflogic’s 16 gates all the way to FPGA LUT6, in one layer type.

⌁

Straight to FPGA

Extract the trained model into an IR (JSON), then emit Verilog / VHDL. Inference runs as bitwise operations — fast and low power, no GPU.

⇄

Hybrid networks

Keep attention in PyTorch and swap only the MLP for LUTs. Drop a logic layer into any existing nn.Module.

▤

Visual editor

Inspect the IR graph, LUT heatmaps and live training (time machine / gradient streaming) from the browser.

≡

HDL equivalence checking

Tests assert that PyTorch hard eval ⇔ IR simulate ⇔ HDL simulation all agree.

∇

Pluggable learning rules

BP / AP (derivative-free) / DFA / EGGROLL (evolution strategies), annotated per layer. Mix different rules in one network.

ターミナルウィンドウ
pip install griffith-logic # distribution: griffith-logic / import: griffith_logic

To work on Griffith itself (or to run the examples/), use uv instead.

ターミナルウィンドウ
uv sync --extra dev --extra cpu # setup (use --extra cu128 on GPU machines)
uv run python examples/01_xor.py # learn XOR → accuracy 1.00 on the discretized circuit
mnist_lut.py
import torch
import griffith_logic as gl # gl is the idiomatic alias
# A 3-layer N=4 LUT network (MNIST-sized)
model = torch.nn.Sequential(
torch.nn.Flatten(),
gl.LutLayer(in_dim=784, out_dim=16000, n_inputs=4),
gl.LutLayer(in_dim=16000, out_dim=16000, n_inputs=4),
gl.LutLayer(in_dim=16000, out_dim=16000, n_inputs=4),
gl.GroupSum(k=10, tau=30.0),
)
# Training: gradients flow through a softmax relaxation
y = model(torch.rand(32, 784)) # (32, 10) class logits
# Inference: argmax discretization collapses it into a Boolean circuit
model.eval()
y_hard = model(torch.rand(32, 784)) # no GPU, bitwise ops only