I’m on an m5 pro 48gb, i’m using qwen 3.8 27b on ollama and i think i’m missing a lot because i get some critical memory spikes sometimes while sing 125k context in Pi Harness if i remember right (haven’t spin out a session for a couple weeks now).
What quant, context size and server (MLX, llama.cpp, LM Studio, etc.) work well on a Mac with this much memory?
Right now, i’m thinking of this setup which is on oMLX running a DFlash2 version of Qwen 3.8 27b.
but i may change my mind if there is a better alternative.
Hmm… I’m not very familiar with Macs, so I did some digging:
Short answer for an M5 Pro with 48 GB
For Qwen3.8-27B with Pi Harness on an M5 Pro/48 GB, my first choice would be reliable 4-bit weights and a verified 32K–64K working context, using your existing Ollama setup as the reference. Then I would compare oMLX + DFlash2 on the same coding task. If 125K/128K is genuinely useful, keep it as a second target rather than abandoning it: the question is whether it fits with usable latency, reasonable memory pressure, and correct tool calls.
- Quant: Start with a maintained 4-bit weight build. Do not confuse weight quantization with KV-cache precision: 4-bit weights can still use full-precision KV. An 8-bit KV setting may save context memory if the specific backend actually supports it; GGUF and MLX quantization labels are not automatically equivalent.
- Context: Begin with 32K/64K actually served, then try 96K/125K/128K if useful. Model-card context, configured maximum, an accepted API request and effective retained agent history are different things.
- Server: Ollama first (least disruption), oMLX + DFlash2 next (strong decoding candidate), with llama.cpp/GGUF and LM Studio/Splash as alternative packages. Compare full Pi tasks, not just decode tok/s.
A close community oMLX result for M5 Pro/48 GB reports peaks of 23.2 GB at 32K, 28.5 GB at 64K and 39.5 GB at 128K, with 4-bit weights and 8-bit KV. It used oMLX 0.6.3rc2, and its published recipe lists max_context_window=71680 despite the 128K benchmark input. This shows experimental feasibility in a related stack, not that a normal Pi API request can safely use 128K on your Ollama installation.
I have not tested this on a Mac or reproduced your memory spike. The observations below come from published documentation, source code, issue discussions and other people’s measurements, so I would keep the exact cause of your earlier spike open.
An easy path before changing everything
- With the model loaded, run
ollama --versionandollama ps; note the model tag,PROCESSOR, and effectiveCONTEXT(Ollama context guide). Don’t infer these from an assumed default. - Was 125K the actual prompt/history, or only the configured ceiling? Compare Pi’s declared model window with the server’s effective window.
- Did memory rise on the first long prefill, after repeated Pi/tool turns, or only with overlapping requests? These point to different mechanisms.
On macOS, watch Memory Pressure and Swap Used, not just a peak process number (Apple’s Activity Monitor guide). A brief allocation, a retained cache that plateaus and sustained system-wide swapping are different outcomes.
My decision map would be roughly:
Was ~125K the configured ceiling, rather than the actual prompt size?
Yes: align Pi's model context declaration with the server's real limit.
Check accepted request size before diagnosing a 125K prefill.
No: did memory jump on the first long request?
Yes: investigate active KV, prefill peak, and headroom/swap.
No: did it grow after many Pi turns or simultaneous requests?
Yes: investigate retained prefixes, agent history,
compaction, cache lifecycle, and concurrency.
No: check exact version, model build, and reproducibility.
After that, compare one alternative server with the same actual task.
1. Choosing weight quantization, KV precision, and useful context
Start by separating the two kinds of quantization
The word “quant” gets used for more than one object. Weight quantization changes the representation of the model’s parameters: a 4-bit model generally costs much less to keep loaded than unquantized bf16 weights. KV-cache quantization changes the storage format of attention keys and values created while processing prompts and generating text. A 4-bit weight build can still have a bf16 KV cache; equally, a backend may support 8-bit or 4-bit KV on top of some weight format. A draft model used for speculative decoding can be a third memory consumer.
For 48 GB unified memory, a maintained 4-bit conversion is the sensible first trial. Quantization quality is particularly important for a coding agent: tool-call schemas, correct file edits, and recovery after mistakes count more than plausible text alone. More aggressive 2/3-bit weights may be worth exploring later, but saving memory at the expense of reliable tool execution can lose time overall.
I would not assume that “Q4” in a GGUF name, “4bit” on an MLX repository, and a particular Ollama tag mean mathematically identical quantizers. They can differ in group size, outlier handling, tensor exemptions, conversion version and the underlying runner. Two builds labeled 4-bit can have different disk sizes, runtime allocations and quality. For a fair comparison, keep the exact model artifact or at least record the precise tag/revision. If a comparison switches model format and inference engine at the same time, the result belongs to the combination, not to one magic property of MLX or GGUF.
KV-cache compression is a separate and version-sensitive choice
Ollama’s upstream configuration reference documents OLLAMA_KV_CACHE_TYPE (f16, q8_0, q4_0) with Flash Attention. However, the availability and effect of those generic settings depend on the version and actual runner; historical MLX paths did not necessarily honor every documented cache knob. I would not prescribe q8_0 as an assured fix without checking that your Qwen backend uses it.
oMLX provides its own cache formats, including affine/TurboQuant choices on supported paths. Do not translate an Ollama q8_0 flag directly into an oMLX setting. Test memory and quality under the specific release, since low-precision cache, kernels and cache reuse can interact.
For an agent, the practical quality checks are retrieval of a fact near the beginning of a long history, consistent tool arguments, and a successful multi-step edit. Smaller cache formats can save memory without preserving every long-context task equally well.
Why 32K and 64K are starting points, not hard ceilings
32K/64K are starting points, not architectural ceilings. At 32K there is more headroom for prefill, tools and macOS. At 64K, many coding sessions can preserve substantially more context; if memory pressure and Swap remain comfortable, increase only when the task really benefits. A claimed 128K ceiling does not by itself mean 128K of useful input fits: leave room for system/tool messages and output tokens.
Four distinct things people may mean by “128K”
- Model capability (Qwen’s published maximum).
- Server admission/allocation (
CONTEXT, model settings). - Actual prompt tokens sent on a particular request.
- Useful Pi history remaining after tool output and compaction.
The second and third need checking on the exact Pi-to-server route; the fourth is about task quality, not merely token count.
Decision rule: If a 64K real task is stable and satisfactory, keep it. If it fails because facts or tool outputs are regularly dropped too early, extend the window cautiously. If the 125K attempt causes persistent swap or much worse latency, return to the smaller window while checking whether cache precision or server behavior can improve the larger run. None of these choices requires assuming your original spike was a bug.
2. Which server would I compare, and why?
Ollama: useful as a reference even if you later switch
Because Ollama is what you have, the first question is not “Which alternative should I install?” but “Can the existing server be made predictable enough to use as a baseline?” If it can, you can compare the result with any new runtime on the same Pi task rather than comparing someone else’s benchmark with your own anecdote. If it cannot, an alternative engine becomes a sensible way to distinguish a server-specific effect from a model-size or workflow limit.
Ollama’s own docs illustrate why checking the live value matters: the upstream configuration reference describes a 4096-token default, while the dedicated context page lists memory-dependent defaults and shows a CONTEXT column in ollama ps. Rather than choose a default from the docs, inspect the loaded model and actual request route.
oMLX + DFlash2: a serious candidate, but test the right outcome
Your proposed oMLX + DFlash2 is a serious alternative. The Qwen3.8 DFlash2 draft is designed to propose token blocks that the target verifies. When acceptance is good this can accelerate decoding; the draft also adds state and has its own compatibility requirements.
Evaluate three separate outcomes: (a) cold-prefill memory peak/pressure, (b) generation speed, and (c) a complete Pi tool cycle. DFlash principally targets (b), not automatically (a). A memory improvement may instead come from KV precision, quantized weights, a cache policy or a specific runtime fix; a decoding speedup can be offset by prefill or failed tool calls.
oMLX releases move quickly. 0.8.2 was current in this November 21 check; its release page identifies a hotfix inheriting changes from 0.8.1. Don’t import pre-integration DFlash cache flags or old recipes uncritically: the model settings code has distinct settings for context admission, caches and speculative decoding.
The published 128K benchmark’s max_context_window=71680 illustrates a key distinction: a direct benchmark input and a normal API chat admission limit need not be identical. Before comparing Pi performance, check that the server actually accepts the requested context through the endpoint Pi uses; do not extrapolate a benchmark rung into an API guarantee.
llama.cpp / GGUF: a useful alternative implementation
A suitable llama.cpp build is worth keeping in the comparison set, especially if you want a GGUF-based server, explicit slot/context settings, or a different cache implementation. Different runner implementations can make a large difference for a hybrid architecture. That does not automatically mean the generic llama.cpp build is faster or more economical than oMLX on your chip; the exact model revision, quantization, build and flags matter.
LM Studio and Splash: convenience and another performance profile
LM Studio is a reasonable option if you prefer a GUI-driven local-model workflow and compatible API serving. Splash is another relevant inference implementation for this model family, and one published same-hardware comparison reports attractive throughput and memory figures in its specific configuration. Its README documents a splash pi helper, so it may be relatively easy to try with Pi after verifying the installed release. It is worth including in a comparison.
“LM Studio” does not name one invariant backend; versions and model routes matter. A reported MLX context-setting issue makes served-context verification worthwhile, but does not prove current LM Studio releases have the same problem. Similarly, a Splash result on one version is not a general ranking.
For Pi, the practical questions are decisive: does it accept the model you want, report usage/context correctly, preserve tool-call schemas and tool results, permit the window you configured, and stay responsive across a long sequence? A runtime that is much faster on a stand-alone completion but makes tool calling unreliable is not necessarily the better agent server. A runtime that is slightly slower but stable and easy to operate may be a better everyday choice. That judgment is yours, not something a benchmark can decide by itself.
I would compare the packages, not just their engine names
| Package | Main reason to try | Main condition to check |
|---|---|---|
| Current Ollama | Minimal migration; baseline | Effective context, Mac pressure, Pi tools |
| oMLX + DFlash2 | Apple Silicon options; speculative decode | Cold vs warm latency, KV settings, accepted window |
| llama.cpp/GGUF | Different cache implementation; portability | Exact model build and context/slot settings |
| LM Studio/Splash | GUI or another inference profile | Bundled runtime, context, Pi API/tool calls |
3. Why the memory numbers are unusual for Qwen3.8-27B
Qwen’s official model configuration has 64 layers: 16 full-attention and 48 Gated DeltaNet/linear-attention layers. Those are different state representations. Treating all 64 as ordinary token-indexed KV layers would overstate the conventional attention-cache calculation; treating the model as having no other long-session state would understate the runtime problem.
Here is a simple calculation, rather than a measurement. The official text config has four KV heads per full-attention layer, a 256-dimensional head and bf16 as a declared dtype. If all sixteen full-attention layers held conventional bf16 K and V for each token, the idealized storage would be:
16 full-attention layers * 2 (K and V) * 4 KV heads
* 256 values/head * 2 bytes/value
= 65,536 bytes per token (64 KiB per token)
32,768 tokens: 2.00 GiB of this attention K/V
65,536 tokens: 4.00 GiB
125,000 tokens: about 7.63 GiB
131,072 tokens: 8.00 GiB
This is illustrative arithmetic, not measured memory. It assumes conventional bf16 KV only in the 16 full-attention layers and excludes 4-bit model weights, recurrent state, preserved prefixes, cache metadata, temporary prefill allocations, any DFlash draft, MLX allocator overhead and macOS. Quantized KV, padding, batching and other implementations change real allocations; the figure is not a whole-process bound.
Five memory categories worth keeping apart
- Weights/draft/vision: the loaded baseline.
- Live context: K/V for full-attention layers plus recurrent/linear state.
- Prefill workspace: potentially large but transient buffers during a cold long request.
- Retained prefixes/snapshots: saved work for reuse; may occupy memory or disk after the reply.
- Allocator and macOS: unified memory also serves the OS and tools; Memory Pressure/Swap expose the practical cost.
What the Ollama MLX prefix-cache code suggests (and does not prove)
A pinned Ollama MLX prefix-cache snapshot has an 8 GiB budget for paged-out snapshots and eviction logic. That is not a cap on total server RAM or live KV. The separate recurrent-cache code shows why cache accounting cannot be reduced to conventional KV alone. It is a versioned code observation, not proof that your installation used this exact path.
A plateau can still be painful. Suppose the server is retaining caches by design, but the Mac starts compressing and swapping aggressively. The memory use may be “expected” from the server’s point of view and still produce a bad experience for the person using the machine. Conversely, a high but stable allocation with little memory pressure may be less urgent than a lower peak that repeatedly forces disk swap. The practical goal is to keep Pi usable.
Cold input, warm reuse and overlapping requests imply different experiments
If the problem occurs as the first long prompt arrives, I would prioritize prefill peak, active K/V and model/draft headroom. Lower KV precision or a smaller input may help; prefill kernels and runtime versions may also change the temporary allocation. If the problem occurs only after many Pi turns, retained prefixes, recurrent snapshots, compaction behavior and request lifetimes move higher in the ranking. If it occurs when two activities overlap, look at batching, concurrency and cache copying. These are related mechanisms, not mutually exclusive diagnoses.
4. Pi context metadata and automatic compaction are another boundary
There is an additional complication because your model is being used through Pi Harness rather than only through a one-shot server benchmark. The agent has its own model metadata, token accounting and history management. The server has its own context allocation and request-admission rules. The model architecture has its native capability. And there is the prompt that actually reaches inference. Those four limits can disagree without any single component being “broken.”
The inspected public Pi models documentation shows how a compatible Ollama/LM Studio-style endpoint can be configured in models.json. The compaction documentation describes automatic history summarization. In the inspected source, the relevant basic threshold is:
start considering compaction when:
contextTokens > contextWindow - reserveTokens
ordinary documented reserveTokens default: 16,384
ordinary documented keepRecentTokens default: 20,000
In the inspected public Pi source these are defaults (reserveTokens=16,384, keepRecentTokens=20,000), not observations of your local Pi. The first value is a reserve for the compaction trigger, not a statement that the agent always runs on 16K context. contextWindow is Pi’s declared window, which can differ from the server’s actual allocation.
For example, Pi at 262,144 but Ollama at 64K would let Pi plan around a larger budget than the server can handle. Pi at 32K but a server at 128K may cause earlier-than-needed summarization. These are hypothetical mismatches, not a diagnosis or proof of a memory spike: the actual symptom might be compaction timing, rejection, or an interrupted tool loop.
The simplest check is the selected model’s Pi context declaration versus the loaded model’s Ollama CONTEXT. If they differ materially, try aligning them to a comfortable served window such as 64K before troubleshooting deeper. That is preferable to editing lots of hidden knobs or manually forcing memory to a very high limit. If they already agree, that eliminates one common integration question and strengthens the case for looking at cache behavior or the exact prompt size.
Why this matters specifically for tools
A coding agent may place substantial output from read, grep, a shell command or a test log into the next model request. The user sees “the same conversation,” but from the server’s perspective the prompt can change considerably between turns. The sequence may alternate between very large inputs, short requests that share earlier prefixes, and summaries after a compaction. A single long-context benchmark doesn’t reproduce all of that. It measures an important piece of performance, but not the entire agent workflow.
Compaction introduces its own trade-off. Shorter retained history may reduce context cost and improve responsiveness, but a summary can omit details the model will later need for a correct edit. Keeping more verbatim history can improve continuity at the cost of memory and time. This is why I would not advise turning compaction off as a first response to a memory spike, or turning it up so aggressively that Pi loses the project state you need. A stable middle ground is often to configure a served window that is actually comfortable, align the agent’s declaration with it, and let the ordinary summarization mechanism do its intended job.
The same integration check applies if you move to oMLX, llama.cpp or LM Studio. A new server may advertise a much larger nominal limit, but Pi still needs correct model metadata and a compatible API. A successful curl request to a bare completion endpoint is encouraging; a successful Pi tool cycle including the expected schema and retained history is stronger evidence that the migration will help you day to day.
5. Nearby measurements, issues, and version-specific fixes
Closest published reference: M5 Pro, 48 GB, 4-bit Qwen3.8
The oMLX community result is unusually close to your hardware. The page reports Qwen3.8-27B-4bit on an M5 Pro with 48 GB, under oMLX 0.6.3rc2 and a DFlash/TurboQuant-KV-8-bit configuration. The recorded ladder is:
| Benchmark input | Reported peak memory | Reported prefill speed | Reported generation speed |
|---|---|---|---|
| 32K tokens | 23.2 GB | 389.0 tok/s | 41.9 tok/s |
| 64K tokens | 28.5 GB | 324.9 tok/s | 26.2 tok/s |
| 128K tokens | 39.5 GB | 229.4 tok/s | 20.8 tok/s |
The figures are community benchmark peaks, not macOS Swap measurements. In the same published settings max_context_window=71680 appears alongside the 128K test. Thus the run supports feasibility on that benchmark path, not automatic 128K acceptance by a normal Pi chat endpoint. Do not copy experimental memory-cap overrides from another M5 Pro recipe without understanding the machine-specific guard and risk.
A cross-engine comparison on the same hardware
The Garden Desk discussion includes an M5 Pro / 48-GB Qwen3.8-27B comparison of oMLX, oMLX + DFlash2, Splash and llama.cpp variants. It reports both very short prompts and prompts around 31K tokens. For example, an early 31K comparison gave oMLX at 27.3 GiB reported peak with bf16 KV, oMLX + DFlash2 at 25.4 GiB with bf16 KV, and Splash at 18.6 GiB with INT8 KV. The speed figures also differed substantially.
Ollama MLX cache behavior: similar symptom, not an established diagnosis
In Ollama issue #18131, an Apple Silicon user reported high swap during agent workloads and focused on the MLX prefix-cache budget. The issue is open at the time of this check. It involves a different Mac and agent setup, so the right takeaway is that cache retention can matter materially for whole-machine memory pressure, not that Pi on your M5 Pro necessarily hits the same code path or version-dependent behavior.
Ollama issue #17924 is a useful counterexample: a rising memory trace was initially called a leak, but later observations showed a prefix-cache plateau, and the diagnosis was corrected. That does not prove every cache increase is harmless; watch Swap and whether growth levels off, and keep the exact version/runner distinct.
oMLX has also had genuinely relevant multi-request memory fixes
PR #5253 addresses quantized KV rollback during batched speculative verification, and PR #5321 reduces extra KV copies when requests join or restore a batch. Both merged November 20, 2026. The relevant reports include long overlapping Qwen3.8 requests. They show how a steady-state estimate can miss temporary spikes; they do not diagnose a single Ollama prefill.
These are oMLX-specific concurrency/cache paths. Some comparisons came from a 64-GB machine with a 48-GB software memory guard, which is not equivalent to physically having 48 GB. If using a recent release, check whether those fixes are present; don’t claim that installing 0.8.2 alone fixes the poster’s earlier Ollama memory event.
The current release notes and source are also moving fast. The 0.8.2 release page identifies a small hotfix and carries forward 0.8.1 features; it should not be described as a release that uniquely invented every preceding November cache improvement. Verify the actual build you test, especially if following an August or September recipe, because cache setting names and DFlash integration have changed over time.
Similar but different: other Apple Silicon runners
For context, there are reports involving MLX-LM memory during long-lived serving, LM Studio’s MLX context setting, and hybrid-state cache behavior in llama.cpp. These are useful pointers if you decide to reproduce an issue on another implementation. They are not independent confirmation of one common bug in Ollama, oMLX, Pi and llama.cpp. Similar symptoms can arise from different layers: actual context allocation, cache retention, recurrent-state snapshots, temporary batch copying, or incorrect model metadata.
6. A small comparison that answers the practical question
The no-benchmark baseline
If you already have Ollama running, these commands are enough for an initial snapshot:
ollama --version
ollama ps
When the model is loaded, note the exact tag, effective CONTEXT, and whether it is being handled as expected under PROCESSOR. The Ollama guide shows an example of those columns. In Pi, note the selected model and its declared context if that information is readily visible. You do not need to dump private code, upload full conversation history, or run an expensive external benchmark just to answer the two basic questions.
Keep the comparison fair without making it a research project
For a useful comparison, hold the model checkpoint/weight precision, task and effective context as close as practical. Mark whether each request was cold (no reusable prefix) or warm (reuse possible). Otherwise an engine with a hot prefix may look much faster than one doing the same input from scratch.
Change one main variable at a time: server first for a package comparison; KV precision for memory; speculation for decode speed; or Pi’s declared context for an integration check. Pi tool-call correctness, retries and time to completion matter more than a single token-rate headline.
A compact note could look like this, with no need to fill every field:
| Setup | Actual input | Warm/cold | Memory Pressure / Swap Used | Result |
|---|---|---|---|---|
| Current Ollama, 4-bit, effective 64K | Representative Pi task | Cold | Observe, not estimated | Tool task completed? |
| Same setup | Comparable later tool turn | Warm/reused | Observe | Still responsive? |
| oMLX + DFlash2, comparable quant | Same task if convenient | Cold and then warm | Observe | Better total latency/quality? |
| Optional 125K/128K | Only if you need it | Stated clearly | Stop if pressure becomes severe | Actual request accepted and useful? |
Judge time to a correct result: cold prefill, first-token time, decode, tool schemas, retries, and whether the Mac stays responsive. The best raw decode benchmark need not win a coding-agent session.
The smallest observations with the highest diagnostic value
If you can only supply two things, the highest information value seems to be: (1) whether 125K was an actual input/history or only the configured limit, and (2) whether the memory spike happened on the first long prefill or after repeated Pi/tool calls. Those two facts distinguish several branches before any version-specific detective work. Memory Pressure and Swap observations would help but are not prerequisites.
If you later have an exact reproducer, an issue report becomes much easier to act on with the software version, exact model tag and runner, effective context, number of overlapping requests, input token count if known, and whether the symptom disappears when the model is unloaded. You need not share private prompts to do that; a synthetic public prompt with roughly the same length can be sufficient when it reproduces the same behavior. If a synthetic prompt does not reproduce the issue, that is also a useful clue about cache reuse or the actual agent sequence.
Things I would avoid as a first step
I would avoid raising Metal/wired-memory limits with sudo, disabling safety guards or blindly copying somebody else’s 128K recipe. Reserving OS headroom is safer than maximizing one GPU allocation at the cost of system-wide swap.
Also avoid treating a setting from a closed PR, another backend, or an older DFlash engine as active in the version you installed. Check the release’s docs and the actual runtime path. An ignored knob can make comparisons misleading.
A practical end state
A successful setup should load the selected 4-bit Qwen3.8 model, let Pi operate at a verified effective 32K or 64K context, complete the tool workflows you actually use, and avoid persistent memory pressure or debilitating swap. From there, it becomes an optimization problem rather than a troubleshooting emergency: increase real context if needed, test a supported KV-compression mode, and compare oMLX + DFlash2 against the reference on a representative workload. That preserves your original goal and leaves room to change your mind about the server.
Bottom line: I would not assume you need to give up Qwen3.8-27B, Pi, or the possibility of 125K. I would start with a known 4-bit build and a verified 32K/64K serving window on Ollama, then compare oMLX + DFlash2 under the same useful task. The nearby M5 Pro/48-GB results make a longer window plausible, but they also show how little headroom a 128K run may leave. If you remember only whether the 125K figure was an actual request and whether the spike was cold or after many Pi turns, that would already narrow the explanation a great deal; the options above do not depend on having those answers first.
Thank you for this informative reply, i really appreciate it.
any tips for running benchmarks on different servers/weight quantization/…
and what exact models do you recommend for my case ?
Well, I think the safest approach is to get everything working with a small model first, then move on to the larger model you actually want to use:
For your M5 Pro / 48 GB, I would separate two questions: (1) does the local server reliably work with Pi? and (2) which model, quantization, and server give you the best actual Pi experience? A small model is an inexpensive way to answer the first question; it is not intended as a replacement for Qwen3.8-27B.
My suggested path:
- Prove that the connection works: start with
qwen3.5:0.8bin Ollama. Check ordinary chat and one direct request to its local API. This confirms the basic installation, model loading, and HTTP path, not coding-agent capability. - Prove that a small Pi task works: use
qwen3.5:4b, then optionallyqwen3.5:9bif the task needs a stronger model. Try a harmless read-only task in a disposable folder. This checks model selection, tool-call formatting, tool responses, and the agent loop. A failure by an 0.8B/4B model to decide on the right tool is not automatically a server bug. - Move to your real target: keep the existing Ollama setup as a baseline, then compare a 4-bit Qwen3.8-27B on the runtime you want to use. Concrete options include this MLX 4-bit checkpoint and Unsloth’s GGUF collection (for example
UD-Q4_K_Mwith llama.cpp). Your oMLX + DFlash2 idea is still a reasonable candidate to compare against the working baseline, not something you need to rule out in advance. - Benchmark a real workflow, not just token generation: first compare short prompts, then a moderately long prompt, then one repeatable Pi task. Record latency, task success, and macOS Memory Pressure / Swap. Increase context only if it helps that task.
If you want the shortest practical shopping list, it is 0.8B for connectivity, 4B for the first agent test, optional 9B for a stronger sanity check, then your intended 27B. The 2B is available too, but I would not make four separate small-model tests a prerequisite.
A first pass could be as simple as:
ollama run qwen3.5:0.8b
ollama run qwen3.5:4b
ollama ps
ollama list shows locally installed models; ollama ps shows models that are currently loaded, with their effective context and processor placement. If the tiny model responds in Ollama, the next useful test is the same model via Ollama’s OpenAI-compatible endpoint, before involving Pi:
curl http://localhost:11434/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen3.5:0.8b",
"messages": [{"role": "user", "content": "Reply with the word READY."}],
"stream": false
}'
That request only tests basic text generation; it does not test tool calling. The endpoint format is documented in Ollama’s OpenAI compatibility guide.
Specific small models, MLX alternatives, and the actual 27B target
For the setup/smoke-test phase, I would stay with the same general model family to avoid introducing unnecessary variables:
| Purpose | Ollama model | Example MLX weights | Interpretation |
|---|---|---|---|
| Fast chat/API check | qwen3.5:0.8b |
Qwen3.5-0.8B-4bit | Can the server load and return text? |
| Optional intermediate step | qwen3.5:2b |
Qwen3.5-2B-4bit | Basic formatting / structured-response check |
| First Pi agent test | qwen3.5:4b |
Qwen3.5-4B-MLX-4bit | Can a short, safe tool-use loop complete? |
| Optional stronger small model | qwen3.5:9b |
Qwen3.5-9B-4bit | Does a stronger small model handle the same task? |
The Ollama identifiers are listed in the Qwen3.5 tags catalog. Those MLX links are candidate checkpoints, not a claim that each one works unchanged in every MLX-based server. Check your chosen server’s accepted model format and current supported architectures. Also, a model repository’s download size or advertised context window is not its peak unified-memory usage.
The difference in purpose matters:
- 0.8B: a passing text response says something useful about the connection; a failed coding-agent task says almost nothing about 27B performance.
- 4B: a more meaningful first trial of tool messages and the Pi loop, but still not a definitive measure of agent quality.
- 9B: worth trying if 4B can chat but makes unreliable decisions about simple tools. If 9B works with the same server settings, that is a useful clue that model capability played a role.
- 27B: the real test of quality, long context, memory headroom, and performance. Do not extrapolate its 125K behavior from the little models.
For the 27B phase, these are concrete starting points rather than an exhaustive ranking:
- MLX: mlx-community/Qwen3.8-27B-4bit. Verify the serving project’s required conversion, architecture support, and any separate DFlash2 draft model. A generic MLX 4-bit repository is not automatically a ready-made oMLX+DFlash2 bundle.
- GGUF: unsloth/Qwen3.8-27B-GGUF. Its model page documents
UD-Q4_K_Mfor a llama.cpp route; this gives you a precisely named starting quant, not proof that it is identical to an MLX 4-bit quant. - Ollama: keep the exact model/tag and version that already run on your machine as the control. Do not quietly swap the checkpoint while comparing servers.
A fair performance comparison ideally holds the underlying base model fixed. If one runtime needs GGUF and another needs MLX/oQ, you have changed format and quantizer as well as server. That is still an entirely useful whole-stack comparison; just do not describe the result as an isolated server speedup or an isolated quantization-quality result.
Pi connection: distinguish a working API from a working agent
Pi’s current models documentation shows how to connect Ollama or another compatible server through models.json. For example, the following is a configuration excerpt for an Ollama-served 4B model:
{
"providers": {
"ollama": {
"baseUrl": "http://localhost:11434/v1",
"api": "openai-completions",
"apiKey": "ollama",
"models": [{ "id": "qwen3.5:4b" }]
}
}
}
On Pi versions following those docs, this belongs in ~/.pi/agent/models.json; /model can then be used to select the entry. The ollama API key in the example is a dummy value for the local server, not a private credential. Since Pi is changing quickly, use the documentation matching your installed version if its configuration format differs. The Pi llama.cpp guide also describes a separate router-based local GGUF route.
For the very first agent test, I would create a disposable folder with a tiny README.md containing two or three unambiguous facts, and ask Pi something like “Read README.md and tell me which two features are listed; do not modify any files.” Keep it read-only, and avoid running commands in a real project until the tool flow is known to work.
There are several distinct possible results:
The model cannot load or a plain chat request fails
Check the checkpoint format, server/version, model name and logs.
The plain API request works but Pi cannot connect
Check Pi's configured endpoint, API type, model ID and model selection.
Pi connects but receives malformed tool messages
Check tool-call/schema compatibility and chat-template behavior.
Pi can call a tool but repeatedly chooses the wrong action
Try the same tiny task with 4B or 9B before declaring a server bug.
A safe read-only task works end to end
Keep that working configuration as the baseline for the 27B test.
I would keep this smoke test deliberately small. A few working requests are more informative than repeatedly changing servers, models, and quantizations at once.
A compact benchmark that can actually answer your server/quantization question
I would avoid a large matrix of servers multiplied by quantizations multiplied by context sizes on day one. A small sequence that changes one factor at a time where possible is easier to interpret:
- Baseline: use your currently working Ollama + 27B setup, with a known model tag, short input, one concurrent request, and a fixed output cap (say 256 tokens). Record a cold run and a warmed-up run separately.
- Server/format candidate: run the closest supported 27B build on oMLX, or on llama.cpp/GGUF. Keep the prompt, actual input length, output cap, approximate context limit, tool task, and concurrency the same. If model quantization differs, label it a whole-stack result.
- Quantization check: on the same server and base model, compare a second supported weight quant if you have a reason to; do not change KV precision and weight precision simultaneously if the goal is to identify their separate effects.
- Longer context: after 4K-8K works, try a representative 32K or 64K actual input and one repeatable multi-turn Pi workflow. Only run a 96K/125K case if it is relevant to what you actually do and the Mac has enough memory headroom.
A small log is enough:
| Record | Why it matters |
|---|---|
| Model repo, exact quant/tag, server and version | Makes comparisons reproducible |
| Actual input/output tokens, served context, concurrency | Prevents accidental context-size mismatches |
| Cold/warm status, KV precision, cache/DFlash options | Separates setup and acceleration effects |
| End-to-end wall time, time to first token, prefill/decode speed if available | Helps identify where time goes |
| Whether the Pi task succeeded and whether the output was correct | Agent usefulness matters more than tok/s alone |
| Peak and steady memory, Memory Pressure, Swap Used | Reveals whether the configuration is comfortable on 48 GB |
Two or three repeats of a short task, when convenient, are usually more useful than a single headline number; you can report the spread instead of pretending the measurements are exact. A benchmark result with a fast decode rate but bad prompt ingestion, failed tool calls, or heavy swapping might be worse for Pi than a slower-looking one.
For an apples-to-apples test, keep the prompt identical, start from a known session/cache state, avoid other substantial memory-consuming applications, note whether a model is already loaded, and compare the same successful task. If a server’s chat template, reasoning mode, sampling behavior, or tool format is different, record that too rather than treating the outputs as directly equivalent. Disable optional accelerators for an initial reference where practical, and measure DFlash2 separately if it is the feature you want to evaluate.
The target should be something like “Which setup completes my typical Pi coding task correctly and promptly without sustained memory pressure?”, rather than a universal winner in tokens per second.
How I would interpret the previous ~125K memory spike
I would keep this part separate from choosing a starter model, because we still do not know exactly what caused your earlier spike. The crucial first distinction is whether 125K was the configured maximum or the amount of prompt/history actually sent.
125K was a configured maximum, not a 125K input
Check the context actually served by Ollama and declared to Pi.
A large allocation may still be possible, but do not assume a 125K prefill occurred.
A single genuinely long request causes the spike
Check active attention/KV state, transient prefill memory,
weight and KV precision, and Memory Pressure / Swap.
Memory grows primarily after repeated Pi/tool turns
Check retained session/prefix caches, agent-history compaction,
unload behavior, and whether requests overlap.
Memory looks stable, but tasks become slow or fail
Check long-prompt processing, tool-call correctness, and swap;
low peak RAM is not the only success criterion.
The Ollama context guide explains context settings and how ollama ps reports the context of a loaded model. Pi also has its own context compaction mechanism, so the model’s advertised context, the server’s actual limit, and the window Pi believes it has should agree. On macOS, look at the Activity Monitor memory indicators, especially Memory Pressure and Swap Used, rather than treating a process memory peak as the whole story.
I mentioned this in more detail in my previous reply, so I would not try to diagnose it again from scratch here. One related M5 Pro / 48 GB community oMLX benchmark reports about 23.2 GB at 32K, 28.5 GB at 64K, and 39.5 GB at 128K for one 4-bit/8-bit-KV configuration. But it is from an older oMLX version, its recipe has a separately stated max_context_window, and a benchmark’s 128K input does not prove that an ordinary Pi request can be served at 128K with the same memory footprint. The figures are useful as a reference point, not as a guarantee for your system.
In other words, I would start with a real 32K-64K working window, then increase it if your task benefits and your 48 GB machine remains responsive. If the 125K workflow is important, keeping it as a specific second-stage goal makes sense.
Where I would put Ollama, oMLX/DFlash2, llama.cpp and LM Studio in the comparison
These are different useful routes, not a ranking I can establish without measurements on your Mac:
- Ollama: the control because it already runs for you. It provides a straightforward model catalog, local API, and context visibility. Start by establishing what the current setup does well, rather than replacing it before measuring.
- oMLX + DFlash2: worth comparing for Qwen3.8-27B decoding on Apple Silicon, particularly because you are already considering it. Confirm which base/draft checkpoint, acceleration settings, and API interface the installed release actually supports. A faster generation phase is not necessarily a faster entire agent task or a lower memory peak.
- llama.cpp / GGUF: useful if you want a named GGUF quantization, explicit context and cache controls, and an alternative local server. The Unsloth 27B GGUF page includes a runnable
UD-Q4_K_Mexample; Pi’s local-model guide documents the router option. - LM Studio: useful if its model management and local-server workflow appeal to you. Still verify the selected backend, quantization format, exposed context length and tool-call behavior, rather than assuming every MLX/GGUF path is interchangeable.
The fastest comparison is probably your working Ollama 27B configuration versus one carefully configured oMLX+DFlash2 27B configuration, on the same short and then longer Pi task. Add llama.cpp/GGUF if you want to compare quant families or need a second server. There is no need to install all four options just to choose a first working setup.
I also would not begin by raising macOS/Metal memory ceilings. Establish a stable baseline and watch swapping first; memory-limit overrides make results harder to interpret and can leave too little headroom for the rest of the system.
If you end up with even a tiny set of results, the most useful details to share would be the exact model/quant, server version, effective context, whether Pi completed one real task, and roughly how latency and Memory Pressure/Swap behaved. That would give others a reproducible starting point without asking you to run an elaborate benchmark suite.
The key distinction is that small models establish a known-good pipeline; the 27B runs decide which setup is actually worth using. I have not tested these combinations on a Mac myself, so I would treat the model listings and community measurements as starting points to verify on your machine, rather than performance promises.
my setup is working fine but its just too heavy on the memory, thats what i’m trying to figure out.
for the models and quants i was asking about, i meant variants of qwen 3.8 27b because there are different quants from various organizations
Ah, I see what you meant! Hmm… my hunch is that long contexts or accumulated conversation history may be contributing more than the quantization scheme or file size of the weights, though…
:
You’re right: I went in the wrong direction with the smaller-model suggestion. Your Pi/Ollama setup already works, and you were asking which organizations’ quantized versions of the same Qwen3.8-27B are worth trying, especially because the model is heavy on a 48 GB M5 Pro. That is a much more useful comparison to make here.
The Qwen3.8-27B quantizations I’d actually put on the shortlist
For your existing Ollama setup, I’d start with GGUF because it lets you compare Q3 and Q4 while retaining Qwen3.8-27B. Keep whatever you currently have as the baseline, rather than treating a new download as a compulsory replacement.
| Checkpoint / distribution | Published file or catalog size | What I would use it for |
|---|---|---|
Ollama qwen3.8 / qwen3.8:27b |
Approximately 18 GB in the catalog | Your existing control, after identifying the exact tag/digest and whether it is using an MLX or GGUF runner. Do not assume this catalog entry uses the same quantizer as the GGUFs below. |
Unsloth Qwen3.8-27B-UD-Q4_K_M.gguf |
16.6 GB | My practical Q4 GGUF reference: check whether normal Pi coding quality is acceptable at a moderate weight size. |
Unsloth Qwen3.8-27B-UD-Q3_K_XL.gguf |
13.1 GB | A meaningful reduction in weight storage if Q4 leaves too little headroom; check tool calls and longer tasks rather than assuming quality is unchanged. |
Unsloth Qwen3.8-27B-UD-Q5_K_M.gguf |
19.9 GB | Optional higher-size quality control, not a memory-saving recommendation. |
The Unsloth repository also documents direct use through Ollama, for example:
ollama run hf.co/unsloth/Qwen3.8-27B-GGUF:UD-Q4_K_M
And, for a lower-weight comparison:
ollama run hf.co/unsloth/Qwen3.8-27B-GGUF:UD-Q3_K_XL
If you’re open to an MLX / oMLX comparison, there’s a genuinely different family of 27B quantized checkpoints to consider:
| Checkpoint | Published package size / characterization | Why I would consider it |
|---|---|---|
MLX Community Qwen3.8-27B-4bit |
Around 16.1 GB, standard MLX 4-bit | A recognizable MLX reference; useful to separate normal MLX loading from specialized oQ quantization. |
Jundot Qwen3.8-27B-oQ3e-mtp |
About 14.36 GB for the language, vision and MTP package on its current model card | A smaller mixed-precision oQ candidate. It is not literally uniform three-bit precision throughout the network. |
Jundot Qwen3.8-27B-oQ3.5e-mtp |
About 14.92 GB including those components | Intermediate oQ option when oQ3e is a little too aggressive. |
Jundot Qwen3.8-27B-oQ4e-mtp |
About 17.5 GB in the current model listing | A less aggressively compressed oQ candidate with relevant published M5 Pro benchmarks. Not necessarily the smallest weights in this group. |
- Want to remain on Ollama and preserve the current workflow? Keep your existing tag as a baseline; try Unsloth Q4_K_M, then Q3_K_XL if Q4 still feels too close to swap. This answers the original question about third-party 27B quantized weights.
- Want to test a server that can directly manage KV precision and long-session caching on Apple Silicon? Try oMLX with an explicitly compatible oQ4e or oQ3.5e checkpoint and supported KV-compression settings, as an alternative whole stack. I would not describe a win there as proof that the weight quantizer alone caused it.
Why my suspicion still falls on context and cache behavior
For a long Pi session, memory is not just the downloaded checkpoint. It includes weights, active full-attention KV, linear-attention/recurrent state, retained prefixes, prefill/allocator workspace, and whatever else is running on macOS. These components react to different controls.
Qwen3.8-27B is an especially good reason to distinguish these. Its published configuration describes 64 language blocks with a full-attention interval of four, meaning 16 full-attention blocks and 48 linear-attention / Gated DeltaNet blocks. So it would be misleading to estimate its attention cache as if all 64 layers were conventional full attention.
At 125,000 actually cached tokens, the idealized full-attention KV alone is 16 layers x 2 (K,V) x 4 KV heads x 256 values x 2 bytes x 125,000 = 8,192,000,000 bytes, or about 7.63 GiB in bf16. That is a calculation, not a measurement of your Mac, and it excludes recurrent state, snapshots, workspace and weights.
The distinction suggests a practical strategy: compare the weights when the baseline memory floor is too high; compare context and cache controls when the slope or peak is the problem. Both changes may be needed, but we can tell what each one accomplished instead of mixing every option at once.
A very low-cost first observation is simply:
ollama ps
Look at the loaded NAME, PROCESSOR, CONTEXT and residency. The Ollama context-length guide shows these fields and notes that a larger context can require more memory. CONTEXT is the allocated/served window, not a direct readout of how many real prompt tokens were sent. The other important macOS signals are Memory Pressure and Swap Used in Activity Monitor, not merely the disk download size or a single process’s memory figure.
1. How I would compare the 27B quants without changing too many things at once
Start with the same model, not the same nominal bit count
To isolate weight quantization, keep the same GGUF-capable runtime, actual prompt, context, sampling, chat template and tool schema; compare Unsloth UD-Q4_K_M with UD-Q3_K_XL. For a server comparison, keep the exact same GGUF file and vary only Ollama versus direct llama.cpp where feasible. An MLX/oQ-to-GGUF result is a valid whole-stack comparison, not proof that its weight quantizer alone won.
When selecting a published weight file, I would record its exact repository, filename and revision/hash rather than writing down only “Q4.” That becomes especially important after a maintainer re-quantizes the same model at the same URL. The Qwen model ID is the anchor, but the byte-level artifact is what the server actually executes.
What Q3, Q4 and Q5 tell you, and what they don’t
- Unsloth Q4_K_M: the sensible default control when tool reliability and coding quality matter and the machine can accommodate it.
- Unsloth Q3_K_XL: the direct answer to “can I get a smaller 27B?” Worth testing if Q4 approaches memory pressure. It is not automatically a worse user outcome if the Q4 run swaps badly; a small quality tradeoff could be justified by much better responsiveness and stability.
- Unsloth Q5_K_M: only worth the extra memory when it answers a quality question or when the context/cache budget has already been addressed. A bigger weight file is not a memory-pressure treatment.
- Very low-bit GGUFs: possible technical fallbacks for an otherwise infeasible workload, but they introduce a larger uncertainty about long reasoning, structured tool calls and code edits. I’d reserve them for a targeted experiment rather than recommending them as the first fix.
Keep the comparison’s unit of analysis clear
There are at least three distinct questions one might call a “server comparison”:
| Question | Change | What a result could actually mean |
|---|---|---|
| Is Q3 lighter than Q4 at acceptable quality? | Change GGUF weight file under the same runtime | Mostly a weight quantization/size tradeoff, plus any implementation differences in the quant formats. |
| Does Ollama handle this GGUF better than direct llama.cpp? | Keep the same GGUF file/revision, adjust the two servers to as-comparable-as-possible settings | A better approximation of server, cache, scheduler and integration differences. Still check templates, slots and served context. |
| Is oMLX + oQ/KV compression more practical than my current Ollama setup? | Change model package, backend and cache policy together | A legitimate whole-stack user-experience comparison, not proof that oQ alone is responsible. |
A small, task-based quality check
I would pick just one representative Pi task: perhaps navigate a small real repository, inspect two files, propose a narrowly specified fix, apply it, and run an existing test. Keep the same tools and same relevant context. Preserve the starting repository state between trials and do not give one quant the already-solved outcome. A useful comparison is whether it finishes successfully, how many attempts or unnecessary tool calls it makes, and how long the complete work takes.
runtime/version | exact weights/revision | actual input tokens
context/window | KV cache format (if known) | cold or warm
max memory/pressure | swap | prefill time | complete-task time
Pi task result | wrong/extra tool calls | notes
2. A decision tree for the memory spike: actual 125K input, repeated Pi turns, or parallel loads?
I wouldn’t assume a particular cause from “it was heavy at roughly 125K,” because that phrase can describe very different states of a local server. Here is the shortest useful diagnostic tree I can think of:
A. Was ~125K actually sent/processed, or was it the allowed maximum?
Actual, very long input:
Start with weights + live full-attention KV + recurrent state
+ prefill/temporary allocations. Check the peak within one request.
Maximum window setting only:
First establish the actual prompt length and served context.
Do not apply a 125K-token KV estimate to an unobserved request.
B. When does memory become troublesome?
On the first long request after a cold model load:
Prioritize live context, prefill workspace, and the weight floor.
After many Pi requests, tools, compactions or reused prefixes:
Prioritize prefix/session cache retention and lifecycle policies.
Look for growth followed by a plateau versus unbounded growth.
Mainly with several models, clients or parallel requests:
Prioritize combined allocations, scheduler admission,
per-request states, concurrent slots and cache duplication.
C. What happens after changing only the weight file?
Q3 lowers baseline and avoids swap, but long-prompt growth persists:
Both weights and context/cache matter; consider both controls.
Q3 barely changes system pressure:
Check that the new model/runner actually loaded and that
cache, context and other resident models were held constant.
Q3 damages a real task:
Retain Q4, improve cache/context policy or use another runtime.
D. What happens after a single clean unload and reload?
Memory resets and then grows across turns:
Stronger evidence for an intentional or unintended retained state.
Still not a leak diagnosis without version-specific investigation.
The same first long request always peaks similarly:
Stronger evidence for capacity and temporary workspace pressure.
Why a long single prompt can be expensive even without a leak
If a true 125K prompt arrives in a fresh session, the server must process it and maintain enough usable state for subsequent tokens. Qwen3.8’s hybrid layout reduces the conventional attention cache relative to a hypothetical 64-layer full-attention transformer, but it doesn’t make the entire inference process constant-memory. There are still 16 full-attention layers, Gated DeltaNet state, workspaces and runtime-specific buffers.
Why many short Pi turns can produce a different memory curve
There is a directly relevant neighboring report: Ollama issue #18131 describes a 32 GB Apple Silicon agent workload with MLX prefix-cache retention and heavy swap. The issue points to an approximately 8 GiB cache budget, rather than proving a leak. This is a useful reason to inspect cache lifetime if your memory climbs over many turns. But your machine has 48 GB, the model version and activity may differ, and the report does not establish your root cause. A related issue #17924 further illustrates why a cache plateau can be mistaken for monotonic leakage. Older issue #16698 describes memory accumulation on an older MLX runner; its historical resolution does not prove that a current build has or lacks the same bug.
Parallel or multi-model memory pressure is a third case
A particularly relevant different-machine example is Ollama issue #19417. It describes Qwen3.8-27B on an M5 Max with 128 GB, Ollama 0.40.13, and other resident models. The author reports that MLX memory scheduling booked roughly 16.9 GiB of weights while the overall context/cache demand was much larger. There is a proposed fix in PR #19419, but when checked on November 22, 2026, the PR was open, not a shipped fix one can simply assume is present. Because the hardware, concurrency and context differed, that issue is evidence for a possible scheduling mechanism, not evidence that your single-model 48 GB session has the same defect.
There is a separate, almost opposite kind of estimation problem in Ollama issue #19463: for hybrid GGUF models, the memory predictor may overestimate the KV cache by treating recurrent layers like full-attention layers, leading to unnecessary evictions. Its details and related PR #18866 are useful if the observed symptom is an unexpected unload or model churn. They should not be combined with #19417 into a claim that “Ollama always underestimates memory.” MLX and GGUF paths can fail in opposite directions.
A minimal cold/warm observation
If you already know that the spike happens after repeated Pi work, one simple controlled check is more informative than running seven models:
A minimal check is enough: note ollama ps, Memory Pressure and Swap; compare one fresh request with several normal Pi turns; then try a clean model unload and repeat one request. If only the warm series grows, investigate retained state. If the very first 125K input peaks, investigate live context and prefill. An unload is a diagnostic, not a request to discard caches after every turn.
A macOS measurement caution
“Memory used” can refer to several incompatible numbers: process resident size, memory allocated within MLX/Metal, cached allocator blocks, unified memory pressure, disk swap, and how much another app can still get without performance collapse. The best practical signal for whether 48 GB is enough is a combination of Memory Pressure, Swap Used, a successful real task and tolerable time-to-first-token/total time. A large cache that remains reclaimable and causes no pressure may be fine. A smaller resident footprint that produces sustained swap and minutes of delay is not fine.
3. Memory-saving options in order of effort and what each one actually changes
Option 1: Make the effective context budget intentional
| Actual task | Served window to try | Why |
|---|---|---|
| Normal edit or code-review session that fits well below 32K | 32K | A useful constrained baseline for memory and interactivity. |
| Multi-file agent task where 32K triggers premature compaction or truncation | 64K | Often a sensible intermediate budget. |
| Proven need to reason over a large uninterrupted input | 128K (or the task’s actual requirement) | Keep the feature you want, then investigate KV precision and caching. |
These are trial points, not magic thresholds. The current Ollama guide even suggests at least 64K for demanding agent/coding uses, which is a reason not to tell every agent user that 32K is always enough. A large context can genuinely improve some tasks while reducing throughput and increasing memory; that tradeoff should be evaluated using the work you care about.
If Pi’s model metadata claims a 256K window while the server is actually configured for something smaller, the agent may carry a transcript longer than the backend can honor. If Pi believes it has much less context than the server, it may compact before necessary. The useful thing is not merely setting OLLAMA_CONTEXT_LENGTH but confirming the effective value after the model loads, then checking the client configuration as well. On a long-running system, settings in the app, environment, model manifest and client request may not all mean the same thing. Defaults have changed across releases.
Option 2: Reduce avoidable retained and concurrent state
If memory pressure appears after multiple requests, consider what is still resident. A locally convenient multi-model setup may keep a second model, an earlier session or a cached prefix around for faster reuse. That is a reasonable optimization until it causes swap.
Option 3: Quantize KV cache, if your exact backend supports it
This is distinct from choosing a Q3 or Q4 checkpoint. With a GGUF path, a sensible conservative comparison is default K/V cache precision versus q8_0, keeping weight quantization and real prompt fixed. The llama.cpp server documentation currently documents --cache-type-k and --cache-type-v, including q8_0 and more aggressive formats. A direct llama.cpp test might look like this, provided your specific model/build combination accepts the chosen formats:
# Illustration only: verify the flags with the installed llama.cpp build.
# Keep the same GGUF and prompt when comparing against the default.
llama-server \
--model /path/to/your-Qwen3.8-27B-Q4_K_M.gguf \
--ctx-size 65536 \
--cache-type-k q8_0 \
--cache-type-v q8_0
For Ollama there is an extra caveat: do not assume OLLAMA_KV_CACHE_TYPE controls the MLX backend merely because it exists for another path. An older Ollama MLX issue #16698 found a mismatch, and the surrounding implementation has changed over time. First establish whether your actual model is using MLX or a GGUF/llama.cpp runner, then verify the configuration in that specific version. If the setting is ignored, a “before/after q8” run isn’t an experiment at all.
Option 4: Try oMLX’s cache policy as a separate configuration
oMLX is interesting not merely because it loads MLX weights, but because it provides explicit cache management, including a hot in-RAM tier, a cold on-SSD tier, and optional lower-precision KV formats. Its project docs describe Affine4/Affine8, prefix sharing, model lifecycle controls, and a process-wide memory limit. Release 0.8.2 is the latest release checked during this research, but that does not mean all screenshots or older recipes use its semantics.
Option 5: Keep DFlash2 and MTP in the speed column until measured otherwise
DFlash2 and MTP can be valuable acceleration strategies. But generation acceleration and peak-RAM reduction are not synonyms. An acceleration path may need extra weights, draft/prediction state, temporary activations or a different caching scheme. The net effect depends on version, model and acceptance behavior. A faster run may also change how much time the system spends under pressure; that isn’t the same as lowering its peak allocation.
This matters particularly because oMLX’s own published benchmark recipes include switches for DFlash, MTP and KV compression. One should not summarize a result as “DFlash2 saves 11 GB” merely because a faster recipe happened to contain several features. In the relevant 128K M5 Pro result below, DFlash was disabled while TurboQuant KV4 and MTP were enabled. It would be incorrect to credit DFlash for its memory number.
Option 6: Change how information enters the context
If the necessary working set often approaches 125K, then the most effective memory improvement may be to avoid presenting everything as one contiguous, always-hot transcript. This is a separate design decision from changing the model. For example:
- Keep a durable short task specification and exact acceptance criteria, rather than having the agent infer them from fifty old tool turns.
- Use targeted retrieval from the repository or documentation for a subtask, then carry forward verified file paths, line references and failing test names.
- Keep large build logs and generated files on disk. Put only the important excerpts or summarized outcome into the model context, with a way to retrieve the complete original when needed.
- Split a large task into stages with stable artifacts and a clear handoff, while preserving the constraints the next stage must know.
- Use Pi compaction when useful, but review the result if a failure depends on an exact earlier observation rather than a broad summary.
What I would not start with
I would not recommend overriding macOS’s memory safety behavior, aggressively raising Metal wired-memory limits, disabling system memory protections, or installing an unreviewed patch as the first response to a working but memory-heavy model. Those are harder to interpret and potentially destabilizing. Nor would I treat an open GitHub PR as though a packaged version already includes it.
I also would not change Q3 weights, q4 KV cache, DFlash, MTP, context size and concurrency simultaneously. If the resulting run is good, it may be usable; but if it fails or is only marginally better, it’s difficult to identify which component to fix. A small controlled comparison followed by a practical whole-stack trial is a better balance of effort and information.
4. When I would stay on Ollama, switch backends, or consider a different model
| If your situation looks like this | The route I would consider | Why / tradeoff |
|---|---|---|
| Existing Pi + Ollama works and Q4 or Q3 GGUF leaves comfortable headroom | Stay on Ollama. | Least disruption. Keep the exact model tag and context behavior recorded so updates don’t silently change the baseline. |
| Current Ollama GGUF path still has cache pressure and you want explicit control over KV formats or slot policies | Try llama.cpp server with the same GGUF file | Cleaner comparison of some runtime controls; different setup, model template, session management and client integration may still affect results. |
| You want the 27B model with more explicit Apple-specific cache compression, retention and SSD-tier controls | Try oMLX plus a compatible MLX/oQ checkpoint | Changes the whole serving stack and often the weight format. Can be useful even if you can’t attribute the result to weights alone. |
| You want a GUI and selectable engines rather than a terminal-first setup | Try LM Studio, documenting its actual MLX/GGUF/Splash engine | Convenience may matter, but engine/version determines memory behavior. An LM Studio label is not a memory specification. |
| 27B’s required context still produces unacceptable pressure after sensible tuning | Change context workflow first; optionally compare another model architecture or size | Preserve the task goal. A model switch is an alternative, not a substitute for answering which Qwen3.8-27B quant is best. |
A note on a possible different-model fallback
You mentioned the desired Qwen3.8-27B variants, so I’d keep that at the center. Still, if 125K of actual live context is non-negotiable and even a good 27B quant plus cache controls makes the machine swap, then another model family or task organization becomes reasonable.
Other alternatives are not necessarily new weights at all: a retrieval-oriented coding workflow, periodically compacted tool results, an indexed source repository, or staged tasks with a narrow working set might preserve more quality than forcing an extremely small Qwen quant. If you have a true single-document 125K requirement, those tricks may be insufficient; then a direct long-context benchmark is the right evidence.
Don’t treat context architecture as a universal answer
Qwen3.8 is already a hybrid of Gated DeltaNet and full-attention blocks. Therefore recommending a “hybrid model” as though Qwen were dense full attention misses an important fact. But neither hybrid/linear attention nor sliding-window attention means the entire model has no context cost: recurrent state, attention layers, cache snapshots, prompt processing and runtime implementation still have to fit somewhere.
The goal is to retain your option to use Qwen3.8-27B. Switching backend or workflow is a way to make that possible, not a verdict that your target model is unsuitable.
5. What the public M5 Pro measurements and GitHub reports actually establish
There is a particularly useful community oMLX benchmark of Qwen3.8-27B-oQ4e-mtp on an M5 Pro with 48 GB. That makes it unusually close to your hardware. But the exact recipe matters more than a single headline number.
The page reports 128K context, 28.4 GB peak memory, approximately 316 prompt-processing tokens/s, and 22.5 generated tokens/s for its 128K test, using oMLX v0.7.2. The configuration includes TurboQuant 4-bit KV cache and Lightning MTP enabled, with DFlash disabled. It was recorded on October 22, 2026. These are the page’s reported benchmark measurements, not measurements I made on a Mac.
Two limitations are especially important:
- The benchmark used a named oQ4e checkpoint before the November 19, 2026 re-quantization shown on the current Jundot card. A new download is not guaranteed to be byte-for-byte the same model that produced the October measurement.
- The benchmark measures a particular prepared context and server recipe. It does not prove that a Pi Harness session with tool schemas, many turns, different cache retention, extra resident applications and a long history will have the same peak, throughput, or tool-call reliability.
The GitHub reports point to additional mechanisms:
| Public report | What it shows | Why it isn’t a diagnosis of your Mac |
|---|---|---|
| Ollama #18131 | A 32 GB Apple Silicon MLX agent workload saw heavy swap with retained prefix-cache memory. | Different hardware/memory tier, release, workload and cache lifecycle. |
| Ollama #19417 | An M5 Max, multiple-resident-model MLX workload had scheduler memory admission based too heavily on loaded weights; the report gives measured/predicted memory details. | Different 128 GB system, parallel residency and version. It could matter only if your scenario has corresponding conditions. |
| Ollama PR #19419 | Proposed change to memory pre-flight for MLX model loading. | Still open when checked on November 22; do not assume an official Ollama build contains it. |
| Ollama #19463 | GGUF hybrid-model KV memory can be overestimated, resulting in model eviction/churn. | A different runner and a different direction of the error; it does not explain every high memory reading. |
| Ollama #16698 and #17924 | Historical debate over retained MLX cache, release handling and plateaus versus leaks. | Older version-specific reports; not proof of an unresolved leak today. |
My practical recommendation, without turning this into a giant benchmarking project
model tag/digest (or HF repo + exact quant file/revision)
server version / actual runner
served context and whether ~125K was actual input
fresh long prompt vs repeated warm Pi session
macOS Memory Pressure and Swap Used
whether the Pi task completed correctly
- Q3 clearly fixes the pressure and Pi still does the work: keep it. There is no need to switch backends for its own sake.
- Q3 saves some baseline memory but the 125K spike remains: retain Q3 if its quality is fine, and separately address KV/context or retained prefix state.
- Q3 fails important coding/tool-use tasks: keep Q4 and look for context/cache savings or a backend that handles the same model more efficiently.
- Memory grows only with a warm session: focus on cache budget, compaction, idle lifetime and whether a cold reload changes the pattern.
- Ollama cannot provide a needed KV/cache control on the active path: try the corresponding supported path in llama.cpp or oMLX, with the change clearly labeled as a whole-stack trial.
- The required 125K workload is still unusable after that: consider a more selective retrieval/compaction workflow, or only then a different model family with a measured long-context memory and quality tradeoff.
My main point isn’t that the quantization choices are unimportant. They are worth comparing, and Q3 versus Q4 is exactly the right kind of comparison for your question. I just wouldn’t expect a difference of a few gigabytes in the weight file to explain every kind of memory growth in a long-context coding-agent session. Keeping the weight choice separate from live KV, retained session state and server behavior gives you a much better chance of finding a configuration that stays usable without giving up the 27B model you wanted.