Gemma 4 26B-A4B inference in ~2 GB of RAM on any M-series MacBook
Swift apple-silicongemmagemma4gemma4-26b-a4bgpgpullmllm-inferencelocal-aimacosmetalon-device-aion-device-llmswift
Polish Mac generation experience
Andrey Mikhaylov1b9127612861
diff --git a/AGENTS.md b/AGENTS.mdindex d053ba58..ed8d7c36 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -37,4 +37,4 @@ Report the commit, hardware and RAM, macOS, Swift version, exact command, exit c## App controls-The Mac app exposes generation controls plus cache slots, LFU/LRU, prefill, FP16 or K4/V4 KV, RDADVISE, and verification. Interactive generation defaults to 1,024 new tokens, temperature 0.1, Top-K 64, Top-P 0.95, and repetition penalty off at 1.0. Start with production defaults. The HUD reports rate, tokens, and decode-service memory; Last run adds TTFT and I/O. The app must be built with its sibling `TurboFieldfareDecodeService`; it never falls back to loading a second in-process model. See [README](README.md) and [Runtime controls](docs/RUNTIME_CONTROLS.md).+The Mac app exposes generation controls plus cache slots, LFU/LRU, prefill, FP16 or K4/V4 KV, RDADVISE, and verification. Interactive generation defaults to 1,024 new tokens, temperature 1.0, Top-K 64, Top-P 0.95, and repetition penalty off at 1.0. Start with production defaults. The HUD reports rate, tokens, and decode-service memory; Last run adds TTFT and I/O. The app must be built with its sibling `TurboFieldfareDecodeService`; it never falls back to loading a second in-process model. See [README](README.md) and [Runtime controls](docs/RUNTIME_CONTROLS.md).diff --git a/README.md b/README.mdindex b8ecbfcc..ae57c1ab 100644--- a/README.md+++ b/README.md@@ -118,7 +118,7 @@ The package is arm64-only. Older macOS and Metal versions are not supported.> capital of France is` or `Q: Why is the sky blue?\nA:`.The interactive default generates up to 1,024 new tokens with temperature-`0.1`, Top-K `64`, and Top-P `0.95`. The repetition penalty is off (`1.0`).+`1.0`, Top-K `64`, and Top-P `0.95`. The repetition penalty is off (`1.0`).Temperature `0` selects deterministic greedy decoding. The model may stillrepeat, loop, or produce incorrect text, so review its continuation.diff --git a/Sources/TurboFieldfareApp/Core/Inference/AppGenerationRequest.swift b/Sources/TurboFieldfareApp/Core/Inference/AppGenerationRequest.swiftindex 881d2a74..b56a4925 100644--- a/Sources/TurboFieldfareApp/Core/Inference/AppGenerationRequest.swift+++ b/Sources/TurboFieldfareApp/Core/Inference/AppGenerationRequest.swift@@ -15,7 +15,7 @@ public struct AppGenerationRequest: Equatable, Sendable {prompt: String,maxNewTokens: Int = 1_024,maxContextTokens: Int = 4096,- temperature: Float = 0.1,+ temperature: Float = 1.0,topK: Int? = 64,topP: Float? = 0.95,repetitionPenalty: Float = 1.0,diff --git a/Sources/TurboFieldfareApp/Core/Inference/DecodeServiceInferenceClient.swift b/Sources/TurboFieldfareApp/Core/Inference/DecodeServiceInferenceClient.swiftindex 39528465..ed7f10f2 100644--- a/Sources/TurboFieldfareApp/Core/Inference/DecodeServiceInferenceClient.swift+++ b/Sources/TurboFieldfareApp/Core/Inference/DecodeServiceInferenceClient.swift@@ -83,6 +83,7 @@ public final class DecodeServiceInferenceClient: AppModelLifecycleClient,var expectedSequence: UInt64 = 1var lastMetricYield = Date.distantPast+ var hasYieldedVisibleText = falsewhile true {let event = try DecodeFrameCodec.read(DecodeServiceEvent.self, from: handles.output)@@ -105,11 +106,15 @@ public final class DecodeServiceInferenceClient: AppModelLifecycleClient,if event.kind == .snapshot {generationTranscriptMailbox.append(event.textDelta)let now = Date()- if now.timeIntervalSince(lastMetricYield) >= 0.5 {+ let beginsVisibleText = !hasYieldedVisibleText+ && event.textDelta.contains { !$0.isWhitespace }+ if beginsVisibleText+ || now.timeIntervalSince(lastMetricYield) >= 0.5 {lastMetricYield = now+ hasYieldedVisibleText = hasYieldedVisibleText || beginsVisibleTextcontinuation.yield(.token(AppTokenEvent(index: max(0, event.tokenCount - 1),- textDelta: "",+ textDelta: beginsVisibleText ? event.textDelta : "",elapsedDecodeSeconds: event.decodeSeconds)))}continuediff --git a/Sources/TurboFieldfareApp/Core/State/AppModel.swift b/Sources/TurboFieldfareApp/Core/State/AppModel.swiftindex a3b5b295..99068600 100644--- a/Sources/TurboFieldfareApp/Core/State/AppModel.swift+++ b/Sources/TurboFieldfareApp/Core/State/AppModel.swift@@ -18,7 +18,7 @@ public final class AppModel {public var runtimeOptions = AppRuntimeOptions()public var maxNewTokens: Int = 1_024public var maxContextTokens: Int = 4096- public var temperature: Double = 0.1+ public var temperature: Double = 1.0public var topKEnabled: Bool = truepublic var topK: Int = 64public var topPEnabled: Bool = truediff --git a/Sources/TurboFieldfareApp/Mac/Components/GenerateControl.swift b/Sources/TurboFieldfareApp/Mac/Components/GenerateControl.swiftindex c25c1419..b096adc4 100644--- a/Sources/TurboFieldfareApp/Mac/Components/GenerateControl.swift+++ b/Sources/TurboFieldfareApp/Mac/Components/GenerateControl.swift@@ -35,41 +35,43 @@ struct GenerateControl: View {}private var runningPill: some View {- HStack(spacing: 10) {- if model.isCancellationPending {- Text("Stopping")- .font(.callout.weight(.medium))- } else if model.phase == .prefill {- Text(model.presentation.label)- .font(.callout.weight(.medium))- .monospacedDigit()- } else {- Text("\(MetricFormat.rate(model.liveTokensPerSecond)) tok/s")- .font(.callout.weight(.semibold))- .monospacedDigit()- }- Button {- model.cancel()- } label: {+ Button {+ model.cancel()+ } label: {+ HStack(spacing: 10) {+ if model.isCancellationPending {+ Text("Stopping")+ .font(.callout.weight(.medium))+ } else if model.phase == .prefill {+ Text(model.presentation.label)+ .font(.callout.weight(.medium))+ .monospacedDigit()+ .contentTransition(.numericText())+ } else {+ Text("\(MetricFormat.rate(model.liveTokensPerSecond)) tok/s")+ .font(.callout.weight(.semibold))+ .monospacedDigit()+ .contentTransition(.numericText())+ }Label("Stop generation", systemImage: "stop.fill").labelStyle(.iconOnly).font(.callout).frame(width: 28, height: 28)- .contentShape(Circle())}- .buttonStyle(.plain)- .keyboardShortcut(.cancelAction)- .disabled(!model.canCancel)- .help("Stop generation")+ .padding(.leading, 18)+ .padding(.trailing, 4)+ .frame(minWidth: 140, minHeight: controlHeight)+ .contentShape(Capsule())}- .padding(.leading, 18)- .padding(.trailing, 4)- .frame(minWidth: 140, minHeight: controlHeight)- .contentShape(Capsule())+ .buttonStyle(.plain).foregroundStyle(.white).background(.indigo, in: .capsule).overlay {Capsule().stroke(.white.opacity(0.16), lineWidth: 0.5)}+ .keyboardShortcut(.cancelAction)+ .disabled(!model.canCancel)+ .help("Stop generation")+ .animation(.smooth(duration: 0.2), value: model.presentation.label)}}diff --git a/Sources/TurboFieldfareApp/Mac/Diagnostics/InspectorView.swift b/Sources/TurboFieldfareApp/Mac/Diagnostics/InspectorView.swiftindex 8379dac2..64eeaec2 100644--- a/Sources/TurboFieldfareApp/Mac/Diagnostics/InspectorView.swift+++ b/Sources/TurboFieldfareApp/Mac/Diagnostics/InspectorView.swift@@ -127,7 +127,7 @@ struct InspectorView: View {}}}- Text("Defaults: 1,024 tokens, temperature 0.10, Top-K 64, Top-P 0.95. Repetition penalty is off.")+ Text("Defaults: 1,024 tokens, temperature 1.00, Top-K 64, Top-P 0.95. Repetition penalty is off.").font(.caption).foregroundStyle(.secondary)}diff --git a/Sources/TurboFieldfareApp/Mac/Diagnostics/RunnerDiagnosticsSection.swift b/Sources/TurboFieldfareApp/Mac/Diagnostics/RunnerDiagnosticsSection.swiftindex a0404926..08945a96 100644--- a/Sources/TurboFieldfareApp/Mac/Diagnostics/RunnerDiagnosticsSection.swift+++ b/Sources/TurboFieldfareApp/Mac/Diagnostics/RunnerDiagnosticsSection.swift@@ -15,7 +15,9 @@ struct RunnerDiagnosticsSection: View {groupLabel("Performance")DiagnosticRow("Prompt prefill", MetricFormat.seconds(diagnostics.prefillSeconds))+ DiagnosticRow("First token wait", MetricFormat.seconds(diagnostics.timeToFirstTokenSeconds))DiagnosticRow("Request TTFT", MetricFormat.seconds(diagnostics.requestStartTimeToFirstTokenSeconds))+ DiagnosticRow("Decode duration", MetricFormat.seconds(diagnostics.decodeSeconds))DiagnosticRow("Decode rate", "\(MetricFormat.rate(diagnostics.tokensPerSecond)) tok/s")DiagnosticRow("Peak memory", MetricFormat.memory(diagnostics.peakMemoryBytes))DiagnosticRow("I/O / token",diff --git a/Sources/TurboFieldfareApp/Mac/Diagnostics/StatusHUDView.swift b/Sources/TurboFieldfareApp/Mac/Diagnostics/StatusHUDView.swiftindex edaecc27..07025c4a 100644--- a/Sources/TurboFieldfareApp/Mac/Diagnostics/StatusHUDView.swift+++ b/Sources/TurboFieldfareApp/Mac/Diagnostics/StatusHUDView.swift@@ -67,12 +67,16 @@ private struct PhaseLabel: View {Text(label)case .pulse(let label):PulsingDot()- Text(label).monospacedDigit()+ Text(label)+ .monospacedDigit()+ .contentTransition(.numericText())case .steady(let label):Circle().fill(.indigo).frame(width: 7, height: 7)- Text(label)+ Text(label).contentTransition(.opacity)case .quiet(let label):- Text(label).foregroundStyle(.secondary)+ Text(label)+ .foregroundStyle(.secondary)+ .contentTransition(.opacity)}}.font(.caption.weight(.medium))diff --git a/Sources/TurboFieldfareApp/Mac/Generation/OutputPaneView.swift b/Sources/TurboFieldfareApp/Mac/Generation/OutputPaneView.swiftindex 9a8aeffe..be456a00 100644--- a/Sources/TurboFieldfareApp/Mac/Generation/OutputPaneView.swift+++ b/Sources/TurboFieldfareApp/Mac/Generation/OutputPaneView.swift@@ -7,7 +7,9 @@ struct OutputPaneView: View {var body: some View {Group {- if model.hasOutputTranscript {+ if model.isRunning && !hasVisibleCompletion {+ pendingGeneration+ } else if model.hasOutputTranscript {transcript} else {placeholder@@ -27,13 +29,7 @@ struct OutputPaneView: View {@ViewBuilderprivate var placeholder: some View {ScrollView {- Group {- if model.phase == .prefill {- prefillPlaceholder- } else {- emptyPlaceholder- }- }+ emptyPlaceholder.padding(.horizontal, 24).padding(.vertical, 20).frame(maxWidth: .infinity, alignment: .leading)@@ -42,27 +38,16 @@ struct OutputPaneView: View {}private var transcript: some View {- VStack(alignment: .leading, spacing: 16) {- IncrementalTranscriptView(- prompt: model.outputPromptText,- output: model.outputText,- mailbox: model.generationTranscriptMailbox)- .frame(maxWidth: .infinity, maxHeight: .infinity)-- if model.phase == .prefill {- prefillStatus- }- }+ IncrementalTranscriptView(+ prompt: model.outputPromptText,+ output: model.outputText,+ mailbox: model.generationTranscriptMailbox)+ .frame(maxWidth: .infinity, maxHeight: .infinity).padding(.horizontal, 24).padding(.vertical, 20)}- private var prefillPlaceholder: some View {- prefillStatus- .frame(maxWidth: .infinity, minHeight: 240)- }-- private var prefillStatus: some View {+ private var pendingGeneration: some View {VStack(spacing: 10) {Text("Processing prompt").font(.callout)@@ -74,6 +59,12 @@ struct OutputPaneView: View {.foregroundStyle(.tertiary)}}+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ .padding(24)+ }++ private var hasVisibleCompletion: Bool {+ model.outputText.contains { !$0.isWhitespace }}private var emptyPlaceholder: some View {diff --git a/Sources/TurboFieldfareApp/Mac/Generation/PromptComposerView.swift b/Sources/TurboFieldfareApp/Mac/Generation/PromptComposerView.swiftindex 3e51b3cf..932e54e8 100644--- a/Sources/TurboFieldfareApp/Mac/Generation/PromptComposerView.swift+++ b/Sources/TurboFieldfareApp/Mac/Generation/PromptComposerView.swift@@ -4,6 +4,7 @@ import SwiftUIstruct PromptComposerView: View {@Bindable var model: AppModel@FocusState private var promptFocused: Bool+ @State private var showingPromptTips = falsevar body: some View {VStack(alignment: .leading, spacing: 8) {@@ -42,17 +43,68 @@ struct PromptComposerView: View {}private var editorHeight: CGFloat {- model.promptText.isEmpty ? 38 : 76+ model.promptText.isEmpty ? 46 : 84}private var footer: some View {HStack(spacing: 10) {+ promptTipsSpacer()clearActionGenerateControl(model: model)}}+ private var promptTips: some View {+ Button {+ showingPromptTips.toggle()+ } label: {+ Label("Prompt tips", systemImage: "questionmark.circle")+ .labelStyle(.iconOnly)+ .frame(width: 28, height: 28)+ .contentShape(Circle())+ }+ .buttonStyle(.borderless)+ .foregroundStyle(.secondary)+ .help("Prompt tips")+ .popover(isPresented: $showingPromptTips,+ attachmentAnchor: .point(.top),+ arrowEdge: .top) {+ promptGuide+ }+ }++ private var promptGuide: some View {+ VStack(alignment: .leading, spacing: 14) {+ Text("Prompting this model")+ .font(.headline)++ tipSection("It continues text",+ "This is a base completion model, not a chat assistant. Write the beginning of the output you want, such as “A concise explanation:” or a function signature.")+ tipSection("If it repeats or runs on",+ "Keep Temperature at 1.0, retry, shorten Max response, or enable Repetition penalty.")+ tipSection("If it drifts or invents facts",+ "Put required facts, constraints, and the desired structure directly in the prompt. Keep the requested continuation focused and verify factual output.")+ tipSection("For code or exact formats",+ "Include the signature, schema, or a short example. Lower temperature can reduce variation, but it may increase repetition and does not guarantee correct code.")+ tipSection("If it does not answer",+ "Turn the question into an answer prefix. For example, use “The reason this happens is” instead of “Why does this happen?”")+ }+ .font(.callout)+ .frame(width: 390, alignment: .leading)+ .padding(18)+ }++ private func tipSection(_ title: String, _ detail: String) -> some View {+ VStack(alignment: .leading, spacing: 3) {+ Text(title)+ .fontWeight(.semibold)+ Text(detail)+ .foregroundStyle(.secondary)+ .fixedSize(horizontal: false, vertical: true)+ }+ }+@ViewBuilderprivate var clearAction: some View {if !model.isRunning && model.hasOutputTranscript {diff --git a/Sources/TurboFieldfareCLI/Args.swift b/Sources/TurboFieldfareCLI/Args.swiftindex af0bc657..53c3f3e5 100644--- a/Sources/TurboFieldfareCLI/Args.swift+++ b/Sources/TurboFieldfareCLI/Args.swift@@ -15,7 +15,7 @@ public struct Args: Equatable, Sendable {prompt: String,maxNew: Int = 1_024,maxContext: Int = 4096,- temperature: Float = 0.1,+ temperature: Float = 1.0,topK: Int? = 64,topP: Float? = 0.95,repetitionPenalty: Float = 1.0,@@ -67,7 +67,7 @@ extension Args {options:--max-new <int> Generated-token limit (default 1024).--max-context <int> Context limit in tokens (default 4096).- --temperature <float> Sampling temperature (default 0.1; 0 = greedy).+ --temperature <float> Sampling temperature (default 1.0; 0 = greedy).--top-k <int> Top-k truncation, 1...256 (default 64; 0 = off).--top-p <float> Nucleus truncation (default 0.95).--repetition-penalty <f> Repetition penalty (default 1.0).@@ -82,7 +82,7 @@ extension Args {var prompt: String?var maxNew = 1_024var maxContext = 4096- var temperature: Float = 0.1+ var temperature: Float = 1.0var topK: Int? = 64var topP: Float? = 0.95var repetitionPenalty: Float = 1.0diff --git a/Tests/TurboFieldfare/Core/CLI/CLIArgumentsTests.swift b/Tests/TurboFieldfare/Core/CLI/CLIArgumentsTests.swiftindex 282a64e3..ce1e5600 100644--- a/Tests/TurboFieldfare/Core/CLI/CLIArgumentsTests.swift+++ b/Tests/TurboFieldfare/Core/CLI/CLIArgumentsTests.swift@@ -8,7 +8,7 @@ import Testing#expect(arguments.prompt == "hi")#expect(arguments.maxNew == 1_024)#expect(arguments.maxContext == 4096)- #expect(arguments.temperature == 0.1)+ #expect(arguments.temperature == 1.0)#expect(arguments.topK == 64)#expect(arguments.topP == 0.95)#expect(arguments.repetitionPenalty == 1)diff --git a/Tests/TurboFieldfareApp/Core/Inference/AppGenerationRequestTests.swift b/Tests/TurboFieldfareApp/Core/Inference/AppGenerationRequestTests.swiftindex 8e7ed539..e8452116 100644--- a/Tests/TurboFieldfareApp/Core/Inference/AppGenerationRequestTests.swift+++ b/Tests/TurboFieldfareApp/Core/Inference/AppGenerationRequestTests.swift@@ -8,7 +8,7 @@ import Testing@Test func defaultRequestUsesDocumentedSamplingPolicy() {let request = AppGenerationRequest(modelDirectory: existingDirectory, prompt: "hello")#expect(request.maxNewTokens == 1_024)- #expect(request.temperature == 0.1)+ #expect(request.temperature == 1.0)#expect(request.topK == 64)#expect(request.topP == 0.95)#expect(request.repetitionPenalty == 1)diff --git a/Tests/TurboFieldfareApp/Core/Inference/RealInferenceClientStateTests.swift b/Tests/TurboFieldfareApp/Core/Inference/RealInferenceClientStateTests.swiftindex 8c422aff..f67fffbe 100644--- a/Tests/TurboFieldfareApp/Core/Inference/RealInferenceClientStateTests.swift+++ b/Tests/TurboFieldfareApp/Core/Inference/RealInferenceClientStateTests.swift@@ -79,7 +79,7 @@ import TurboFieldfareprompt: "hello")let config = RealInferenceSession.generationConfig(for: request)- #expect(config.temperature == 0.1)+ #expect(config.temperature == 1.0)#expect(config.topK == 64)#expect(config.topP == 0.95)#expect(config.repetitionPenalty == 1)diff --git a/Tests/TurboFieldfareApp/Core/State/AppModelTests.swift b/Tests/TurboFieldfareApp/Core/State/AppModelTests.swiftindex 7dc468ba..aa615e14 100644--- a/Tests/TurboFieldfareApp/Core/State/AppModelTests.swift+++ b/Tests/TurboFieldfareApp/Core/State/AppModelTests.swift@@ -10,7 +10,7 @@ import Testingmodel.promptText = "go"let request = try model.makeRequest()- #expect(request.temperature == 0.1)+ #expect(request.temperature == 1.0)#expect(request.topK == 64)#expect(request.topP == 0.95)#expect(request.maxNewTokens == 1_024)diff --git a/docs/COMMUNITY_BENCHMARKS.md b/docs/COMMUNITY_BENCHMARKS.mdindex 125c643c..d3eaf03d 100644--- a/docs/COMMUNITY_BENCHMARKS.md+++ b/docs/COMMUNITY_BENCHMARKS.md@@ -9,7 +9,7 @@ comparable.This is an explicit reproducibility workload, not the interactive productdefault. The app and CLI normally allow up to 1,024 new tokens and sample with-temperature `0.1`, Top-K `64`, and Top-P `0.95`; the commands below override+temperature `1.0`, Top-K `64`, and Top-P `0.95`; the commands below overridethose values with a fixed 256-token greedy decode.The public package uses `TurboFieldfareCLI` for this measurement. Its timingdiff --git a/docs/RUNTIME_CONTROLS.md b/docs/RUNTIME_CONTROLS.mdindex 74c042d1..270927d0 100644--- a/docs/RUNTIME_CONTROLS.md+++ b/docs/RUNTIME_CONTROLS.md@@ -13,7 +13,7 @@ The Mac app and CLI share these interactive defaults:| --- | --- | --- | --- | --- || Maximum response | 1...4,096 tokens | `--max-new` | 1,024 | Caps newly generated tokens. It does not include prompt tokens. || Maximum context | 256...8,192 tokens | `--max-context` | 4,096 | Sets the prompt plus generation KV-cache budget. |-| Temperature | 0...2 in 0.05 steps | `--temperature` | 0.1 | `0` selects deterministic greedy decoding; positive values sample. |+| Temperature | 0...2 in 0.05 steps | `--temperature` | 1.0 | `0` selects deterministic greedy decoding; positive values sample. || Top-K | Off or 1...256 | `--top-k` | 64 | Keeps at most K candidates. The CLI value `0` turns it off. || Top-P | Off or 0.01...1 | `--top-p` | 0.95 | Keeps candidates within the selected probability mass before Top-K. It is effective only while Top-K is enabled. || Repetition penalty | Off or 1...1.8 | `--repetition-penalty` | Off (`1.0`) | Values above `1.0` penalize tokens already present in the sequence. |