Tool

Run Gemma 4 26B inference on 8GB Apple Silicon Macs

TurboFieldfare runs the 26B-parameter Gemma 4 model in about 2GB of RAM on Apple Silicon by streaming MoE experts from SSD instead of loading them all.

Works with metalswifthuggingface

91
Spark score
out of 100
Updated 5 days ago
Version 0.2.1
Models
gemini 2 0llama 3

Add to Favorites

Why it matters

Enable developers to run a 26-billion-parameter language model locally on memory-constrained Apple Silicon Macs by streaming only the required model experts from disk, keeping total RAM usage around 2GB while maintaining usable inference speeds.

Outcomes

What it gets done

01

Stream and repack Gemma 4 26B-A4B model weights from Hugging Face into optimized .gturbo format

02

Execute token-by-token inference using Metal 4 GPU acceleration with expert streaming from SSD

03

Generate text completions through native Mac app, CLI, or OpenAI-compatible server interface

04

Manage 4-bit quantized weights and FP16 KV cache within strict memory budget constraints

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/drumih-turbo-fieldfare | bash

Overview

Turbo Fieldfare

TurboFieldfare is a custom Swift and Metal runtime that runs Google's Gemma 4 26B-A4B instruction-tuned model in about 2GB of RAM on Apple Silicon Macs, keeping only the shared core and KV cache resident while streaming mixture-of-experts weights from SSD per token, with a streaming installer, native Mac app, CLI, and local OpenAI-compatible server. Use it to run a genuinely large local LLM on memory-constrained Apple Silicon hardware, especially 8GB Macs; it's scoped to one pinned Gemma 4 checkpoint, text-only, macOS 26/Metal 4/Swift 6.2+ arm64 only, and only one TurboFieldfare process should run at a time.

What it does

TurboFieldfare runs Google's instruction-tuned Gemma 4 26B-A4B (26 billion total parameters, about 3.88B active per token) in roughly 2GB of RAM on any Apple Silicon Mac, including 8GB models, without loading the full 14.3GB model into memory. It keeps only the shared 1.35GB core and an FP16 KV cache resident, then streams the mixture-of-experts weights each token actually needs directly from SSD as they're required. It's a custom, model-specific Swift and Metal runtime rather than a wrapper around MLX or llama.cpp, and the project publishes a curated record of 102 measured experiments across kernels, caching, I/O, prefill, and decode that shaped the design.

Weights are quantized as MLX affine 4-bit (group 64) for shared and routed experts, with an 8-bit router. At each transformer layer, Metal computes attention and the router from resident weights; the CPU uses the router's top-8 expert IDs to plan against a 16-slot LFU expert cache, fills cache misses with bounded parallel pread calls into Metal-visible buffers, and Metal computes the resident shared-expert branch concurrently with those reads before combining shared and routed outputs. Prompt prefill processes chunks of up to 128 tokens so one fetched expert can serve multiple rows; generation repeats the routed-layer loop one token at a time. The model installer follows the same bounded-memory discipline: it streams required byte ranges directly from the pinned Hugging Face revision and repacks them into the .gturbo on-disk format as they arrive, never materializing a second full checkpoint on disk, and only accepts the roughly 14.3GB result after manifest and file-hash validation.

Measured decode throughput: 5.1-6.3 tok/s on an 8GB M2 MacBook Air, and 31-35 tok/s on a 24GB M5 Pro - the project is explicit these are reference points, not a performance ceiling, since prompt length, generated length, page-cache state, and hardware all affect real throughput, and it publishes a community benchmark guide for reporting results on other hardware. The system is currently text-only: the native app and CLI handle user/model messages and optional system guidance but expose no tool execution; the local OpenAI-compatible server does accept function-tool declarations and returns model-produced tool calls, but the client must authorize and execute them. Images, audio, and video are not supported.

When to use - and when NOT to

Use TurboFieldfare when you want to run a genuinely large (26B-parameter) instruction-tuned model locally on Apple Silicon hardware that couldn't otherwise fit it in memory - specifically 8GB Macs, where a naive full-model load simply isn't possible. It's a fit for local, private, on-device inference of this one pinned model checkpoint, whether through the native Mac app, the CLI for scripted or reproducible completions, or the loopback OpenAI-compatible server for integrating with existing tooling (the docs specifically cover Python and OpenCode setup).

