GGUF
llama.cpp
conversational
mikezhaocs's picture
Demo replays from the public project page, since gated files do not load before access
ccb4a83 verified
|
Raw History Blame Contribute Delete
8.39 kB
---
license: fair-noncommercial-research-license
base_model: facebook/MobileLLM-R2-2.5B # the safetensors repository
library_name: gguf
tags:
- gguf
- llama.cpp
---
# MobileLLM-R2 GGUF
GGUF files of MobileLLM-R2, the final instruct model, for [llama.cpp](https://github.com/ggml-org/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](https://huggingface.co/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](#build-llamacpp-with-the-patch)).
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
```bash
# 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:
```bash
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](https://github.com/laude-institute/harbor) (`pip install harbor`, Python 3.12 or newer) ships Terminus-2 and runs each task in a Docker or Podman container:
```bash
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](https://huggingface.co/datasets/DCAgent2/swebench-verified-sample-100) 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](https://facebookresearch.github.io/MobileLLM/R2/static/images/terminus-django__django-13410.svg)
![Replay: MobileLLM-R2 Q8_0 fixing django__django-11066 in Claude Code](https://facebookresearch.github.io/MobileLLM/R2/static/images/claude-code-django__django-11066.svg)
## 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/`.
```bash
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](https://huggingface.co/facebook/MobileLLM-R2-2.5B-GGUF/blob/main/LICENSE).