A Core ML export of
google/functiongemma-270m-it,
optimized for the Apple Neural Engine on iOS 18 / macOS 15. The 18-layer
transformer is reshaped into Apple's
BC1S layout (
(B, C, 1, T)
channel-last with 1×1
Conv2d projections and per-head split attention)
and the K/V cache lives in
MLState slots, so token-by-token decode
sends no tensor I/O back to the host.
This is the
fp16 reference build — full Float16 weights, no
quantization. For the same accuracy with ~½ the disk and faster decode,
see the
Palettize-8 variant.
1import CoreML
2
3let url = URL(fileURLWithPath: "FunctionGemmaANEUnifiedStateful.mlmodelc")
4let config = MLModelConfiguration()
5config.computeUnits = .cpuAndNeuralEngine
6let model = try MLModel(contentsOf: url, configuration: config)
7let state = model.makeState()
8
9// Build prefill inputs (input_ids, cos/sin tables, attention mask,
10// write_mask=ones, logits_mask one-hot at the last prompt position),
11// then for decode call repeatedly with T_q=1 inputs and a one-hot
12// write_mask at the current cache slot.
13let output = try await model.prediction(from: prefillInputs, using: state)
14let logits = output.featureValue(for: "logits")!.multiArrayValue!
The full prefill + decode driver is published as part of the
speech-swift SDK.
1import coremltools as ct
2import numpy as np
3
4model = ct.models.MLModel(
5 "FunctionGemmaANEUnifiedStateful.mlpackage",
6 compute_units=ct.ComputeUnit.CPU_AND_NE,
7)
8state = model.make_state()
9out = model.predict(prefill_inputs, state=state)
10next_id = int(out["logits"][0].argmax())
Upstream model:
google/functiongemma-270m-it
— Gemma 3 270M instruction-tuned for structured function calls.