GGUF
llama.cpp
conversational
How to use from
Hermes Agent
# Gated model: Login with a HF token with gated access permission
hf auth login
Start the llama.cpp server
# Install llama.cpp:
brew install llama.cpp
# Start a local OpenAI-compatible server:
llama serve -hf facebook/MobileLLM-R2-2.5B-GGUF:
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:9931/v1
hermes config set model.default facebook/MobileLLM-R2-2.5B-GGUF:
Run Hermes
hermes
Quick Links

You need to agree to share your Hugging Face information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this model content.

MobileLLM-R2 GGUF

GGUF files of MobileLLM-R2, the final instruct model, for llama.cpp.

MobileLLM-R2 is the latest 2.5B-parameter model in the MobileLLM family. Trained on 1.2T pre-training tokens and fewer than 2T tokens in total, it supports both long-horizon reasoning and multi-turn agentic tool use. The safetensors model is facebook/MobileLLM-R2-2.5B.

Which file to use

The smallest and fastest files are in dense/, 1.5 to 5.0 GB. On an Apple M4 Max laptop, Q4_K_M decodes 137 tokens/s at a 4K context (84 at 32K) and peaks at 3.0 GiB of memory at 32K with an 8-bit KV cache. They run on llama.cpp built with the small patch in that folder (build steps).

Each file is dense/MobileLLM-R2-dense-<quantization>.gguf:

Quantization Size (GB) Perplexity vs BF16
BF16 5.00 15.61 reference
Q8_0 2.67 15.64 +0.2%
Q6_K 2.09 15.64 +0.2%
Q5_K_M 1.87 15.76 +1.0%
Q4_K_M 1.67 16.17 +3.6%
IQ4_XS 1.54 16.37 +4.9%

Perplexity is measured with llama-perplexity on the full WikiText-2 test set at a 512-token context. The quantized files were made with an importance matrix computed on wikitext-2 train plus code, included as dense/MobileLLM-R2-dense.imatrix.gguf.

To run on llama.cpp as released (b11671 or later, the first release with the muse-spark architecture), use the files at the top of this repo, MobileLLM-R2-<quant>.gguf. They hold the same model in a layout that llama.cpp supports without the patch, at 21-25% more size and slower decoding (the files in dense/ decode 2.3x faster on CPU and 27% faster on a GPU).

Quick start

# llama.cpp built with the patch (steps below): chat in the terminal, or an OpenAI-compatible server with tool calling
./build/bin/llama-cli -m dense/MobileLLM-R2-dense-Q4_K_M.gguf --jinja
./build/bin/llama-server -m dense/MobileLLM-R2-dense-Q4_K_M.gguf --jinja --swa-full -c 32768

# llama.cpp b11671 or later as released
llama-server -m MobileLLM-R2-Q4_K_M.gguf --jinja --swa-full -c 32768
  • Context: 32,768 tokens, the length the model was trained at.
  • Sampling: the files carry the recommended defaults (temperature 0.6, top-p 0.95, top-k 20); llama.cpp uses them unless you pass your own.
  • Stopping: each reply ends with <|eot|>. The model also emits <|eom|> to close a message inside a reply, for example between parallel tool calls; that token does not end the reply.
  • --swa-full: the files mark every layer as sliding-window with a 131,072-token window, so that llama.cpp applies RoPE on every layer as the model expects. Attention still covers the whole context. We tested llama-server with --swa-full.

Tool calling

llama-server --jinja turns the model's tool calls into OpenAI tool_calls, streaming or not. We tested single calls, parallel calls, no-call answers, multi-turn conversations with tool results and typed arguments: 12 of 12 runs passed with BF16 and with Q4_K_M, both in dense/ and at the top of the repo.

In a reply without tool calls, llama-server --jinja returns the model's reasoning in reasoning_content and only the answer in content.

Agentic coding

MobileLLM-R2 learned agentic coding from traces recorded with the Terminus-2 agent, which reads a terminal screen and answers with JSON keystrokes. Use it in that harness.

Start the server with low reasoning strength, the setting the model's agentic and tool-calling training data used:

llama-server -m MobileLLM-R2-Q8_0.gguf --jinja --swa-full -c 32768 \
    --chat-template-kwargs '{"reasoning_strength": "low"}'

