CoolFace
Modelpublic

AbijahKaj/qwen3-4b-skidl

sourceHugging Faceapache-2.0updated 8d agoView on Hugging Face
1likes234downloads
Model Card

qwen3-4b-skidl

A fine-tune of Qwen/Qwen3-4B for generating executable SKiDL Python netlists from natural-language circuit descriptions. Given a description like "ESP32 board with BME280 on I2C and USB-C", the model outputs valid Python using Part(), Net(), and generate_netlist() — producing a .net file KiCad can open directly.

Blog post: Teaching a Small LLM to Design Electronic Circuits: Fine-Tuning Qwen3-4B on 100K KiCad Netlists

This repo has two branches:

BranchContentsSizeUse
`main` (this)Merged weights — LoRA baked into base7.5 GBLoad directly, no base model needed
`lora`Adapter only504 MBLightweight; load on top of Qwen3-4B

Quick start

Merged (main branch — recommended)

python
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(
    "AbijahKaj/qwen3-4b-skidl",
    dtype="auto",
    device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained("AbijahKaj/qwen3-4b-skidl")

LoRA adapter (lora branch)

python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-4B", dtype="auto", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("AbijahKaj/qwen3-4b-skidl", revision="lora")
model = PeftModel.from_pretrained(base, "AbijahKaj/qwen3-4b-skidl", revision="lora")

Generating a circuit

python
SYSTEM = (
    "You are an expert electronics engineer and KiCad schematic designer. "
    "When given a description of an electronic circuit, generate executable "
    "SKiDL Python code that defines the circuit using the SKiDL library."
)

messages = [
    {"role": "system", "content": SYSTEM},
    {"role": "user", "content": "Design a CAN bus interface using MCP2515 controller and TJA1050 transceiver on SPI, with 120 ohm termination resistor."},
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
print(tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))

Training

Base modelQwen/Qwen3-4B
MethodSFT + LoRA
DatasetAbijahKaj/kicad-netlist-sft-dataset — 100,179 SKiDL Python circuit examples
LoRA rank / alphar=64, α=32, dropout=0.05
Target modulesq/k/v/o\proj, gate/up/down\proj
Epochs2
Peak LR2e-4 (cosine decay)
Effective batch8
Max length8192 tokens
Trainable params~132M (5.65% of 4B)

Loss curve

PhaseTrain lossToken accuracy
Start0.8675%
Epoch 1 end0.1795%
Epoch 2 end0.1595–96%
Eval loss (final)0.158195.3%

SKiDL validation (final checkpoint)

Functional scoring across 5 held-out circuits: Python syntax + SKiDL import + net count + part count + connectivity + GND checks.

CircuitScore
LED blink — ATtiny850.85
USB power meter — ATmega328P + INA2190.85
CAN bus — MCP2515 + TJA10500.95
Average0.883

Why SKiDL?

KiCad's native s-expression netlist is deeply nested and pathological for LLMs. PCBSchemaGen (arXiv:2602.00510) shows SKiDL Python achieves 87% Pass@1 with GPT-4o on circuit generation — because Python-based HDLs align with LLM pretraining data and are 3× more compact than s-expressions.

Dataset

AbijahKaj/kicad-netlist-sft-dataset — 100,179 ChatML examples:

SourceCount
Si7li/ltspice-spice-circuits (LTspice → SKiDL)~54,000
bshada/open-schematics (GitHub .kicad_sch files)~45,000
Ashed00/SPICE-Circuits~800
Synthetic + tool-augmented~308

References