Skip to content

Gemma 4 26B-A4B inference in ~2 GB of RAM on any M-series MacBook

Polish public release and repository workflows (#1)

Andrey Mikhaylovf9d14a0fc99b
diff --git a/.github/ISSUE_TEMPLATE/benchmark.yml b/.github/ISSUE_TEMPLATE/benchmark.yml
new file mode 100644
index 00000000..5084817a
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/benchmark.yml
@@ -0,0 +1,57 @@
+name: Performance or benchmark report
+description: Share a reproducible measurement from Apple Silicon.
+title: "[Benchmark]: "
+labels:
+ - performance
+body:
+ - type: markdown
+ attributes:
+ value: Follow docs/COMMUNITY_BENCHMARKS.md and remove personal paths or unrelated process details.
+ - type: input
+ id: commit
+ attributes:
+ label: Commit
+ description: Exact commit SHA used for the measurement.
+ validations:
+ required: true
+ - type: input
+ id: hardware
+ attributes:
+ label: Mac hardware and memory
+ placeholder: M2 MacBook Air, 8 GB
+ validations:
+ required: true
+ - type: input
+ id: environment
+ attributes:
+ label: macOS and Swift versions
+ validations:
+ required: true
+ - type: textarea
+ id: command
+ attributes:
+ label: Command and runtime controls
+ render: shell
+ validations:
+ required: true
+ - type: textarea
+ id: workload
+ attributes:
+ label: Workload
+ description: Include the sanitized prompt, prompt-token count, generated-token count, and cache state.
+ validations:
+ required: true
+ - type: textarea
+ id: results
+ attributes:
+ label: Results
+ description: Include prefill, TTFT, decode throughput, memory, and repeated-run observations when available.
+ validations:
+ required: true
+ - type: textarea
+ id: parity
+ attributes:
+ label: Correctness and output
+ description: Include generated token IDs or text when comparing runtime variants.
+ validations:
+ required: true
diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml
new file mode 100644
index 00000000..d31fc61e
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug.yml
@@ -0,0 +1,60 @@
+name: Bug report
+description: Report reproducible incorrect behavior or a crash.
+title: "[Bug]: "
+labels:
+ - bug
+body:
+ - type: markdown
+ attributes:
+ value: Do not include credentials, private paths, or model weights.
+ - type: input
+ id: commit
+ attributes:
+ label: Commit
+ description: Commit SHA or release where the problem occurs.
+ validations:
+ required: true
+ - type: input
+ id: hardware
+ attributes:
+ label: Mac hardware and memory
+ placeholder: M2 MacBook Air, 8 GB
+ validations:
+ required: true
+ - type: input
+ id: environment
+ attributes:
+ label: macOS and Swift versions
+ placeholder: macOS 26.x, Swift 6.2
+ validations:
+ required: true
+ - type: textarea
+ id: reproduction
+ attributes:
+ label: Reproduction steps
+ description: Include the smallest command, prompt, or interaction that reproduces the issue.
+ validations:
+ required: true
+ - type: textarea
+ id: expected
+ attributes:
+ label: Expected behavior
+ validations:
+ required: true
+ - type: textarea
+ id: observed
+ attributes:
+ label: Observed behavior
+ description: Include sanitized logs or diagnostics when useful.
+ validations:
+ required: true
+ - type: dropdown
+ id: model
+ attributes:
+ label: Does this require the installed model?
+ options:
+ - "Yes"
+ - "No"
+ - Unsure
+ validations:
+ required: true
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 00000000..0917e044
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
+blank_issues_enabled: false
+contact_links:
+ - name: Security vulnerability
+ url: https://github.com/drumih/turbo-fieldfare/security/advisories/new
+ about: Report suspected security vulnerabilities privately.
diff --git a/.github/ISSUE_TEMPLATE/feature.yml b/.github/ISSUE_TEMPLATE/feature.yml
new file mode 100644
index 00000000..4c46cd2d
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature.yml
@@ -0,0 +1,36 @@
+name: Feature proposal
+description: Propose a focused runtime, platform, or tooling improvement.
+title: "[Feature]: "
+labels:
+ - enhancement
+body:
+ - type: textarea
+ id: problem
+ attributes:
+ label: Problem
+ description: Describe the concrete limitation or use case.
+ validations:
+ required: true
+ - type: textarea
+ id: proposal
+ attributes:
+ label: Proposed change
+ description: Describe the smallest useful implementation and affected surfaces.
+ validations:
+ required: true
+ - type: textarea
+ id: evidence
+ attributes:
+ label: Evidence or measurements
+ description: Include profiler data, benchmark results, or primary references when applicable.
+ - type: textarea
+ id: memory
+ attributes:
+ label: Bounded-memory behavior
+ description: Explain how the proposal remains valid on an 8 GB Mac without loading full shards or tensors.
+ validations:
+ required: true
+ - type: textarea
+ id: alternatives
+ attributes:
+ label: Alternatives considered
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 00000000..d52a2950
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,23 @@
+## Summary
+
+Describe the focused change and why it is needed.
+
+## Validation
+
+List the commands and relevant model runs used to validate the change.
+
+## Memory and performance
+
+For model, importer, streaming, or Metal changes, describe the bounded-memory
+behavior and include before/after measurements when performance changes.
+Write `Not applicable` when this section does not apply.
+
+## Remaining limitations
+
+List any behavior that was intentionally left unchanged or still needs
+validation.
+
+- [ ] The change does not load a complete checkpoint, shard, or large model
+ tensor into Swift heap memory.
+- [ ] Logs and artifacts contain no credentials, private paths, or model
+ weights.
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 579108fe..c1314620 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2,8 +2,17 @@ name: CI
on:
push:
+ branches:
+ - main
pull_request:
+permissions:
+ contents: read
+
+concurrency:
+ group: ci-${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
jobs:
test:
runs-on: macos-26
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 00000000..1614a08f
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,39 @@
+# Security policy
+
+## Supported versions
+
+Security fixes are applied to the latest version of the `main` branch. Older
+commits, forks, experimental branches, and modified model packages are not
+supported.
+
+TurboFieldfare is a research project. It is not intended for production,
+multi-user, or security-critical deployments.
+
+## Reporting a vulnerability
+
+Do not open a public issue for a suspected security vulnerability. Use
+[GitHub private vulnerability reporting](https://github.com/drumih/turbo-fieldfare/security/advisories/new)
+instead.
+
+Include:
+
+- a description of the vulnerability;
+- the affected commit or version;
+- reproduction steps or a minimal proof of concept;
+- the expected and observed behavior;
+- the potential security impact; and
+- a suggested mitigation, if known.
+
+Do not include personal data, credentials, access tokens, or copyrighted model
+weights in the report.
+
+Reports are especially useful when they involve unsafe model-package handling,
+path traversal, buffer or offset safety, malformed remote data, verification
+bypasses, command-line injection, credential exposure, or unexpected file
+access. Model quality problems, incorrect generated text, expected high
+resource use, and performance regressions are not normally security
+vulnerabilities.
+
+Please allow the issue to be investigated and a fix to be prepared before
+publishing vulnerability details. Credit can be included in the eventual
+advisory unless the reporter prefers to remain anonymous.
diff --git a/Sources/TurboFieldfare/Kernels/TensorCore/MPPPrefillInt4QMM.swift b/Sources/TurboFieldfare/Kernels/TensorCore/MPPPrefillInt4QMM.swift
index aa3fc9c5..56380155 100644
--- a/Sources/TurboFieldfare/Kernels/TensorCore/MPPPrefillInt4QMM.swift
+++ b/Sources/TurboFieldfare/Kernels/TensorCore/MPPPrefillInt4QMM.swift
@@ -26,6 +26,10 @@ final class MPPPrefillInt4QMM {
}
}
+ var isAvailable: Bool {
+ pipeline != nil
+ }
+
@discardableResult
func encode(commandBuffer: MTLCommandBuffer,
weights: MTLBuffer, weightsOffset: Int = 0,
diff --git a/Tests/TurboFieldfare/Core/Kernels/TensorCore/MPPPrefillInt4QMMTests.swift b/Tests/TurboFieldfare/Core/Kernels/TensorCore/MPPPrefillInt4QMMTests.swift
index cee4a514..bf431457 100644
--- a/Tests/TurboFieldfare/Core/Kernels/TensorCore/MPPPrefillInt4QMMTests.swift
+++ b/Tests/TurboFieldfare/Core/Kernels/TensorCore/MPPPrefillInt4QMMTests.swift
@@ -4,6 +4,11 @@ import Testing
@testable import TurboFieldfare
import TurboFieldfareValidationSupport
+private let mppTensorOpsAvailable: Bool = {
+ guard let context = try? MetalContext() else { return false }
+ return MPPPrefillInt4QMM(context: context).isAvailable
+}()
+
@Suite struct MPPPrefillInt4QMMTests {
private struct Inputs {
let packed: [UInt8]
@@ -182,7 +187,9 @@ import TurboFieldfareValidationSupport
return path
}
- @Test func affineThreadgroupCandidateMatchesFP32AffineReference() throws {
+ @Test(.enabled(if: mppTensorOpsAvailable,
+ "Requires runtime MPP TensorOps support"))
+ func affineThreadgroupCandidateMatchesFP32AffineReference() throws {
let context = try MetalContext()
let candidate = MPPPrefillInt4QMM(context: context)
let baseline = try PrefillInt4QMM(context: context)
@@ -201,7 +208,9 @@ import TurboFieldfareValidationSupport
compareCPUReference: true)
}
- @Test func selectedProductionAttentionShapesMatchCurrentPolicy() throws {
+ @Test(.enabled(if: mppTensorOpsAvailable,
+ "Requires runtime MPP TensorOps support"))
+ func selectedProductionAttentionShapesMatchCurrentPolicy() throws {
let context = try MetalContext()
let candidate = MPPPrefillInt4QMM(context: context)
let baseline = try PrefillInt4QMM(context: context)
@@ -224,7 +233,9 @@ import TurboFieldfareValidationSupport
}
}
- @Test func fullProductionShapeIsByteStableAcross32Dispatches() throws {
+ @Test(.enabled(if: mppTensorOpsAvailable,
+ "Requires runtime MPP TensorOps support"))
+ func fullProductionShapeIsByteStableAcross32Dispatches() throws {
let m = 32
let n = 2816
let k = 8192
diff --git a/docs/SYSTEM_DESIGN.md b/docs/SYSTEM_DESIGN.md
index e949c473..5ab0e3d3 100644
--- a/docs/SYSTEM_DESIGN.md
+++ b/docs/SYSTEM_DESIGN.md
@@ -163,42 +163,40 @@ misses can run on the I/O executor in parallel, but no two reads may write the
same slot concurrently.
```mermaid
-flowchart TB
- subgraph Disk["1. Model package on SSD"]
- direction TB
- MF["Manifest, layout,\nand tokenizer"]
- MW["Common weights\nmodel_weights.bin"]
- LF["Routed experts\n30 layer files\n128 experts each"]
- MF -->|validates at load| MW
- MF -->|validates lazily| LF
+flowchart LR
+ subgraph Disk[".gturbo on SSD"]
+ MW["model_weights.bin\ncommon weights"]
+ LF["30 layer files\n128 routed experts each"]
+ MF["manifest + layout + tokenizer"]
end
- subgraph Memory["2. Unified memory"]
- direction TB
- RB["Mapped common buffers\nread-only, no heap copy"]
- KV["FP16 KV cache\n25 bounded SWA rings\n5 linear full-context stores"]
- EC["Expert cache\n16 LFU slots\nper opened layer"]
- WS["Reusable activation\nand kernel scratch"]
+ subgraph Memory["Unified memory"]
+ RB["read-only mapped\ncommon buffers"]
+ EC["per-layer LFU slots\n16 expert blobs"]
+ KV["FP16 KV ring"]
+ WS["reusable scratch"]
end
- subgraph GPU["3. Per-layer Metal execution"]
- direction TB
- AT["Attention + router"]
- SE["Shared expert\nresident branch"]
- RE["Routed MoE\ncached or streamed top-8"]
- T["Combine branches\n+ layer tail"]
- HD["Tied 4-bit head\nafter layer 30"]
-
- AT --> SE
- AT --> RE
- SE --> T
- RE --> T
- T --> HD
+ subgraph GPU["Metal execution"]
+ AT["attention + router"]
+ SE["shared expert"]
+ RE["routed MoE"]
+ HD["tied 4-bit head"]
end
- MW -->|mmap| RB
- LF -->|pread on cache miss| EC
- Memory -->|feeds each layer| GPU
+ MF -->|validate| MW
+ MF -->|validate lazily| LF
+ MW -->|mmap, no heap copy| RB
+ LF -->|bounded pread on miss| EC
+ RB --> AT
+ RB --> SE
+ EC --> RE
+ KV <--> AT
+ WS <--> GPU
+ AT --> SE
+ AT --> RE
+ SE --> HD
+ RE --> HD
classDef disk fill:#DBEAFE,stroke:#2563EB,color:#172554,stroke-width:1.5px;
classDef memory fill:#DCFCE7,stroke:#16A34A,color:#052E16,stroke-width:1.5px;
@@ -206,7 +204,7 @@ flowchart TB
classDef output fill:#F3E8FF,stroke:#9333EA,color:#3B0764,stroke-width:1.5px;
class MF,MW,LF disk;
class RB,KV,EC,WS memory;
- class AT,SE,RE,T compute;
+ class AT,SE,RE compute;
class HD output;
style Disk fill:#EFF6FF,stroke:#93C5FD,color:#1E3A8A,stroke-width:2px
diff --git a/docs/assets/turbofieldfare-app.webp b/docs/assets/turbofieldfare-app.webp
index 3b95f0ab..73797d92 100644
Binary files a/docs/assets/turbofieldfare-app.webp and b/docs/assets/turbofieldfare-app.webp differ