To serve several agents at once, add -np N and set -c to N ร— 32768.

Terminus-2

Harbor (pip install harbor, Python 3.12 or newer) ships Terminus-2 and runs each task in a Docker or Podman container:

export OPENAI_API_KEY=sk-no-key-required
harbor run -p <tasks> -a terminus-2 -m openai/mobilellm-r2 \
    --ak api_base=http://127.0.0.1:8080/v1 \
    --ak 'model_info={"max_input_tokens": 29696, "max_output_tokens": 3072, "input_cost_per_token": 0, "output_cost_per_token": 0}' \
    --ak 'llm_call_kwargs={"max_tokens": 3072}' \
    --ak temperature=0.6 --ak max_turns=250 --ak parser_name=json \
    --ak enable_summarize=true --ak proactive_summarization_threshold=8000

<tasks> is a Harbor task or a directory of tasks (harbor init creates one, and harbor task migrate converts Terminal-Bench tasks). These are the settings the model was evaluated with: a 29,696-token input budget leaves room for a 3,072-token reply in the 32,768-token context, and Terminus-2 summarizes the history when fewer than 8,000 tokens remain.

Claude Code (demo)

Claude Code speaks the Anthropic Messages API, which llama-server also serves, so the model can run behind it. The model was not trained on Claude Code's tool format, and on its own it often answers with a plan instead of a tool call, which ends a non-interactive run. For the demo below, a small adapter between Claude Code and llama-server repaired those mechanical mistakes: a plan sent instead of a tool call, a tool call written as text, a stray \n after shell commands, and a context that outgrew 32,768 tokens. We provide this as a demo only; the adapter's code will be released along with our open-source code on GitHub. Anthropic does not support using Claude Code with models other than Claude.

Demo: replays of solved SWE-bench tasks

We ran both harnesses on tasks from a 100-task sample of SWE-bench Verified, with MobileLLM-R2-Q8_0.gguf on llama.cpp and each task in a container without network access. demo/swe_replay.html (open it in a browser; it works offline) replays runs whose fix passed the task's SWE-bench tests: the model's plan, the commands it ran, what the terminal showed, the final diff and the test verdict. In the Claude Code runs, steps the adapter repaired are labeled. python3 demo/replay.py demo/records/<file>.json replays one run in a terminal.

Replay: MobileLLM-R2 Q8_0 fixing django__django-13410 in Terminus-2

Replay: MobileLLM-R2 Q8_0 fixing django__django-11066 in Claude Code

Build llama.cpp with the patch

llama.cpp's muse-spark architecture has no plain feed-forward layer, so the files at the top of this repo store each feed-forward layer as a single expert between two identity projections, which costs 0.27-0.54 GB per file and time on every token. The patch in dense/ adds a plain feed-forward path and a tied output head to muse-spark, about 25 lines of logic in src/models/muse-spark.cpp. llama.cpp without the patch cannot load the files in dense/.

git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
git checkout f64a49819ccbf67a710f9a1927080e25775651ef  # the commit the patch was made and tested against
git apply /path/to/dense/muse-spark-dense-ffn.patch
cmake -B build -DCMAKE_BUILD_TYPE=Release   # add -DGGML_CUDA=ON for NVIDIA GPUs
cmake --build build -j --target llama-cli llama-server
./build/bin/llama-server -m dense/MobileLLM-R2-dense-Q4_K_M.gguf --jinja --swa-full -c 32768

How these files were made

The files were converted from the safetensors release with a converter written for this model; it maps the model onto llama.cpp's muse-spark architecture. Against the original model in PyTorch (fp32) on 30,690 wikitext-2 test tokens at a 2048-token context, the BF16 files score perplexity 13.7092 (dense/) and 13.7098 (top of the repo), against the original's 13.7071. The tokenizer produces the same token ids as the original on all 288,379 tokens of the WikiText-2 test text.

License

Released under the FAIR Noncommercial Research License; see LICENSE.

Downloads last month
36
GGUF
Model size
3B params
Architecture
muse-spark
Hardware compatibility
Log In to add your hardware

4-bit

5-bit

6-bit

8-bit

16-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for facebook/MobileLLM-R2-2.5B-GGUF

Quantized
(1)
this model

Collections including facebook/MobileLLM-R2-2.5B-GGUF