SPB Git

spb/zyquo-mlx Public MIT

The local MLX foundry for your Mac — run, fine-tune, quantize, and ship models. Nothing leaves your machine.

Swift 93.4% Python 3.8% Makefile 2.2% Shell 0.5%
1.7 KB · 60 lines swift
Raw Blame History
1//2//  GenerationParams.swift3//  Zyquo MLX4//5//  Author: Simon-Pierre Boucher6//  Mail: contact@spboucher.ai7//89import Foundation10import MLXLMCommon1112/// App-level generation parameters (Codable for persistence, presets, and13/// per-run notes). Mapped 1:1 onto `MLXLMCommon.GenerateParameters`14/// (verified fields — docs/MLX-RESEARCH.md §4.3).15struct GenerationParams: Codable, Hashable, Sendable {16    var temperature: Float = 0.617    var topP: Float = 1.018    var topK: Int = 019    var minP: Float = 0.020    var maxTokens: Int? = 204821    var repetitionPenalty: Float?22    var repetitionContextSize: Int = 2023    var seed: UInt64?24    /// KV-cache quantization bits (nil = off).25    var kvBits: Int?26    var kvGroupSize: Int = 6427    /// Cap on KV cache length (RotatingKVCache when set).28    var maxKVSize: Int?2930    var asMLX: GenerateParameters {31        GenerateParameters(32            maxTokens: maxTokens,33            maxKVSize: maxKVSize,34            kvBits: kvBits,35            kvGroupSize: kvGroupSize,36            temperature: temperature,37            topP: topP,38            topK: topK,39            minP: minP,40            repetitionPenalty: repetitionPenalty,41            repetitionContextSize: repetitionContextSize,42            seed: seed43        )44    }45}4647/// Final statistics for one generation (from `GenerateCompletionInfo`).48struct InferenceStats: Codable, Hashable, Sendable {49    var promptTokens: Int50    var generatedTokens: Int51    /// Time to first token ≈ prompt processing time.52    var ttft: TimeInterval53    var generateTime: TimeInterval54    var stopReason: String5556    var tokensPerSecond: Double {57        generateTime > 0 ? Double(generatedTokens) / generateTime : 058    }59}60