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

Property Value
Base model google/gemma-4-E2B-it
Architecture Gemma 4 E2B — 35 layers, 1.536B effective parameters
Attention Sliding window (256 dim) + global (512 dim), every 5th layer global
FFN Double-wide MLP on global layers (12,288 vs 6,144 for SWA layers)
Fine-tuning method QLoRA via Unsloth
LoRA rank / alpha r=64, α=128, rank-stabilized (rsLoRA)
LoRA target modules q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj, embed_tokens, lm_head
Context length 131,072 tokens
GGUF quantization Q8_0
Training hardware NVIDIA GeForce RTX 5080

Intended Use

Designed for electronics engineers and hobbyists working with KiCad EDA:

  • Generating valid .kicad_sch schematic 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-it for 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:

Type Count Description
tool_call_script 234 KiCad Python API: generate/modify schematics programmatically
tool_call_repair 32 Debugging and fixing broken KiCad scripts
sch_generation 21 Full schematic generation from circuit description
sch_section 40 Section-level schematic understanding

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-it

Training 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 convert_hf_to_gguf.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-api

Requires 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_api

Available MCP Tools

Tool Description
create_schematic Create a new .kicad_sch file
load_schematic Load an existing schematic from disk
save_schematic Save the current schematic to disk
add_component Place a component (lib_id, reference, value, position, footprint)
search_components Search KiCad symbol libraries by keyword
add_wire Draw a wire between two coordinates
add_label Add a net label at a position
add_hierarchical_label Add a hierarchical interface label
add_junction Add a junction dot at a wire crossing
list_components List all components in the open schematic
get_schematic_info Get component count, wire count, and file info
get_component_pin_position Get the absolute XY position of a specific pin
add_label_to_pin Attach a net label directly to a component pin
connect_pins_with_labels Connect two pins via a shared net name
list_component_pins List all pins for a component with their positions
remove_component Remove a component by reference
remove_wire Remove a wire by UUID

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

  1. Download KiCad-Gemma4-E2B-v2-Q8_0.gguf
  2. Place it at: .lmstudio/models/CanadaDiver/KiCad-Gemma4-E2B-v2/KiCad-Gemma4-E2B-v2-Q8_0.gguf
  3. Load and chat

llama.cpp / llama-server

llama-server -m KiCad-Gemma4-E2B-v2-Q8_0.gguf --port 8080 -c 8192

HuggingFace 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

Contributor Contribution License
Google DeepMind Gemma 4 E2B base model Apache 2.0
Unsloth QLoRA fine-tuning framework, 4-bit base Apache 2.0
Seeed Studio OPL KiCad Library — real schematic training data CC BY-SA 4.0
KiCad EDA KiCad documentation and file format reference GPL
HuggingFace Transformers, PEFT, TRL training stack Apache 2.0

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}
}
Downloads last month
58
GGUF
Model size
5B params
Architecture
gemma4
Hardware compatibility
Log In to add your hardware

8-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for CanadaDiver/KiCad-Gemma4-E2B-v2

Quantized
(130)
this model