CoolFace
Modelpublic

CanadaDiver/KiCad-Gemma4-E2B-v2

sourceHugging Facecc-by-nc-nd-4.0updated 6mo agoView on Hugging Face
1likes32downloads
Model Card

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

PropertyValue
Base modelgoogle/gemma-4-E2B-it
ArchitectureGemma 4 E2B — 35 layers, 1.536B effective parameters
AttentionSliding window (256 dim) + global (512 dim), every 5th layer global
FFNDouble-wide MLP on global layers (12,288 vs 6,144 for SWA layers)
Fine-tuning methodQLoRA via Unsloth
LoRA rank / alphar=64, α=128, rank-stabilized (rsLoRA)
LoRA target modulesqproj, kproj, vproj, oproj, gateproj, upproj, downproj, embedtokens, lm_head
Context length131,072 tokens
GGUF quantizationQ8\_0
Training hardwareNVIDIA 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:

TypeCountDescription
tool_call_script234KiCad Python API: generate/modify schematics programmatically
tool_call_repair32Debugging and fixing broken KiCad scripts
sch_generation21Full schematic generation from circuit description
sch_section40Section-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 `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

bash
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):

json
{
  "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

bash
claude mcp add kicad-sch -- python -m mcp_kicad_sch_api

Available MCP Tools

ToolDescription
create_schematicCreate a new .kicad_sch file
load_schematicLoad an existing schematic from disk
save_schematicSave the current schematic to disk
add_componentPlace a component (lib_id, reference, value, position, footprint)
search_componentsSearch KiCad symbol libraries by keyword
add_wireDraw a wire between two coordinates
add_labelAdd a net label at a position
add_hierarchical_labelAdd a hierarchical interface label
add_junctionAdd a junction dot at a wire crossing
list_componentsList all components in the open schematic
get_schematic_infoGet component count, wire count, and file info
get_component_pin_positionGet the absolute XY position of a specific pin
add_label_to_pinAttach a net label directly to a component pin
connect_pins_with_labelsConnect two pins via a shared net name
list_component_pinsList all pins for a component with their positions
remove_componentRemove a component by reference
remove_wireRemove 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. 1.Download KiCad-Gemma4-E2B-v2-Q8_0.gguf
  2. 2.Place it at: .lmstudio/models/CanadaDiver/KiCad-Gemma4-E2B-v2/KiCad-Gemma4-E2B-v2-Q8_0.gguf
  3. 3.Load and chat

llama.cpp / llama-server

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

HuggingFace Transformers

python
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

ContributorContributionLicense
Google DeepMindGemma 4 E2B base modelApache 2.0
UnslothQLoRA fine-tuning framework, 4-bit baseApache 2.0
Seeed StudioOPL KiCad Library — real schematic training dataCC BY-SA 4.0
KiCad EDAKiCad documentation and file format referenceGPL
HuggingFaceTransformers, PEFT, TRL training stackApache 2.0

Synthetic training pairs were generated using Gemma 4 E4B-it running locally via LM Studio.


Citation

bibtex
@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}
}