Instructions to use Tekimax/granite-ml-coder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Tekimax/granite-ml-coder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Tekimax/granite-ml-coder") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Tekimax/granite-ml-coder") model = AutoModelForCausalLM.from_pretrained("Tekimax/granite-ml-coder") 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - MLX
How to use Tekimax/granite-ml-coder 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("Tekimax/granite-ml-coder") 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
- vLLM
How to use Tekimax/granite-ml-coder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Tekimax/granite-ml-coder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Tekimax/granite-ml-coder", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Tekimax/granite-ml-coder
- SGLang
How to use Tekimax/granite-ml-coder 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 "Tekimax/granite-ml-coder" \ --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": "Tekimax/granite-ml-coder", "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 "Tekimax/granite-ml-coder" \ --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": "Tekimax/granite-ml-coder", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Pi
How to use Tekimax/granite-ml-coder with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "Tekimax/granite-ml-coder"
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "Tekimax/granite-ml-coder" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use Tekimax/granite-ml-coder 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 "Tekimax/granite-ml-coder"
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 Tekimax/granite-ml-coder
Run Hermes
hermes
- MLX LM
How to use Tekimax/granite-ml-coder with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "Tekimax/granite-ml-coder"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "Tekimax/granite-ml-coder" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Tekimax/granite-ml-coder", "messages": [ {"role": "user", "content": "Hello"} ] }' - Docker Model Runner
How to use Tekimax/granite-ml-coder with Docker Model Runner:
docker model run hf.co/Tekimax/granite-ml-coder
granite-ml-coder
A compact Python / machine-learning coding assistant, fine-tuned from
ibm-granite/granite-3.1-1b-a400m-instruct. It writes runnable
scikit-learn / pandas / NumPy code, explains ML pipeline steps, and reasons about
everyday concepts like overfitting, cross-validation, and gradient descent.
It is small enough to run fully locally — on a laptop CPU, via Ollama, or quantized to GGUF — which makes it a good private copilot for data-science work where your data shouldn't leave the machine.
Built as the reference model for the TEKIMAX ML Model Workshop (fine-tune → host on HF/Ollama → build a production DL app).
Quick start
Transformers
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
tok = AutoTokenizer.from_pretrained("Tekimax/granite-ml-coder")
model = AutoModelForCausalLM.from_pretrained(
"Tekimax/granite-ml-coder", dtype=torch.float32, attn_implementation="eager"
)
messages = [
{"role": "system", "content": "You are an expert Python machine-learning engineer."},
{"role": "user", "content": "Write a scikit-learn pipeline to classify the iris dataset and explain how you avoid overfitting."},
]
enc = tok.apply_chat_template(messages, add_generation_prompt=True,
return_tensors="pt", return_dict=True, enable_thinking=False)
out = model.generate(**enc, max_new_tokens=400, do_sample=True, temperature=0.7, top_p=0.9)
print(tok.decode(out[0][enc["input_ids"].shape[1]:], skip_special_tokens=True))
Ollama (recommended for local use)
ollama run tekimaxllc/granite-ml-coder "Write a Keras autoencoder for network-traffic anomaly detection"
GGUF / llama.cpp
A 4-bit Q4_K_M build (~378 MB) is available at
Tekimax/granite-ml-coder-GGUF:
llama-cli -m granite-ml-coder-Q4_K_M.gguf -p "Write a sklearn pipeline"
Intended use
- Drafting Python ML code (scikit-learn, pandas, NumPy, Keras) inside notebooks/IDEs
- Explaining ML pipeline steps and concepts (overfitting, gradient descent, model choice)
- A private, offline coding copilot for data-science tasks
Training
| Base model | ibm-granite/granite-3.1-1b-a400m-instruct (Apache-2.0, IBM) — ~1.3B total / 400M active MoE |
| Data | iamtarun/python_code_instructions_18k_alpaca, filtered to ML/DS rows (≈2,341 examples) |
| Method | Full fine-tune, instruction format with the Granite chat template; loss computed on the assistant answer only (prompt tokens masked) |
| Schedule | 2 epochs · effective batch size 16 · LR 2e-5 cosine · max_len 512 |
| Hardware | Apple M2 Ultra, CPU (the MPS/Metal backend was unstable for fine-tuning on torch 2.12 — see the workshop appendix) |
| Result | training loss decreasing steadily, no NaN |
Limitations
- It's a 1B model. It learns style, format, and common patterns well, but is not a frontier model — it can produce incomplete or subtly wrong code, and it won't reliably "pick the best model" for hard problems. Treat its output as a fast first draft and verify before use.
- English, Python-focused. Strongest on classic ML (sklearn/pandas); weaker on large, novel, or multi-file tasks.
- Inherits any biases/limitations of the base model and the training dataset.
License
Apache-2.0, inherited from the base model and dataset.
Citation / credits
- Base model: Granite
- Dataset: iamtarun/python_code_instructions_18k_alpaca
- Built with Hugging Face
transformersTrainer; quantized withllama.cpp.
- Downloads last month
- 23
Quantized
Model tree for Tekimax/granite-ml-coder
Base model
ibm-granite/granite-3.1-1b-a400m-base