Walk this list on a real device. A Mac GPU pass is useful. It is not the iOS jetsam pass.
- Architecture. Read
model_type. Callcontains. Register if missing. Load only after that. Confirm names in the mlx-swift-lm docs you pinned. - Weights. Load once at startup or on first use in the foreground. Do not reload on every prompt. Fail the screen if load throws. Do not start generate on a nil container.
- Memory. Pick a 4-bit or other quantized build you can hold with KV cache. Check the current MLX Swift GPU cache and memory limit APIs in mlx-swift. Cap the cache. After cancel, drop the generate Task. Do not keep an extra copy of tokens in three views.
- Cancellation. One generate Task.
scenePhase != .activecancels it. The token loop honorsTask.isCancelled. No second generate from.inactive. - Resume. Partial text stays on screen. Resume is a user tap after
.active. New Task. Saved prompt. - Logging. Log three events with a reason: register miss, load failure, generate cancel. Include
model_type, phase, and cancelled yes or no. Do not log the prompt if it can hold private text. - Device proof. Background during a long run. Confirm no Metal error and no zombie Task. Cold-start after jetsam. Confirm load and register still run.
enum MLXProductionLog {
case registerMiss(modelType: String)
case loadFailed(modelType: String, message: String)
case generateCancelled(phase: String)
}
func record(_ event: MLXProductionLog) {
// Send to your existing os.Logger or tracer.
// Do not put user prompt text in the event.
switch event {
case .registerMiss(let modelType):
print("mlx.register_miss type=\(modelType)")
case .loadFailed(let modelType, let message):
print("mlx.load_failed type=\(modelType) \(message)")
case .generateCancelled(let phase):
print("mlx.generate_cancelled phase=\(phase)")
}
}
If you also ship Core AI for some jobs, keep the split clear. This list is the MLX Swift runtime. The baked .aimodel path is PyTorch to Core AI in Xcode. Picking which runtime a task should use is Route work to the right Apple model. Measuring the tokens you do stream is Stream tokens and measure speed.
Related links
- Core AI vs Core ML vs MLX
- Route work to the right Apple model
- Stream tokens and measure speed
- PyTorch to Core AI in Xcode
- The agent harness (and how to improve it)
- mlx-swift and mlx-swift-lm
- scenePhase
Rule. Register, load, cap memory, cancel on phase, log the three failures. Then ship.
Key concepts
- Register and load before any generate.
- Cap GPU cache and resident weights. Prove memory on a device.
- Cancel on not-active. Resume only from a user tap.
- Log register miss, load failure, and generate cancel without prompt text.
Takeaways
- You can walk a short ship list on a real device.
- You can tell an MLX Swift failure from a Core AI or router failure.
- You can keep private prompts out of the logs.