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.2 KB · 42 lines swift
Raw Blame History
1//2//  QuantConfig.swift3//  Zyquo MLX4//5//  Author: Simon-Pierre Boucher6//  Mail: contact@spboucher.ai7//89import Foundation1011/// Quantization recipe (docs/MLX-RESEARCH.md §5: affine supports bits12/// 2/3/4/5/6/8 with group sizes 32/64/128; mxfp4/nvfp4/mxfp8 have fixed13/// bits/groups).14struct QuantConfig: Codable, Hashable, Sendable {15    enum Mode: String, Codable, CaseIterable, Sendable {16        case affine17        case mxfp418        case nvfp419        case mxfp820    }2122    var bits: Int = 423    var groupSize: Int = 6424    var mode: Mode = .affine2526    static let affineBits = [2, 3, 4, 5, 6, 8]27    static let affineGroupSizes = [32, 64, 128]2829    /// Effective bytes/param for size previews (group-scale overhead included).30    var bytesPerParameter: Double {31        (Double(bits) + 32.0 / Double(groupSize)) / 8.032    }3334    /// Predicted weight size after quantizing a model with the given35    /// parameter count (before/after preview in the Convert UI).36    func predictedWeightBytes(parameterCount: Int64) -> Int64 {37        Int64(Double(parameterCount) * bytesPerParameter)38    }3940    var label: String { "\(bits)-bit \(mode.rawValue) (g\(groupSize))" }41}42