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%
2.1 KB · 69 lines swift
Raw Blame History
1//2//  MetricsStream.swift3//  Zyquo MLX4//5//  Author: Simon-Pierre Boucher6//  Mail: contact@spboucher.ai7//89import Foundation1011/// Typed training events, decoded from the PyBridge JSON-lines protocol12/// (`zyquo_train.py`; payload fields are the stable mlx-lm callback dicts —13/// docs/TRAINING-RESEARCH.md §5.2).14enum TrainingEvent: Sendable {15    case started(model: String, iterations: Int)16    case metric(TrainingMetric)17    case checkpointSaved(fileName: String, iteration: Int)18    case finished19    case failed(message: String)20}2122enum MetricsStream {2324    /// Decode one Python event into a training event (nil = ignorable).25    static func decode(_ event: PythonEvent) -> TrainingEvent? {26        switch event.event {27        case "start":28            return .started(29                model: event.string("model") ?? "?",30                iterations: event.int("iters") ?? 0)3132        case "train":33            return .metric(34                TrainingMetric(35                    iteration: event.int("iteration") ?? 0,36                    trainLoss: event.double("train_loss"),37                    valLoss: nil,38                    learningRate: event.double("learning_rate"),39                    iterationsPerSecond: event.double("iterations_per_second"),40                    tokensPerSecond: event.double("tokens_per_second"),41                    trainedTokens: event.int("trained_tokens"),42                    peakMemoryGB: event.double("peak_memory"),43                    timestamp: .now))4445        case "val":46            return .metric(47                TrainingMetric(48                    iteration: event.int("iteration") ?? 0,49                    trainLoss: nil,50                    valLoss: event.double("val_loss"),51                    learningRate: nil,52                    iterationsPerSecond: nil,53                    tokensPerSecond: nil,54                    trainedTokens: nil,55                    peakMemoryGB: nil,56                    timestamp: .now))5758        case "done":59            return .finished6061        case "error":62            return .failed(message: event.string("message") ?? "unknown error")6364        default:65            return nil66        }67    }68}69