Installation
griffith-logic manages its dependencies with uv.
Don’t invoke .venv directly and don’t use pip install / uv pip install — always go through
uv run and uv sync.
Requirements
Section titled “Requirements”| Item | Requirement |
|---|---|
| Python | 3.11 or newer |
| uv | Latest release recommended |
| OS | macOS (Apple Silicon) / Linux / Windows |
If you don’t have uv yet, install it one of these ways.
curl -LsSf https://astral.sh/uv/install.sh | shbrew install uvpowershell -c "irm https://astral.sh/uv/install.ps1 | iex"-
Clone the repository.
ターミナルウィンドウ git clone https://github.com/tsukushi-gate/Griffith.gitcd Griffith -
Sync with the extras that match your machine.
ターミナルウィンドウ uv sync --extra dev --extra cpuターミナルウィンドウ uv sync --extra dev --extra cu128 -
Verify the install (see “Verifying the install” below).
Available extras
Section titled “Available extras”The extras are declared in [project.optional-dependencies] of pyproject.toml. The first four
are the ones you’ll reach for most.
| extra | What it pulls in | When to use it |
|---|---|---|
cpu | torch, torchvision, timm (CPU / MPS builds) | Everyday development and CI. Always this on Mac |
cu128 | torch, torchvision, timm (CUDA 12.8 builds) | GPU machines, training on Modal / RunPod |
dev | pytest, hypothesis, pytest-cov, httpx, mypy | Tests and type checking (required for development) |
editor | fastapi, uvicorn, python-multipart | Backend of the visual editor |
visualizer | websockets | Per-gate WebGL viewer (tools/visualizer/) |
cloud | modal, runpod, wandb-workspaces | Cloud GPU runs and report generation |
figures | matplotlib, pillow | Plotting experiment results |
teachers / text | onnxruntime, huggingface-hub / transformers, datasets | Converting and distilling pretrained models |
sat | python-sat | SAT-based capacity checks (representability proofs) |
wmt / sentiment | datasets, sacrebleu / fugashi and friends | Translation and Japanese sentiment datasets |
Extras can be combined freely (except cpu together with cu128).
uv sync --extra dev --extra cpu --extra editor # dev environment including the editorHow torch resolves per platform
Section titled “How torch resolves per platform”sys_platform markers under [tool.uv.sources] make the same --extra cpu / --extra cu128
resolve from different indexes depending on the platform. You never have to think about it.
| Environment | Extra to pick | Resolved from |
|---|---|---|
| Mac | cpu | PyPI (Apple Silicon build with MPS support) |
| Linux (CPU) | cpu | dedicated pytorch-cpu index (small, used in CI) |
| Linux (CUDA) | cu128 | dedicated pytorch-cu128 index (CUDA 12.8 build) |
Using pip instead
Section titled “Using pip instead”You can also consume the package as a plain library without uv, but then you must install torch
yourself. As explained above, torch and torchvision resolve from different places per
platform, so they are not part of the package’s core dependencies.
# 1. Install torch for your platform first (https://pytorch.org/get-started/locally/)pip install torch torchvision
# 2. Clone the repository and install it in editable modepip install -e .Environment variables
Section titled “Environment variables”Copy .env.example to .env and fill in what you need. At the moment only wandb-related
variables are used.
cp .env.example .envVerifying the install
Section titled “Verifying the install”uv run python -c "import griffith_logic as gl, torch; print(gl.__name__, torch.__version__)"uv run python examples/01_xor.py # trains XOR → accuracy 1.00 under hard evalmake test # fast test suite (under 2 minutes, always green)If examples/01_xor.py prints XOR: soft acc=1.00, hard acc=1.00, you’re done.
The XOR appendix tutorial walks through what just happened, one cell at a time.
To see it on real data, go to 1. Train on MNIST.
HDL verification tools (optional)
Section titled “HDL verification tools (optional)”You only need an external simulator if you want to check Verilog / VHDL equivalence. HDL generation itself works without them — the comparison step is simply skipped.
brew install icarus-verilog # Verilog comparison (iverilog)We do not recommend installing the VHDL side (ghdl) locally on macOS. The Homebrew Cask build
of ghdl has been measured to be broken and fails to build, so the supported way to run VHDL
equivalence checks is inside CI or a cloud (Modal) container. On machines without ghdl the tests
marked hdl_vhdl are simply skipped automatically; nothing else is affected.
See HDL export for details.
Datasets and their licenses
Section titled “Datasets and their licenses”The tutorials and the scripts under examples/ download the datasets they need at run time
(by default into directories such as data-mnist/ at the repository root, overridable with each
loader’s root= argument). This repository neither bundles nor redistributes the data itself.
| Dataset | Where it is used | Distributed by |
|---|---|---|
| MNIST / Fashion-MNIST | Nearly every tutorial except XOR | via torchvision |
| CIFAR-10 / CIFAR-100 | CNN, ResNet, and Mixer families | via torchvision |
| Tiny Shakespeare | Logic GPT and the RNN family (character LM) | the original author’s public text |
| SST-2 | TextCNN and sentiment distillation | Hugging Face Datasets |
| WRIME | Japanese sentiment analysis | Hugging Face Datasets |
| Oxford-IIIT Pet / WIDER FACE, etc. | Segmentation and object detection | their respective distributors |
Use of each dataset is governed by the license and terms of its distributor. Some are restricted to research use, and some forbid redistribution. Downloading them means accepting those terms, so check the dataset’s own primary source before any commercial use. The library’s own license (griffith-logic) does not extend to the datasets.