Instructions to use robbiemu/MobileLLM-R1-950M-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use robbiemu/MobileLLM-R1-950M-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("robbiemu/MobileLLM-R1-950M-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 robbiemu/MobileLLM-R1-950M-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 "robbiemu/MobileLLM-R1-950M-MLX"
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": "robbiemu/MobileLLM-R1-950M-MLX" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use robbiemu/MobileLLM-R1-950M-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 "robbiemu/MobileLLM-R1-950M-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 robbiemu/MobileLLM-R1-950M-MLX
Run Hermes
hermes
- OpenClaw new
How to use robbiemu/MobileLLM-R1-950M-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 "robbiemu/MobileLLM-R1-950M-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 "robbiemu/MobileLLM-R1-950M-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"
- MLX LM
How to use robbiemu/MobileLLM-R1-950M-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 "robbiemu/MobileLLM-R1-950M-MLX"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "robbiemu/MobileLLM-R1-950M-MLX" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "robbiemu/MobileLLM-R1-950M-MLX", "messages": [ {"role": "user", "content": "Hello"} ] }'
Porting MobileLLM-R1-950M to MLX and mlx-lm: Architectural Challenges and Solutions
I spent a some time pairing with Gemini 2.5 Pro and later OpenAI Codex to drag the brand-new facebook/MobileLLM-R1-950M weights onto Apple Silicon. This write-up is the “why it wasn’t copy-paste” story, plus the gotchas that bit us until the model finally spoke clean English and quantized without drama.
Goal
Enable facebook/MobileLLM-R1-950M to run natively on Apple Silicon using MLX, then create quantized versions compatible with the mlx-lm ecosystem.
1. Why a Direct "Llama-4 Drop-In" Failed
Although the Hugging Face repo presents MobileLLM-R1-950M as a Llama-4-style dense model, its config and weights don't align cleanly with a stock Llama block. The deviations aren't quirks of MLX—they reflect this model's specific architecture:
MLP ambiguity
Config advertises bothintermediate_sizeandintermediate_size_mlp, suggesting a dual-branch feed-forward.
Actual weights contain only a SwiGLU branch (gate_proj,up_proj,down_proj).
→ Solution: auto-detect MLP variant from weight names at load time.Grouped-Query Attention (GQA)
num_attention_heads=24,num_key_value_heads=6.
K/V tensors must be repeated to full head count for attention shapes to align correctly.QK-norm and scaling
Config includesuse_qk_norm=Trueandattn_scale=0.1.
We add the RMSNorm on Q/K as specified, but drop the extra0.1multiplier—applying it in MLX'sscaled_dot_product_attentioncollapses logits into gibberish.RoPE gating
Config lists all layers underno_rope_layers.
Disabling RoPE everywhere would eliminate positional encoding entirely.
→ Treat "all layers disabled" as a config artifact and apply RoPE everywhere.
2. Prompt-Level Deviations
Even after weights loaded correctly, default inference was disrupted by tokenizer settings:
Chat template
Default system prompt: "Please reason step-by-step and put your final answer within \boxed{}."
Without overrides, the model produces verbose "reasoning" outputs.
→ Added CLI controls:--system,--disable-chat-template,--final-only.Double BOS
Both tokenizer and template inserted BOS tokens.
→ Fixed withadd_special_tokens=False.Premature EOS
Template headers (<|eot_id|>) were treated as stop tokens.
→ Limited stopping criteria to true EOS token only.
3. Sampling Stability
Sampling issues stemmed from API mismatches rather than model problems:
- Top-p on probabilities then feeding
mx.random.categoricalproduced repetition loops. - Solution: Apply penalties → scale logits → top-p mask (with
float('-inf')) →categorical(logits). - Added controls for temperature, repetition penalty, frequency penalty.
4. Quantization in mlx-lm: Why Custom Metadata Was Required
mlx-lm provides quantization hooks, but MobileLLM's architecture exposed several challenges:
Frozen gradients during sensitivity analysis → empty sensitivity lists.
→ Avoid freezing weights during gradient computation.Re-quantizing quantized layers → type errors on second pass.
→ SkipQuantizedLinearlayers if already quantized.Embedding/norm dtype crashes
Standard quantization re-quantized everything, but embeddings must remain float.
→ Introduced metadata-driven approach: config.json records per-layer bit-widths. Only specified layers are instantiated asQuantizedLinear.
This metadata contract allows 4-bit mixed-precision MobileLLM to be loaded cleanly by our metadata-aware custom_loader.py, making it compatible with the mlx-lm ecosystem.
5. End State
MLX path:
Structural fixes (GQA, MLP detection), numerical fixes (QK-norm, RoPE, attn_scale), and prompt controls together yield fluent, stable inference.mlx-lm path:
Custom quantization pipeline produces FP16 and 4-bit models. These can be loaded with our metadata-awarecustom_loader.pyand used for inference with our provided scripts.
Performance: measurable speedup and reduced VRAM usage on Apple Silicon, with minimal quality degradation.
Takeaway
The MobileLLM-R1-950M port required systematically addressing architectural mismatches (MLP variant detection, GQA handling, QK-norm implementation, RoPE configuration) and developing a metadata-driven quantization approach. Once these were resolved, the model became fully functional in MLX with both float and quantized inference paths.