Text Generation
Transformers
Safetensors
English
qwen2
arduino
esp32
raspberry-pi
micropython
circuitpython
embedded-systems
code-generation
lora
continued-pretraining
conversational
text-generation-inference
Instructions to use EzioDevio/ArduinoLLM-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use EzioDevio/ArduinoLLM-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="EzioDevio/ArduinoLLM-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("EzioDevio/ArduinoLLM-7B") model = AutoModelForCausalLM.from_pretrained("EzioDevio/ArduinoLLM-7B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use EzioDevio/ArduinoLLM-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "EzioDevio/ArduinoLLM-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EzioDevio/ArduinoLLM-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/EzioDevio/ArduinoLLM-7B
- SGLang
How to use EzioDevio/ArduinoLLM-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "EzioDevio/ArduinoLLM-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EzioDevio/ArduinoLLM-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "EzioDevio/ArduinoLLM-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EzioDevio/ArduinoLLM-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use EzioDevio/ArduinoLLM-7B with Docker Model Runner:
docker model run hf.co/EzioDevio/ArduinoLLM-7B
Upload folder using huggingface_hub
Browse files- README.md +43 -50
- model.safetensors +1 -1
README.md
CHANGED
|
@@ -1,42 +1,54 @@
|
|
| 1 |
-
-
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
|
| 4 |
-
tags:
|
| 5 |
-
- arduino
|
| 6 |
-
- esp32
|
| 7 |
-
- raspberry-pi
|
| 8 |
-
- micropython
|
| 9 |
-
- circuitpython
|
| 10 |
-
- embedded-systems
|
| 11 |
-
- code-generation
|
| 12 |
-
- lora
|
| 13 |
-
- continued-pretraining
|
| 14 |
-
language:
|
| 15 |
-
- en
|
| 16 |
-
library_name: transformers
|
| 17 |
-
---
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|---|---|---|
|
| 33 |
| Format compliance | 83% | **100%** |
|
| 34 |
-
|
|
| 35 |
-
| Correct runtime API | 92% | 92% |
|
| 36 |
-
|
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
|
| 41 |
## Usage
|
| 42 |
|
|
@@ -49,26 +61,7 @@ model, tokenizer = FastLanguageModel.from_pretrained(
|
|
| 49 |
load_in_4bit=True,
|
| 50 |
)
|
| 51 |
FastLanguageModel.for_inference(model)
|
| 52 |
-
|
| 53 |
-
prompt = "How do I wire a BME280 sensor to an ESP32 over I2C, with Arduino code?"
|
| 54 |
-
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 55 |
-
outputs = model.generate(**inputs, max_new_tokens=1300)
|
| 56 |
-
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 57 |
```
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
- **Synthetic**: 1,607 unique wiring/code examples, generated via the Anthropic API, Google's Gemini API, and a locally-hosted Qwen2.5-Coder-32B, validated for format compliance and runtime contamination.
|
| 62 |
-
- **Real corpus**: ~500M tokens (of a 2.59B-token total) from real Arduino/MicroPython/CircuitPython library source code.
|
| 63 |
-
|
| 64 |
-
OpenAI and DeepSeek were not used, since both explicitly prohibit using their API output to train competing models.
|
| 65 |
-
|
| 66 |
-
## Limitations
|
| 67 |
-
|
| 68 |
-
- Most reliable on well-represented single-component combinations.
|
| 69 |
-
- v2 used only ~19% of the available real-code corpus.
|
| 70 |
-
- Always verify wiring against the component's actual datasheet before connecting power.
|
| 71 |
-
|
| 72 |
-
## Full pipeline and dataset
|
| 73 |
-
|
| 74 |
-
See [github.com/EzioDEVio/ArduinoLLM-7B](https://github.com/EzioDEVio/ArduinoLLM-7B) for the complete training pipeline, dataset, and evaluation scripts.
|
|
|
|
| 1 |
+
# ArduinoLLM-7B
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
An open-source, LoRA-tuned Qwen2.5-Coder-7B specialist for embedded systems wiring and code generation — Arduino C++, Raspberry Pi Python, MicroPython, and CircuitPython, across 9 boards (ESP32, ESP32-S3, ESP32-C3, Raspberry Pi, Raspberry Pi Pico, Arduino Uno, ESP8266, Teensy 4.0, M5Stack Core2).
|
| 4 |
|
| 5 |
+
Given a component and a board, it produces a wiring table, an ASCII wiring diagram, working code, and a short explanation — in one consistent format.
|
| 6 |
|
| 7 |
+
## v2: Corpus-Enhanced Training
|
| 8 |
|
| 9 |
+
v1 was trained entirely on synthetic examples generated by LLMs (Claude, Gemini, and a locally-hosted Qwen2.5-Coder-32B). That approach is fast and controllable, but it has a real ceiling: a model trained only on another model's *description* of correct wiring can't be more accurate than the model that generated its training data.
|
| 10 |
|
| 11 |
+
v2 adds a genuine second training stage: **continued pretraining directly on real library source code** — 240,634 real files (~2.59 billion tokens) from the actual Arduino core libraries, `micropython-lib`, and the Adafruit CircuitPython Bundle. This release trained on the first ~500 million tokens (~19% of the corpus) of that real code, then re-ran instruction fine-tuning on top to restore clean output formatting.
|
| 12 |
|
| 13 |
+
### Why this matters
|
| 14 |
|
| 15 |
+
Manual testing of v1 found three concrete, reproducible failure modes:
|
| 16 |
+
- A wiring diagram that internally contradicted its own wiring table
|
| 17 |
+
- A fabricated, non-functional I2C address-conflict "fix" using invented register names
|
| 18 |
+
- A weather-station answer that invented a CO2 reading from a sensor (BME280) that cannot measure CO2
|
| 19 |
+
|
| 20 |
+
All three were re-tested after v2 training and no longer reproduce.
|
| 21 |
+
|
| 22 |
+
### Measured results (12-question held-out benchmark)
|
| 23 |
+
|
| 24 |
+
| Metric | v1 (synthetic only) | v2 (corpus + synthetic) |
|
| 25 |
|---|---|---|
|
| 26 |
| Format compliance | 83% | **100%** |
|
| 27 |
+
| Runtime-contamination-free | 100% | 100% |
|
| 28 |
+
| Correct runtime API present | 92% | 92% |
|
| 29 |
+
| Code syntax valid | ~100% | 100% |
|
| 30 |
+
| Generation speed (RTX 5090) | 73.2 tok/s | 37.5 tok/s |
|
| 31 |
+
|
| 32 |
+
**Known tradeoff**: v2 is currently slower than v1 due to being loaded from a locally re-merged checkpoint rather than a pre-optimized quantized repo. A faster-quantized export may follow.
|
| 33 |
+
|
| 34 |
+
## How it was built
|
| 35 |
+
|
| 36 |
+
1. **Dataset generation** — synthetic wiring/code examples generated via the Anthropic API, Google's Gemini API, and a locally-hosted Qwen2.5-Coder-32B (via vLLM), validated for format compliance and runtime contamination. 1,607 unique examples in `full_dataset.jsonl`.
|
| 37 |
+
2. **Continued pretraining** — `prepare_pretraining_corpus.py` chunks real library source into 2048-token blocks; `train_continued_pretrain.py` runs LoRA rank-32 training with `embed_tokens`/`lm_head` unlocked (needed to absorb new vocabulary/patterns from raw code, not just new behavior).
|
| 38 |
+
3. **Merge** — `merge_pretrain_checkpoint.py` combines the pretraining adapter into a standalone base model.
|
| 39 |
+
4. **Instruction fine-tuning** — `train_lora.py` re-runs standard LoRA fine-tuning (rank 16, attention/MLP only) on top of the corpus-enhanced base, using the same synthetic dataset as v1.
|
| 40 |
+
5. **Final merge** — `merge_final_release.py` combines both stages into the single published model.
|
| 41 |
+
6. **Evaluation** — `evaluate_model.py` runs the 12-question automated benchmark; manual testing checks specific documented failure modes via `ask_model.py`.
|
| 42 |
+
|
| 43 |
+
## Licensing note
|
| 44 |
+
|
| 45 |
+
Built on Qwen2.5-Coder-7B-Instruct (Apache 2.0). Synthetic training data was generated using Anthropic's and Google's APIs, and a locally-run open-weight model ��� OpenAI and DeepSeek were deliberately not used for data generation, as both explicitly prohibit using their outputs to train competing models in their terms of service. The real-code corpus (Arduino core libraries, `micropython-lib`, CircuitPython Bundle) is used under each project's own open-source license.
|
| 46 |
+
|
| 47 |
+
## Limitations
|
| 48 |
|
| 49 |
+
- Reliable on single-component, well-represented combinations; less reliable on genuinely novel multi-sensor combinations or troubleshooting scenarios not well-represented in the training data.
|
| 50 |
+
- v2 trained on only ~19% of the available real-code corpus; the remaining ~81% has not yet been used.
|
| 51 |
+
- Not a substitute for checking your own wiring against a component's actual datasheet, especially for voltage-sensitive components.
|
| 52 |
|
| 53 |
## Usage
|
| 54 |
|
|
|
|
| 61 |
load_in_4bit=True,
|
| 62 |
)
|
| 63 |
FastLanguageModel.for_inference(model)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
```
|
| 65 |
|
| 66 |
+
See `ask_model.py` for a full interactive example.
|
| 67 |
+
- Character LCD displays (HD44780-style, in any interface variant — parallel, I2C backpack, or claimed SPI) are currently unreliable; wiring diagrams have shown pin fabrication and internal inconsistency with the accompanying code across multiple tests. Recommend manual verification against your specific module's datasheet for these displays specifically.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 15231272152
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:928994a9da7b2aafb9d3913d6cc1c205c2c2f853093b0327928b1b140b6406eb
|
| 3 |
size 15231272152
|