Benchmarking llama.cpp and MLX with Qwen 3.8 27B on a 24 GB MacBook Pro, Part 2
Part 1 on inference speed and memory use
I used ten Python coding tasks from the Aider Polyglot benchmark to compare Qwen 3.8 27B in llama.cpp and MLX on a 24 GB M5 Pro MacBook Pro. The tasks included parsing Go game records, writing a small Forth interpreter and implementing spreadsheet-style updates between cells. For each task I gave the model the problem statement and a starter file and asked it to return the complete Python file. Across three runs per setup, with one retry per task, llama.cpp passed all the original Exercism unit tests in 19 of 30 cases and MLX in 16.
The score gap came from two tasks, so I'd want a wider test before choosing a setup for its answer quality. On this Mac I keep llama.cpp as my default for coding. Its requests took about an hour less in total, with most of the difference coming from scoring territory on a Go board, a task both setups missed. It also ran without a memory guard.
In Part 1, MLX generated about 10% more tokens per second at a fixed output length. Here the model could use as many tokens as it needed, up to a limit, and try again after seeing the test output. The total time depended on how much it generated and how often it needed a second attempt.
Scores and request times
Each exercise counted as solved if all its unit tests passed within two attempts. The unit-test totals use the last attempt for each case. The repository has the results and model answers for all six runs.
Metric | llama.cpp | MLX |
|---|---|---|
Solved | 19 of 30 | 16 of 30 |
Solved on first attempt | 10 | 7 |
Unit tests passed on last attempt | 511 of 681 | 430 of 681 |
Second attempts | 20 | 23 |
Total output tokens | 263,556 | 348,680 |
Output tokens per second (full request) | 15.55 | 16.67 |
Total request time | 282.40 min | 348.70 min |
Run 1 | 7 of 10 in 65.94 min | 6 of 10 in 111.29 min |
Run 2 | 6 of 10 in 114.75 min | 4 of 10 in 119.11 min |
Run 3 | 6 of 10 in 101.71 min | 6 of 10 in 118.31 min |
Request time on | 15.15 min | 58.71 min |
Request time excluding | 267.25 min | 289.99 min |
MLX produced about 7% more output tokens per second of request time and used about 32% more output tokens in all. It needed three more requests and averaged about 6,600 output tokens per request, compared with 5,300 for llama.cpp. Output includes reasoning as well as the visible answer. The client timer starts before the HTTP request and stops after the response stream, so these rates include prompt processing. The totals add up request times only. Part 1 measured generation from the first streamed token onward.
About two thirds of MLX's extra request time came from go-counting, which asks the model to write code that identifies each player's territory on a Go board. The tests import three constants absent from the starting file. On all three first attempts, MLX hit the 16,384-token limit before it returned code. Its retries were missing WHITE. The llama.cpp answers were missing WHITE on the first attempt and NONE on the second. The first run shows this in the saved MLX and llama.cpp answers.
Dropping that exercise leaves scores of 19 and 16 out of 27 and reduces the time difference from 23% to about 9%.
Results by coding task
The counts show how many of the three runs solved each task.
Task | What the code had to do | llama.cpp | MLX |
|---|---|---|---|
Score a ten-frame bowling game, including strikes and spares. | 3 | 3 | |
Count the moves needed to measure an exact volume using two buckets. | 3 | 3 | |
Reroot a tree at a chosen node and find paths between nodes. | 3 | 3 | |
Arrange dominoes in a closed chain with matching ends. | 3 | 3 | |
Rank poker hands and return every hand tied for best. | 2 | 2 | |
Parse a Smart Game Format string into a tree of nodes and properties. | 3 | 1 | |
Group books into discounted sets to minimize the basket price. | 2 | 1 | |
Implement a subset of Forth with stack operations, arithmetic and user-defined words. | 0 | 0 | |
Update dependent cells and call registered callbacks when computed values change. | 0 | 0 | |
Identify each player's territory on a Go board and the territory containing a given point. | 0 | 0 |
Each setup solved nine more cases on the second attempt. The difference in final scores came down to two extra solves for llama.cpp on sgf-parsing and one on book-store. In the first run, MLX passed 19 of 23 tests on sgf-parsing. Its second answer introduced an unbound variable in the code that compares two game trees, leaving only six tests passing. Both versions are in the saved MLX answer.
All ten exercises are public and may have appeared in training. The two setups also use different 4-bit weight conversions and different settings for the cache that retains context during generation. The results reflect those choices together with the runtime.
How I ran the test
I used the same Mac, weight files and launch settings as in Part 1. The overnight script started one server at a time and stopped it after ten tasks. I used temperature 0.6, top-p 0.95, top-k 20 and reasoning effort medium, with a limit of 16,384 output tokens per answer. The settings are in the request code and grader defaults.
The grader extracted the Python from the response and ran the unit tests. After a failed attempt, the script sent back the test output or explained why it could not use the answer.
I had planned one attempt per exercise. In the first pilot I left Qwen's reasoning effort at its default, xhigh. In 19 of the 20 requests the model used the full output budget without returning a code block. I switched to medium for the next pilot. It exposed a bug in my code extractor, which dropped an otherwise correct llama.cpp answer because the closing backticks were missing. The saved answer passes all 23 tests with the fixed extractor, bringing the pilot to three solves apiece.
The pilot also showed where test feedback helps. The book-store prompt quotes prices in dollars, and the unit tests expect cents. For the scored runs I kept my own grader and adopted Aider's two-attempt approach, so the model had a chance to act on those failures.
Running MLX on 24 GB
MLX completed all three runs with the memory settings from Part 1. The memory guard stayed active throughout and never stopped the server. macOS was already using roughly 9–10 GB of swap at the start of each session. The effect on request times is unknown.
I still keep MLX available for long prompts. With the roughly 3,100-token prompt in Part 1, it started streaming about two seconds sooner.