Instructions to use KarRak007/qwen2.5-coder-3b-sql-doctor-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use KarRak007/qwen2.5-coder-3b-sql-doctor-mlx with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("KarRak007/qwen2.5-coder-3b-sql-doctor-mlx") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use KarRak007/qwen2.5-coder-3b-sql-doctor-mlx with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use KarRak007/qwen2.5-coder-3b-sql-doctor-mlx with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use KarRak007/qwen2.5-coder-3b-sql-doctor-mlx with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default KarRak007/qwen2.5-coder-3b-sql-doctor-mlx
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use KarRak007/qwen2.5-coder-3b-sql-doctor-mlx with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
qwen2.5-coder-3b-sql-doctor-mlx
A domain-adapted Small Language Model (SLM) for offline SQL performance diagnosis, query rewriting, and index recommendation on Apple Silicon.
Fine-tuned from mlx-community/Qwen2.5-Coder-3B-Instruct-4bit by Kartik Raktate.
๐ฏ Motivation: Privacy & Zero Cloud Dependency
Enterprise production databases contain sensitive customer schemas, confidential column names, and proprietary business logic. Sending production queries to third-party cloud LLMs creates compliance risks and ongoing API costs.
qwen2.5-coder-3b-sql-doctor-mlx runs 100% locally and offline on Apple Silicon via Apple's native MLX framework. It acts as an on-device Senior Database Administrator (DBA) for developer CLI tools, local IDEs, and offline CI/CD pipelines.
โก Key Highlights
- Edge Optimized: Quantized to 4-bit group-wise INT4 precision. Runs with only ~2.1 GB of RAM on Apple Silicon unified memory.
- Strict Domain Output: Generates clean, structured technical reports with:
- Root-Cause Diagnosis: Exact explanation of why the query suffers from sequential scans, memory spills, or CPU bottlenecks.
- Optimized SQL: Rewritten query eliminating anti-patterns (
SELECT *, unindexed subqueries, functions on indexed columns). - Migration Index DDL: Ready-to-run
CREATE INDEX CONCURRENTLY ...statement for PostgreSQL or MySQL.
- Sub-Second Latency: Delivers instantaneous token generation locally using Metal GPU acceleration on Mac.
๐ Quickstart: Running Locally with MLX
1. Installation
pip install mlx-lm
2. Python Inference
from mlx_lm import load, generate
# Load model directly from Hugging Face Hub
model_id = "KarRak007/qwen2.5-coder-3b-sql-doctor-mlx"
model, tokenizer = load(model_id)
# Prompt with your slow query and table schema
user_prompt = """Query: SELECT * FROM orders WHERE YEAR(order_date) = 2024;
Schema: orders (id BIGINT, user_id BIGINT, total NUMERIC, status VARCHAR, order_date DATE)"""
messages = [
{
"role": "system",
"content": "You are sql-doctor, an expert Database Administrator and SQL performance engineer. Analyze the query and provide: 1) Diagnosis, 2) Optimized Query, and 3) Recommended Index."
},
{"role": "user", "content": user_prompt}
]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
response = generate(model, tokenizer, prompt=prompt, max_tokens=350, verbose=False)
print(response)
3. Interactive Terminal Chat
You can test the model interactively directly in your terminal:
python3 -m mlx_lm.chat --model KarRak007/qwen2.5-coder-3b-sql-doctor-mlx
๐ก Example Evaluation
Input Prompt:
Query: SELECT * FROM audit_logs WHERE action LIKE '%login_failed%' ORDER BY created_at DESC LIMIT 50;
Schema: audit_logs (id BIGINT, action VARCHAR, entity_type VARCHAR, entity_id BIGINT, created_at TIMESTAMP)
Model Output:
### Diagnosis
1. `LIKE '%pattern%'` with a leading wildcard cannot leverage a standard B-Tree index, forcing an expensive full sequential scan over disk.
2. `SELECT *` incurs unnecessary I/O overhead reading unused column blocks.
### Optimized Query
```sql
SELECT id, action, entity_id, created_at
FROM audit_logs
WHERE action LIKE '%login_failed%'
ORDER BY created_at DESC
LIMIT 50;
Recommended Index
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX CONCURRENTLY idx_audit_logs_action_gin ON audit_logs USING gin (action gin_trgm_ops);
---
## ๐ ๏ธ Companion Tool: `sql-doctor` CLI
This model powers **`sql-doctor`**, an open-source hybrid static AST analyzer and database query doctor that runs locally in terminal workflows.
```bash
# Check query anti-patterns locally
sql-doctor check "SELECT * FROM users JOIN orders WHERE email LIKE '%@gmail.com'"
๐ Technical Specifications
| Parameter | Specification |
|---|---|
| Base Architecture | Qwen 2.5 Coder 3B Instruct |
| Quantization | 4-bit INT4 Group-wise |
| Trained Layers | LoRA Attention & MLP Adaptors ($r=8, \alpha=16$) |
| Context Window | 32,768 tokens |
| Memory Footprint | ~2.1 GB VRAM / Unified Memory |
| Inference Framework | Apple MLX (mlx-lm) |
| Primary Dialects | PostgreSQL, MySQL, ANSI SQL |
๐ License & Attribution
This model is licensed under the Apache 2.0 License.
Developed and maintained by Kartik Raktate.
- Downloads last month
- -
4-bit