apple_fm
apple_fm
¶
In-process Apple Foundation Models (AFM 3) engine.
Drives Apple's apple_fm_sdk against the on-device model behind Apple
Intelligence, with no HTTP hop and no second process — so the energy measured
around a request is the energy the request actually cost. (The
apple_fm_shim + apple_fm engine pair remains available for pointing
external OpenAI-compatible clients at the same model.)
Requires an Apple Silicon Mac on macOS 26+ with Apple Intelligence enabled, and a full Xcode — not just Command Line Tools — because the SDK compiles Swift bindings at install time::
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \
uv pip install -e '.[afm]'
jarvis ask --engine afm --model afm-3-core "..."
Measurement caveats specific to this backend — read before comparing numbers against MLX or Ollama:
session.stream_responseyields cumulative text snapshots, each batching roughly 8-10 tokens.ttftis therefore time-to-first-chunk (an upper bound on true TTFT — around 450ms on an M1 Pro versus a few tens of ms of real first-token latency), and derived inter-token latencies are inter-chunk latencies. Neither is comparable to a backend that streams one token at a time. Token counts, throughput and per-token energy are unaffected.- The SDK exposes no way to select AFM 3 Core (dense ~3B) versus AFM 3 Core
Advanced (20B sparse MoE, 1-4B active per request); the framework's dynamic
profile picks one from the host device's capabilities.
modelis a run label only — :meth:AppleFMEngine.describerecords the SDK version, context size and host chip so a run can be attributed after the fact. - There is no Private Cloud Compute path in the Python SDK, which suits OpenJarvis: off-device inference would make the on-device energy measurement meaningless.
Classes¶
AppleFMEngine
¶
AppleFMEngine(instructions: str = '', use_case: str = 'general', guardrails: str = 'default', sampling: str = 'greedy')
Bases: InferenceEngine
Apple Foundation Models, driven in-process via apple_fm_sdk.
Source code in src/openjarvis/engine/apple_fm.py
Functions¶
health
¶
Report on-device model availability.
Returns a bool for the ABC, but logs the SDK's reason first: a bare False would hide whether the cause is Apple Intelligence being switched off, an ineligible device, or assets still downloading.
Source code in src/openjarvis/engine/apple_fm.py
can_serve
¶
Only the AFM labels — this engine cannot serve arbitrary model ids.
Unlike the other local engines, "is the model installed" is not a separate concern here: there is exactly one on-device model, so accepting any id would let engine selection route e.g. a Llama request to AFM and silently answer with a different model.
Source code in src/openjarvis/engine/apple_fm.py
prepare
¶
Validate the label, then warm up outside the first energy window.
The first request after boot pays a large one-off cost for model asset load and XPC setup (~10s versus ~450ms warm on an M1 Pro). Burning it here keeps it out of the telemetry window of the first real request.
Source code in src/openjarvis/engine/apple_fm.py
describe
¶
Run metadata. The executing variant is not observable, so the host chip and SDK version are the only way to attribute a run later.