Text Generation
MLX
Safetensors
PyTorch
English
llama4_text
facebook
meta
mobilellm
mlx - apple-mlx - runtime
conversational
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 @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": "robbiemu/MobileLLM-R1-950M-MLX" } ] } } }Run Pi
# Start Pi in your project directory: pi
- 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"} ] }' - Hermes Agent
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
- Atomic Chat
- OpenClaw
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"
|
Download custom_mlx_lm/README.md from robbiemu/MobileLLM-R1-950M-MLX: direct link, hf CLI and curl.
- Browser
- Download file 3.1 kB
-
https://huggingface.co/robbiemu/MobileLLM-R1-950M-MLX/resolve/main/custom_mlx_lm/README.md
- Command line
-
hf download hf://robbiemu/MobileLLM-R1-950M-MLX/custom_mlx_lm/README.md
-
curl -L -o README.md https://huggingface.co/robbiemu/MobileLLM-R1-950M-MLX/resolve/main/custom_mlx_lm/README.md
3.1 kB
Custom MLX-LM Conversion, Quantization, and Inference
Overview
- Scripts here convert the HF safetensors model to MLX format, optionally apply mixed-precision dynamic quantization, and run inference with prompt formatting consistent with inference.py.
- Quant layout is persisted in config.json so the loader can re-materialize only Linear layers as QuantizedLinear while keeping embeddings and norms in float.
Key scripts
- custom_convert_2.py
- Convert and optionally quantize.
- Mixed precision uses calibration data and a sensitivity-driven split between 4-bit and 8-bit Linear layers.
- Saves weights to weights.npz and writes quantization metadata to config.json.
- custom_loader.py
- Loads the model with the correct module types (QuantizedLinear vs float) based on config metadata, then applies saved weights.
- Leaves embeddings and layernorms in float.
- inference_mlx_lm.py (CLI: mobilellm-infer)
- Runs generation. Uses chat_template.jinja when present, else prepends BOS, matching inference.py behavior.
- quant_summary.py
- Prints a summary of per-layer bit-widths and checks quantized tensors exist in weights.npz.
Quickstart
- Mixed-precision dynamic quantization
- uv run python custom_mlx_lm/custom_convert_2.py --hf-path . --mlx-path MobileLLM-R1-950M-mixed-4bit-mlx --dynamic-quant --target-bpw 4.5 --report-ppl
- Group size defaults to 64 when not provided.
- Uniform quantization
- uv run python custom_mlx_lm/custom_convert_2.py --hf-path . --mlx-path MobileLLM-R1-950M-4bit-mlx --quantize --bits 4 --report-ppl
- Summarize quant layout
- uv run python custom_mlx_lm/quant_summary.py --model-path MobileLLM-R1-950M-mixed-4bit-mlx --show 8
- Inference
- mobilellm-infer --model-path MobileLLM-R1-950M-mixed-4bit-mlx --prompt "What is the nearest prime to 9^2?"
Notes and defaults
- Calibration: load_data uses WikiText-like data; dynamic quant computes sensitivities once and chooses 4/8-bit per Linear layer to target the requested bits-per-weight. Reported PPL is from the same set.
- Group size: defaults to 64 when quantizing if not provided.
- Prompt formatting: by default uses chat_template.jinja if present; otherwise prepends BOS for stable behavior across float and quant models.
Troubleshooting
- Empty sensitivities (ValueError: min() arg is empty)
- Fixed: ensure Linear weights are not frozen during sensitivity estimation; grads must exist.
- Unable to quantize model of type QuantizedLinear
- Fixed: second quantization pass now targets only remaining float Linear layers.
- [dequantize] The matrix should be given as a uint32
- Fixed: loader does not blanket-quantize; it re-materializes only Linear layers from per-layer bits map before loading weights, leaving embeddings in float.
Rationale and behavior
- Persist per-layer bits: enables deterministic, loader-driven reconstruction of quant modules and prevents accidental quantization of unsupported modules.
- Keep embeddings float: avoids dtype mismatch and preserves quality.
- Match inference.py formatting: improves output consistency between float and quant variants.