Ssbullock/pcb-layout-llm
Machine LearningA fine-tuned 32B model that plans PCB grouping and routing strategy for KiCad boards before placement and routing.
What it is
This project releases a LoRA adapter fine-tuned on top of Qwen/Qwen2.5-Coder-32B-Instruct for architectural PCB layout planning. It was trained in two stages — QLoRA SFT, then online GRPO — on 245 curated open-source KiCad designs (L1-L14).
Instead of asking the model to emit raw X/Y coordinates, the pipeline feeds it a compact board summary (board_context.md) containing the netlist and footprint geometry. The model returns two JSON artifacts:
groups.json: functional partitioning with one IC per group (core,power,interface), anchor selection, andnearadjacency constraints.routing_strategy.json: ground/split-plane pours, EMI keep-away rules, power width tiers, bus routing, channel reservations, and via/trace rules.
Those plans then drive deterministic placement and Rust A* autorouting through KiCadRoutingTools. The repository also contains the data curation, training, evaluation, and benchmark code.
Quick start
Prerequisites: KiCad 9 or 10 with kicad-cli on PATH, a built checkout of KiCadRoutingTools (update KRT_ROOT if it is not at the default path), and Python 3.10+ with numpy, pillow, and modal for cloud GPU work (L49-L53).
The adapter is published as Simonssb/qwen2.5-coder-32b-pcb-grpo. Load it with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
base_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
adapter_id = "Simonssb/qwen2.5-coder-32b-pcb-grpo"
tokenizer = AutoTokenizer.from_pretrained(adapter_id, trust_remote_code=True)
base = AutoModelForCausalLM.from_pretrained(base_id, torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(base, adapter_id)
Once you have generated pred_groups.json and pred_routing_strategy.json, place and route a board with the physics-engine wrapper:
python3 gym_rollout.py \
--board HydroPCB \
--set sethydro \
--mode rollout \
--groups path/to/pred_groups.json \
--routing-strategy path/to/pred_routing_strategy.json \
--production-finish
To reproduce the benchmark, prepare and evaluate in sequence, then regenerate the chart:
python3 benchmark_frontier_vs_finetuned.py --prepare
python3 benchmark_frontier_vs_finetuned.py --eval
python3 make_benchmark_chart.py
Retraining runs on Modal A100-80GB:
modal run modal_train_sft.py \
--base-model Qwen/Qwen2.5-Coder-32B-Instruct \
--train-file dataset/sft_curated_train.jsonl \
--val-file dataset/sft_curated_val.jsonl
Constraints
- The model plans architecture only; it does not produce coordinates. Actual placement and routing depend on KiCadRoutingTools and a working KiCad/
kicad-cliinstallation. - Serving the 32B base plus adapter requires substantial GPU memory (bfloat16,
device_map="auto"); training scripts assume Modal A100-80GB. - The board context generator covers mechanical/RF lock detection and a 19-point physical quality evaluation, so inputs outside the supported KiCad flow may not be handled.
- No license is declared in the repository, so redistribution and reuse terms are unclear.
Benchmark claims
The README reports a blind evaluation over 23 unseen boards using the same placer, router, and kicad-cli pcb drc gate. The fine-tuned model is claimed to produce valid schemas on 23/23 boards, fully route 19/23, and achieve a 0-DRC rate of 11/23, compared with zero-shot runs of several frontier models and the base model's 0/23 valid schema rate (L15-L33). Per-board results are in runs/frontier_vs_finetuned_leaderboard.md, with the comparison chart at frontier_vs_finetuned_chart.png. These are author-reported figures tied to one specific routing toolchain.
HotRepo's take
The repository sits at the intersection of model training and EDA tooling: it ships weights, a curated dataset, training scripts, and an evaluation harness rather than a single demo. HotRepo's only recorded activity is a new-project snapshot on 2026-11-22, when the repo stood at 104 stars and gained 4 stars in roughly 1.5 hours; there is no GitHub daily rank or extended history to judge sustained traction. The benchmark's value rests on the shared KiCadRoutingTools placer/router and DRC gate, which makes the numbers comparable within that setup but not directly transferable to other routing engines.
Written by AI from the project's public information and HotRepo's records, updated . The project's own docs are the source of truth.