CanadaDiver/KiCad-Gemma4-E2B-v2
KiCad-Gemma4-E2B-v2
A KiCad EDA specialist — fine-tuned from google/gemma-4-E2B-it to generate .kicad_sch schematics, write KiCad Python scripts, select components, and explain PCB design decisions.
License
Fine-tuned weights: CC BY-NC-ND 4.0
- Non-commercial use only. You may not use this model or its outputs as part of any commercial product, service, or API.
- No derivatives. You may not fine-tune, merge, quantize, or redistribute modified versions of this model.
- Attribution required. Any publication or project using this model must credit
CanadaDiver/KiCad-Gemma4-E2B-v2.
Base model weights: Apache 2.0 (Google Gemma 4). Both licenses apply.
Commercial licensing: Contact the repository owner for a separate commercial license if you intend to build a product with this model.
Model Details
Intended Use
Designed for electronics engineers and hobbyists working with KiCad EDA:
- Generating valid
.kicad_schschematic files from natural language descriptions - Writing KiCad Python scripting API code
- Explaining and debugging KiCad schematics and DRC violations
- Selecting components, writing BOMs
- Creating and modifying footprints and symbols
- Answering KiCad workflow questions
- Agentic schematic generation via the companion MCP server (see below)
Out-of-Scope Use
- General-purpose chat (use the base
gemma-4-E2B-itfor that) - Any commercial product or service without a separate commercial license
- Safety-critical hardware design without qualified human review
Training Data
The model was trained on `kicad_agent_final.jsonl` — 366 instruction/output pairs assembled from the following sources:
Real Schematics — Seeed Studio OPL KiCad Library
~93 samples derived from open-source .kicad_sch and .kicad_sym files published by Seeed Studio.
Boards represented:
- Grove Vision AI Module V2
- Seeed Studio XIAO Series (ESP32S3, nRF52840)
- Wio LR1121 Module v0.9
- Wio SX1262 for XIAO ESP32S3
- Wio SX1262 for XIAO nRF52840 v1.3
- XIAO Family (generic)
License: CC BY-SA 4.0 Source: github.com/Seeed-Studio/OPL_Kicad_Library
These schematics were converted into instruction→output training pairs (schematic generation, section understanding, component reference lookup) using Gemma 4 E4B-it running locally.
Synthetically Generated Pairs
~273 samples generated using Gemma 4 E4B-it (via LM Studio) as a teacher model, covering:
Circuit topics covered: passive filters, power supplies (LDO, buck, boost, LiPo charging), microcontroller minimal systems (ESP32, STM32, ATmega, RP2040, nRF52840), digital interfaces (SPI, I2C, UART, USB, CAN, RS-485), analog circuits (op-amps, comparators, ADC/DAC), sensor interfaces, and protection circuits.
Dataset Composition
Total training samples : 366
Real schematic pairs : 93 (25%) — Seeed OPL CC BY-SA 4.0
Synthetic pairs : 273 (75%) — generated via Gemma 4 E4B-itTraining Procedure
Framework : Unsloth + PEFT 0.18.1 + HuggingFace Transformers
Base model : unsloth/gemma-4-E2B-it-unsloth-bnb-4bit (4-bit NF4 for training)
Method : QLoRA (quantized LoRA)
LoRA config:
r = 64
lora_alpha = 128
use_rslora = True (rank-stabilized LoRA)
lora_dropout = 0
use_dora = False
target_modules = q_proj, k_proj, v_proj, o_proj,
gate_proj, up_proj, down_proj,
embed_tokens, lm_head
Training:
Hardware = NVIDIA GeForce RTX 5080 (16 GB)
Sequence length = 4096 tokens max
Train/eval split = 95/5
Framework = SFTTrainer (TRL)After training, LoRA adapters were merged into the base model weights at bf16 precision and exported to GGUF Q8\0 format via a patched `converthftogguf.py`.
GGUF Compatibility Note
Gemma 4 E2B uses a shared-KV mechanism where layers 15–34 reuse the key/value projections from layers 13 (SWA) and 14 (global). Standard GGUF converters omit these tensors via PyTorch parameter deduplication.
The GGUF file in this repo includes explicit copies of the shared KV tensors for all 35 layers (SWA layers → blk.13 weights, global layers → blk.14 weights), ensuring compatibility with all llama.cpp-based runtimes including LM Studio and Ollama.
Agentic Use — KiCad MCP Server
Pair this model with the companion `mcp-kicad-sch-api` MCP server to give it live read/write access to real .kicad_sch files. The model generates schematic intent; the MCP server executes it against an actual KiCad file on disk.
Install
pip install mcp-kicad-sch-apiRequires Python 3.10+ and KiCad installed (for symbol libraries).
Configure — Claude Desktop
Add to %APPDATA%\Claude\claude_desktop_config.json (Windows) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
"mcpServers": {
"kicad-sch-api": {
"command": "python",
"args": ["-m", "mcp_kicad_sch_api"],
"env": {}
}
}
}A ready-to-use config file is included in this repo as mcp_config_claude_desktop.json.
Configure — Claude Code
claude mcp add kicad-sch -- python -m mcp_kicad_sch_apiAvailable MCP Tools
Example Agentic Workflow
With the MCP server running alongside this model in Claude Desktop or Claude Code:
"Create a 3.3 V LDO regulator schematic using the LP2985. Add input and output bypass caps. Save it as `ldo_3v3.kicad_sch`."
The model will call create_schematic, add_component (×3), add_wire (multiple), add_label, and save_schematic in sequence — producing a valid KiCad 8 schematic file without manual placement.
How to Use
LM Studio
- Download
KiCad-Gemma4-E2B-v2-Q8_0.gguf - Place it at:
.lmstudio/models/CanadaDiver/KiCad-Gemma4-E2B-v2/KiCad-Gemma4-E2B-v2-Q8_0.gguf - Load and chat
llama.cpp / llama-server
llama-server -m KiCad-Gemma4-E2B-v2-Q8_0.gguf --port 8080 -c 8192HuggingFace Transformers
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "CanadaDiver/KiCad-Gemma4-E2B-v2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto"
)
messages = [{"role": "user", "content": "Write a KiCad schematic for a 3.3V LDO using LP2985."}]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
outputs = model.generate(inputs, max_new_tokens=1024, temperature=1.0, top_k=64, top_p=0.95)
print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True))Limitations
- Optimized for KiCad tasks; general reasoning capability is reduced vs. the base model
- Training set is small (366 samples) — complex or unusual circuits may produce incorrect output
- Always run KiCad DRC before sending any generated schematic to fabrication
- Trained primarily on KiCad 8.x conventions; KiCad 9.x/10.x syntax may differ in places
- Not a substitute for professional electrical engineering review
Credits & Acknowledgements
Synthetic training pairs were generated using Gemma 4 E4B-it running locally via LM Studio.
Citation
@misc{kicad-gemma4-e2b-v2,
author = {CanadaDiver},
title = {KiCad-Gemma4-E2B-v2: A KiCad EDA specialist fine-tuned from Gemma 4 E2B},
year = {2026},
publisher = {HuggingFace},
url = {https://huggingface.co/CanadaDiver/KiCad-Gemma4-E2B-v2}
}