It is scoped narrowly and deliberately: only the Gemma 4 26B-A4B instruction checkpoint is supported (not an arbitrary model), only text input and output (no images, audio, or video), and only Apple Silicon Macs on macOS 26 with Metal 4 and Swift 6.2+ (the package is arm64-only; older macOS or Metal versions aren't supported). Only one TurboFieldfare process (app, CLI, server, decode service, or test) should run at a time against a given model, since they share the same .gturbo directory and Metal ownership.

Inputs and outputs

Build and run the native Mac app:

git clone https://github.com/drumih/turbo-fieldfare.git
cd turbo-fieldfare
swift build -c release
.build/release/TurboFieldfareMac

Inside the app, choosing Download fetches and repacks the pinned model (~15GB transferred via bounded Hugging Face range requests); Load Model then loads it, and a typed prompt with Generate (or Command+Return) produces output, with a status bar showing decode speed and memory use. From the CLI, install the same model with TurboFieldfareRepack --output scratch/gemma4.gturbo (supports --resume and --verify-install), then run instruction chat via TurboFieldfareCLI --messages-file messages.json or raw completion via --prompt "...", with common options --max-context, --temperature, --top-k, --top-p, --repetition-penalty, --seed, and --stop. The local server (TurboFieldfareServer --model scratch/gemma4.gturbo) listens on http://127.0.0.1:8080/v1 with Chat Completions, streaming, function-tool support, and single-prefix prompt reuse - loopback only, with no remote authentication or TLS.

Output is generated text to stdout (CLI) or the app/server interface, with timing statistics to stderr for the CLI (suppressible with --quiet).

Integrations

TurboFieldfare integrates with Hugging Face to fetch the pinned Gemma 4 26B-A4B checkpoint via bounded range requests during installation, and with the OpenAI Chat Completions API surface through its local loopback server, making it usable from any OpenAI-client-compatible tool (the docs specifically cover Python clients and OpenCode). It's built entirely on Apple's native Metal 4 and Swift 6.2 toolchain with no dependency on MLX or llama.cpp as an inference backend, though it credits Maarten Grootendorst's visual guide to Gemma 4 as an architecture reference.

Who it's for

Developers and researchers on Apple Silicon Macs - especially memory-constrained 8GB models - who want to run a genuinely large, capable instruction-tuned LLM fully on-device, whether through a GUI app, a scriptable CLI, or a local OpenAI-compatible API server, without needing MLX, llama.cpp, or cloud inference. It is licensed under Apache-2.0.

Source README

TurboFieldfare logo: a fieldfare inside a segmented cache ring

TurboFieldfare

Gemma 4 26B-A4B inference in about 2 GB of RAM
A custom Swift + Metal runtime for any Apple Silicon Mac, even the 8 GB ones.

Swift 6.2 Metal 4 macOS 26 or later Apache 2.0 license

Quick start · Local server · Benchmarks · Contribute results · How it works · Experiments · References

Memory got expensive. So I gave a 26-billion-parameter model a ~2 GB budget.

TurboFieldfare runs the instruction-tuned
Gemma 4 26B-A4B
without loading the entire 14.3 GB model into memory. It keeps the shared
1.35 GB core and FP16 KV cache in memory, then streams only the experts needed
for each token from SSD. This is what lets the model run on Macs with 8 GB of
RAM.

The runtime, streaming installer, CLI, and native Mac app are written in Swift
and Metal. TurboFieldfare is model-specific rather than a wrapper around MLX or
llama.cpp. The curated experiment record
summarizes 102 measured results across kernels, caching, I/O, prefill, and
decode.

Try it

git clone https://github.com/drumih/turbo-fieldfare.git
cd turbo-fieldfare
swift build -c release
.build/release/TurboFieldfareMac

On the first run, Swift Package Manager downloads and builds the Swift packages
required by the tokenizer. The complete release build includes the foreground
Mac app and its sibling decode-service executable.

When the app opens, choose Download and let TurboFieldfare fetch and repack
the pinned model (about 15 GB). Once it is ready, choose Load Model, type
your prompt, and press Generate.

At a glance

Metric Value
Model Gemma 4 26B-A4B IT, 26B total parameters, about 3.88B active per token
Weights MLX affine 4-bit, group 64; 8-bit router; 4-bit shared and routed experts
Memory ~2 GB of weights and 4K KV cache
Storage About 14.3 GB for the installed text-only model
Hardware Apple Silicon Mac; 8 GB of RAM
Platform macOS 26, Metal 4, Swift 6.2
M2 measured decode 5.1-6.3 tok/s on an 8 GB M2 MacBook Air
M5 measured decode 31-35 tok/s on a 24 GB M5 Pro

The measured result is a reference point, not a performance ceiling. Prompt
length, generated length, page-cache state, and hardware all affect throughput.
To help measure another Apple Silicon Mac, follow the
community benchmark guide.

Using TurboFieldfare

TurboFieldfare provides a native Mac app, a command-line interface, and an
experimental loopback OpenAI-compatible server. They use the same .gturbo
model directory, but only one model-owning product should run at a time.

The Swift package exposes six products:

Product Purpose
TurboFieldfare Swift library containing the runtime and Metal kernels
TurboFieldfareMac Native Mac app for installation and generation
TurboFieldfareDecodeService One-shot local model and Metal owner used by the Mac app
TurboFieldfareCLI Command-line instruction chat and raw completion
TurboFieldfareServer Loopback OpenAI-compatible Chat Completions server
TurboFieldfareRepack Streaming model installer and install verifier

Requirements

  • An Apple Silicon Mac; the validated target is an 8 GB M2 MacBook Air
  • macOS 26 with Metal 4
  • Xcode 26 and Swift 6.2 or newer
  • Enough free storage for the ~14.3 GB model installation
  • An internet connection for the first model install

The package is arm64-only. Older macOS and Metal versions are not supported.

Prompting the model

The Mac app treats what you type as an instruction and handles Gemma's chat
formatting automatically. Just describe the task and include any context the
model needs.

Generation defaults to temperature 0.2, Top-K 64, and Top-P 0.95. Set
temperature to 0 for deterministic greedy output. The model can still repeat
itself or give incorrect answers, so check important results.

TurboFieldfare is text-only. The app and CLI support user and model messages
plus optional system guidance; they do not expose or execute tools. The
loopback server accepts function-tool declarations and returns
model-produced tool calls for the client to authorize and execute. Images,
audio, and video are not supported.

Mac app

Clone the repository, then run the app from its root:

swift build -c release
.build/release/TurboFieldfareMac

Build the complete package so the app and its sibling decode service are both
available. When launched from this checkout, the app stores the model in
scratch/gemma4.gturbo.

Install the model

On first launch, the app checks the available storage and shows the download
and installed sizes. Choose Download to begin.

The installer never materializes the full source checkpoint. It streams the
required byte ranges from the pinned Hugging Face revision and repacks them
directly into the .gturbo layout as they arrive. This avoids a second full
checkpoint on disk and keeps scratch memory bounded.

The first installation transfers about 15 GB through bounded Hugging Face
range requests. Network speed and Hugging Face response times vary, so it can
take a while. The completed .gturbo installation occupies about 14.3 GB and
is accepted only after its manifest and file hashes have been validated.
Installation does not load the model into memory.

Load and generate

After installation:

  1. Choose Load Model.
  2. Enter a prompt in the composer.
  3. Choose Generate, or press Command+Return.
  4. Use the stop button or Escape to end generation early.

The status bar shows generation progress, decode speed, and memory use. Use the
right pane to configure sampling, context length, expert-cache slots, and
runtime options. See Runtime controls for details
and defaults.

Command-line interface

The CLI uses an existing .gturbo installation. If you installed the model
through the Mac app, it is already available at scratch/gemma4.gturbo.
Otherwise, install it from the command line:

swift run -c release TurboFieldfareRepack \
  --output scratch/gemma4.gturbo \
  --overwrite

Continue a cancelled or interrupted download:

swift run -c release TurboFieldfareRepack \
  --output scratch/gemma4.gturbo \
  --overwrite \
  --resume

Remove saved download state:

swift run -c release TurboFieldfareRepack \
  --discard-partial \
  --output scratch/gemma4.gturbo

The runtime accepts only a completed .gturbo directory with a final
manifest.json.

Verify an existing installation without loading the model:

swift run -c release TurboFieldfareRepack \
  --verify-install \
  --input-gturbo scratch/gemma4.gturbo
Instruction chat

Put chat messages in a JSON array and pass it with --messages-file:

[
  {"role": "user", "content": "Explain why chunked prefill reduces time to first token while keeping memory bounded."}
]
swift run -c release TurboFieldfareCLI \
  --model scratch/gemma4.gturbo \
  --messages-file messages.json

This formats messages in the same way as the Mac app. The CLI response limit
is set with --max-new, which defaults to 1,024 tokens. The Mac app can
generate until the selected context window is full.

Raw completion

--prompt is available for raw completion and reproducible comparisons. It
passes the text directly to the model without chat formatting. Use
--messages-file for instruction-response conversations.

swift run -c release TurboFieldfareCLI \
  --model scratch/gemma4.gturbo \
  --prompt "The capital of France is" \
  --max-new 64 \
  --temperature 0

This example deliberately requests a short greedy completion.

Common generation options include --max-context, --temperature, --top-k,
--top-p, --repetition-penalty, --seed, and repeatable --stop strings.
The public CLI uses production runtime defaults. Run the following command for
the complete option list:

swift run -c release TurboFieldfareCLI --help

Generated text goes to standard output. Timing statistics go to standard error;
add --quiet to suppress that footer in scripts.

Local OpenAI-compatible server

Build the server and point it at an installed model:

swift build -c release --product TurboFieldfareServer
.build/release/TurboFieldfareServer \
  --model scratch/gemma4.gturbo

It listens on http://127.0.0.1:8080/v1 and supports Chat Completions,
streaming, function tools, and single-prefix prompt reuse. The client must
authorize and run every tool call. Keep the server on loopback; it has no
remote authentication or TLS.

See Local server for a test request, Python and
OpenCode setup, prompt reuse, tool handling, and the supported API subset.

Test and contribute

Run the public test suite serially:

Scripts/test.sh

Before starting a model run, close memory-heavy apps and check
memory_pressure -Q. If it reports little free memory, postpone the run. Run
only one TurboFieldfare app, decode service, CLI, server, test, or other
local-model process at a time.

To contribute a comparable performance result, follow the
community benchmark guide.

How the inference engine works

At each transformer layer, Metal computes attention and the router from
resident weights. The CPU uses the router's top-8 expert IDs to plan against
the layer's 16-slot LFU cache, then fills misses with bounded parallel pread
calls into Metal-visible buffers. Metal computes the resident shared-expert
branch while those reads run, then combines the shared and routed outputs.

Prompt prefill uses chunks of up to 128 tokens so one fetched expert can serve
multiple rows. Generation repeats the routed layer loop one token at a time.
The installer applies the same bounded-memory rule: it repacks remote ranges
directly into .gturbo without staging a full shard or tensor.

For a visual introduction to the model architecture, see Maarten Grootendorst's
A Visual Guide to Gemma 4.

System design explains the .gturbo layout, memory
ownership, prefill, router handoff, cb1/io/cb2 phases, Metal kernels, and
correctness invariants.

Status and scope

TurboFieldfare currently includes:

  • Remote streaming repack into the .gturbo model format
  • Instruction-tuned Gemma 4 26B-A4B with verified text-only chat formatting
  • 4-bit MLX affine embedding, attention, shared-expert, and routed-expert
    weights, with an 8-bit router
  • Custom Metal kernels for quantized GEMV, attention, MoE, normalization,
    RoPE, sampling, and production fusions
  • SSD-backed routed-expert streaming with a bounded expert cache
  • Chunked single-prompt prefill and token-by-token generation
  • FP16 KV storage with bounded circular storage for 25 sliding-window layers
    and linear storage for 5 full-attention layers
  • Exact split-K/V decode attention with distinct normalized K and V paths
  • A Swift library, streaming installer, command-line interface, loopback
    OpenAI-compatible server, and native SwiftUI/AppKit Mac app with a one-shot
    local decode service

Current scope is text-only inference from the pinned Gemma 4 26B-A4B
instruction checkpoint on Apple Silicon Macs with at least 8 GB of RAM.

Future work

  • Build iPhone and iPad apps, then measure inference speed and memory use on
    mobile hardware.
  • Benchmark more Apple Silicon Macs, especially the base 16 GB M4 Mac mini and
    other 8 GB models.

Experiments and technical documentation

The experiments that shaped TurboFieldfare
explain the largest wins, the plausible ideas that failed, and the early
results that reversed under stronger validation. The detailed
experiment record keeps all 102
audited entries as optional evidence.

Useful entry points:

Afterword and the project name

Thanks for checking out this project!

My name is Andrey Mikhaylov. You can find me on
LinkedIn.
I am the author of TurboFieldfare and an iOS and Metal engineer. Most of my
work is with images, video, and on-device AI.

I dedicate this project to my wife, Sasha, the most supportive person I know.
She stands by me even through the hardest times. She loves wildlife, goes
birdwatching, and volunteers with our local birding community. Because of her,
I have also grown closer to birds and nature.

TurboFieldfare is named after the fieldfare, a member of the thrush family and
my favourite bird. It is not the most noticeable or brightly coloured bird, but
it definitely has a character and unique features of its own. I think the same
is true of this project: it may not be the most practical, but I built it with
my favourite tools, especially Metal, in my favourite field, on-device ML
inference. It definitely has its own character and unique features.

Next time you are outside, touch the grass and listen to the birds. Sometimes
it is the most beautiful thing you can do. And if you can, support your local
wildlife community. They do important work.

Thank you!

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.