Text Generation
Transformers
GGUF
Rust
English
German
compound-ai
domain-expert
code-generation
ast-refactoring
cpp
python
lumi-g
moe-sovereign
conversational
Instructions to use h3rb3rn/moe-expert-coder-4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use h3rb3rn/moe-expert-coder-4b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="h3rb3rn/moe-expert-coder-4b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("h3rb3rn/moe-expert-coder-4b", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use h3rb3rn/moe-expert-coder-4b with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf h3rb3rn/moe-expert-coder-4b:Q4_K_M # Run inference directly in the terminal: llama cli -hf h3rb3rn/moe-expert-coder-4b:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf h3rb3rn/moe-expert-coder-4b:Q4_K_M # Run inference directly in the terminal: llama cli -hf h3rb3rn/moe-expert-coder-4b:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf h3rb3rn/moe-expert-coder-4b:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf h3rb3rn/moe-expert-coder-4b:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf h3rb3rn/moe-expert-coder-4b:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf h3rb3rn/moe-expert-coder-4b:Q4_K_M
Use Docker
docker model run hf.co/h3rb3rn/moe-expert-coder-4b:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use h3rb3rn/moe-expert-coder-4b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "h3rb3rn/moe-expert-coder-4b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "h3rb3rn/moe-expert-coder-4b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/h3rb3rn/moe-expert-coder-4b:Q4_K_M
- SGLang
How to use h3rb3rn/moe-expert-coder-4b 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 "h3rb3rn/moe-expert-coder-4b" \ --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": "h3rb3rn/moe-expert-coder-4b", "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 "h3rb3rn/moe-expert-coder-4b" \ --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": "h3rb3rn/moe-expert-coder-4b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use h3rb3rn/moe-expert-coder-4b with Ollama:
ollama run hf.co/h3rb3rn/moe-expert-coder-4b:Q4_K_M
- Unsloth Studio
How to use h3rb3rn/moe-expert-coder-4b with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for h3rb3rn/moe-expert-coder-4b to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for h3rb3rn/moe-expert-coder-4b to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for h3rb3rn/moe-expert-coder-4b to start chatting
- Docker Model Runner
How to use h3rb3rn/moe-expert-coder-4b with Docker Model Runner:
docker model run hf.co/h3rb3rn/moe-expert-coder-4b:Q4_K_M
- Lemonade
How to use h3rb3rn/moe-expert-coder-4b with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull h3rb3rn/moe-expert-coder-4b:Q4_K_M
Run and chat with the model
lemonade run user.moe-expert-coder-4b-Q4_K_M
List all available models
lemonade list
- Atomic Chat
docs: upload comprehensive model card for moe-expert-coder-4b
Browse files
README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- de
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
base_model: Qwen/Qwen3.5-4B
|
| 7 |
+
tags:
|
| 8 |
+
- compound-ai
|
| 9 |
+
- domain-expert
|
| 10 |
+
- coding
|
| 11 |
+
- refactoring
|
| 12 |
+
- ast-validation
|
| 13 |
+
- gguf
|
| 14 |
+
- lumi-g
|
| 15 |
+
- moe-sovereign
|
| 16 |
+
datasets:
|
| 17 |
+
- moe-sovereign/expert-coder-sft
|
| 18 |
+
pipeline_tag: text-generation
|
| 19 |
+
library_name: transformers
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# 💻 MoE Sovereign Coder Expert 4B (`moe-expert-coder-4b`)
|
| 23 |
+
*High-Assurance Code Synthesis, Refactoring & AST-Verified Tool Execution*
|
| 24 |
+
|
| 25 |
+
[](https://opensource.org/licenses/Apache-2.0)
|
| 26 |
+
[](https://huggingface.co/Qwen/Qwen3.5-4B)
|
| 27 |
+
[](https://www.lumi-supercomputer.eu/)
|
| 28 |
+
|
| 29 |
+
---
|
| 30 |
+
|
| 31 |
+
## 📌 Executive Summary
|
| 32 |
+
|
| 33 |
+
**`moe-expert-coder-4b`** is a domain-specialized 4-billion parameter Small Language Model (SLM) distilled from **DeepSeek-Coder-V2 (236B)** and **DeepSeek-V3** on the **LUMI-G Supercomputer** (8× AMD Instinct™ MI250X 128GB GPUs).
|
| 34 |
+
|
| 35 |
+
It functions as the dedicated **Software Engineering & High-Assurance Coding Expert** within the MoE Sovereign compound AI architecture. The model is specifically tuned to generate syntax-validated Python, Rust, Go, TypeScript, and C++ code, write atomic unified diffs, adhere to strict static analysis and typing constraints, and correct runtime stack traces through persistent Correction Memory.
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## 🎯 Target Use Cases & Functional Scope
|
| 40 |
+
|
| 41 |
+
1. **Deterministic Code Generation:** Synthesizes production-ready algorithms, microservices, and system-level routines with explicit error handling and type signatures.
|
| 42 |
+
2. **AST-Compliant Refactoring & Atomic Diffs:** Produces minimal, robust diff chunks suitable for automated CI/CD integration without broken syntax trees.
|
| 43 |
+
3. **Static Analysis & Type Checking Compliance:** Generates code guaranteed to satisfy strict Linters (`mypy`, `ruff`, `clippy`, `eslint`).
|
| 44 |
+
4. **Execution Log & Stack Trace Triage:** Rapidly pinpoints root causes in multi-tier error traces and formulates minimal regression-tested patches.
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## 🔬 Behavioral Comparison: Stock Qwen 3.5 4B vs. Distilled Coder
|
| 49 |
+
|
| 50 |
+
| Capability | Base Stock Qwen 3.5 4B | `moe-expert-coder-4b` (Distilled) |
|
| 51 |
+
| :--- | :--- | :--- |
|
| 52 |
+
| **Code Structure** | Explanatory text surrounding code blocks | **Pure, AST-Parsable Code Artifacts** and precise unified diffs |
|
| 53 |
+
| **Typing Discipline** | Optional or inconsistent type hints | **Strict Type Annotations** across all parameters and return types |
|
| 54 |
+
| **Edge Case Handling** | Omits boundary checks or fallback paths | **Defensive Error Handling** with explicit exceptions and error types |
|
| 55 |
+
| **Diff Accuracy** | Generates full-file rewrites prone to hallucination | **Surgical Unified Diffs** with exact line ranges and matching context |
|
| 56 |
+
| **Tool Calling Integration**| Generic code snippet generation | **MCP-Aligned Code Execution Payloads** ready for sandbox execution |
|
| 57 |
+
|
| 58 |
+
---
|
| 59 |
+
|
| 60 |
+
## 🏋️ Training Setup & Distillation Methodology
|
| 61 |
+
|
| 62 |
+
```
|
| 63 |
+
+-----------------------------------------------------------------------------------+
|
| 64 |
+
| LUMI-G DISTILLATION PIPELINE |
|
| 65 |
+
| |
|
| 66 |
+
| [ Teachers: DeepSeek-Coder-V2 (236B) + DeepSeek-V3 ] |
|
| 67 |
+
| | |
|
| 68 |
+
| v (AST Parse Validation + PyTest Execution Verification) |
|
| 69 |
+
| [ SFT Dataset: 32,500 High-Assurance Coding & Refactoring Trajectories ] |
|
| 70 |
+
| | |
|
| 71 |
+
| v (DeepSpeed ZeRO-2, ROCm 7.0, PyTorch 2.6, 8x MI250X) |
|
| 72 |
+
| [ Student: Qwen3.5-4B Hybrid Linear Attention + Mamba Base ] |
|
| 73 |
+
| | |
|
| 74 |
+
| v (LoRA r=16, alpha=32, target_modules: q/k/v/o/gate/up/down)|
|
| 75 |
+
| [ Output: final_adapter -> CPU-BF16 Merge -> GGUF Q4_K_M & Q8_0 ] |
|
| 76 |
+
+-----------------------------------------------------------------------------------+
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
### Hyperparameters:
|
| 80 |
+
- **Compute Cluster:** LUMI-G (8× AMD Instinct MI250X 128GB GPUs, Slurm Job `#21190761`)
|
| 81 |
+
- **Base Architecture:** Qwen3.5-4B (Hybrid Linear Attention + Mamba in BF16)
|
| 82 |
+
- **Dataset Size:** 32,500 AST-validated code synthesis trajectories
|
| 83 |
+
- **Epochs:** 3.0
|
| 84 |
+
- **Effective Batch Size:** 128 (Micro-batch 4 × 8 GPUs × Gradient Accumulation 4)
|
| 85 |
+
- **Learning Rate:** $1.5 \times 10^{-5}$ with Cosine Decay and Warmup
|
| 86 |
+
- **LoRA Configuration:** $r=16$, $\alpha=32$, Dropout $0.05$, Target Modules: `q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj`
|
| 87 |
+
- **Training Loss (Final):** `0.0106`
|
| 88 |
+
- **Token Accuracy (Final):** **`99.62 %`**
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
## 💻 Quickstart Guide (Ollama & Llama.cpp)
|
| 93 |
+
|
| 94 |
+
### 1. Ollama `Modelfile`
|
| 95 |
+
```dockerfile
|
| 96 |
+
FROM ./moe-expert-coder-4b-Q4_K_M.gguf
|
| 97 |
+
PARAMETER num_ctx 262144
|
| 98 |
+
PARAMETER temperature 0.1
|
| 99 |
+
TEMPLATE """{{ if .System }}<|im_start|>system
|
| 100 |
+
{{ .System }}<|im_end|>
|
| 101 |
+
{{ end }}{{ if .Prompt }}<|im_start|>user
|
| 102 |
+
{{ .Prompt }}<|im_end|>
|
| 103 |
+
{{ end }}<|im_start|>assistant
|
| 104 |
+
{{ .Response }}<|im_end|>"""
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
### 2. Python Inference
|
| 108 |
+
```python
|
| 109 |
+
import torch
|
| 110 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 111 |
+
|
| 112 |
+
model_id = "h3rb3rn/moe-expert-coder-4b"
|
| 113 |
+
|
| 114 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 115 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 116 |
+
model_id,
|
| 117 |
+
torch_dtype=torch.bfloat16,
|
| 118 |
+
device_map="auto",
|
| 119 |
+
trust_remote_code=True
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
prompt = "<|im_start|>user\nWrite a thread-safe asynchronous WAL writer in Rust with CRC32 checksum framing.<|im_end|>\n<|im_start|>assistant\n"
|
| 123 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 124 |
+
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.1)
|
| 125 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
---
|
| 129 |
+
|
| 130 |
+
## 📑 Citation
|
| 131 |
+
|
| 132 |
+
```bibtex
|
| 133 |
+
@misc{moe_sovereign_2026_coder4b,
|
| 134 |
+
author = {Horn, Philipp and MoE Sovereign Core AI Team},
|
| 135 |
+
title = {MoE Sovereign Coder Expert 4B: High-Assurance Code Synthesis & Refactoring SLM},
|
| 136 |
+
year = {2026},
|
| 137 |
+
publisher = {Hugging Face},
|
| 138 |
+
howpublished = {\url{https://huggingface.co/h3rb3rn/moe-expert-coder-4b}},
|
| 139 |
+
note = {Trained on the EuroHPC LUMI-G Supercomputer}
|
| 140 |
+
}
|
| 141 |
+
```
|