Local AI

← Back to notes & projects

256GB Mac Studio — Token Freedom

Running Qwen, GLM and DeepSeek Flash locally on a 256GB Mac Studio: prefill at 5k tokens/s and decode at 70 tokens/s.

Token Freedom cover

My Mac Studio arrived a couple of days ago. I installed the models I had been itching to try: Qwen 3.8 Flash, GLM 5.3 Flash, and DeepSeek V4.1 Flash 1017.

This machine has an M5 Ultra, a 30-core CPU, a 64-core GPU, and 256 GiB of unified memory. The inference service is oMLX 0.7.2.

They are usable now. Generation runs at around 60–130 tokens/s, with prefill at 1.5k–5k tokens/s.

The freedom of local deployment is having full control over my data, customizing parameters and weights, and experimenting with post-training and agents however I like. Saving on APIs or subscriptions comes a distant second.

I did work out the numbers, though. Running GLM Flash in 4-bit quantization for roughly 24 hours used 158.56M cached input tokens, 16.38M uncached input tokens, and 3.78M output tokens—an average of 43.7 output tokens per second. At API prices, that comes to about 60 yuan.

Here are the models and their memory use.

Models and memory use with a 256K context

The model directories total about 668 GB. Before switching models, I unload the previous one and then load the next, freeing memory for new requests.

Prefill and decode speed

Single-request prefill and decode speed

Prefill processes the prompt and previous material; decode generates the answer token by token. Sending a long document for the first time means waiting for input processing. Follow-up questions about the same material can reuse the prefix cache and avoid repeated computation.

Prefill directly affects time to first token (TTFT): how long after submitting input the first output token appears. In the worst case tested, with 256K input and no cache hits, the waits were:

  • Qwen27B: 347 seconds, about 5 minutes 47 seconds.
  • Qwen Flash: 53 seconds.
  • GLM Flash: 155 seconds, about 2 minutes 35 seconds.
  • DeepSeek1017: 192 seconds, about 3 minutes 12 seconds.

The cache can also be stored in memory or on disk. A cache hit saves the time spent processing the same material again.

Qwen 3.8 27B: concurrency

Qwen27B concurrency results

DFlash uses a smaller draft model to propose upcoming tokens, which the main model then verifies. This round of tuning also changed KV-cache access: each request maintains its own effective length, and the model reads historical states at each request's position. This reduces whole-cache moves during each rollback.

GLM 5.3 Flash: concurrency

GLM Flash concurrency results

GLM ran into a cache issue: reusing an established long prefix produced repeated output and retrieval failures. Changing the prefill chunk size from 4K to 1K resolved it.

DeepSeek V4.1 Flash 1017: concurrency

DeepSeek concurrency results

When tuning DeepSeek, CED was a major switch affecting input processing. With the same 30K input, enabling CED reduced the total request time from 34.31 seconds to 20.04 seconds. Most of the time saved came from input processing.

Qwen 3.8 Flash Next: concurrency

Qwen Flash concurrency results

Finally, what I learned and the problems I ran into:

  1. I learned what inference temperature means. At temperature 0, the model always chooses the highest-probability token; 1 uses the original probability distribution; values above 1 produce more varied output. For some reason, my default had been set to 0. Agent calls kept getting stuck in endless thinking loops, and it took a long debugging session to find the cause.

  2. Inference also involves MLX, thinking and output limits, matrix computation, and plenty of other details. For anything I do not understand, I can only hope it works. Once something goes wrong, progress tends to stop until I understand the concept involved.

  3. I noticed the effect of Codex's goal feature. Without a goal, its turn-by-turn responses feel like unmotivated dawdling. With a goal, it can endlessly expand unimportant parts and bury the central problem in more work. Both LLMs and agents still have a long way to go when it comes to identifying what matters most.

  4. I found the current GPT series heavily defensive. Various prompting approaches brought limited improvement: the wording changed, while the underlying issue remained. The central point still gets buried under a mass of detail.

Finally, the token count from a 24-hour run.

Token usage over 24 hours