Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import MLXLMCommon
/// KV cache.
public enum GuidedGenerationLoop {

private static let logger = Logger(
subsystem: "com.apple.FoundationModels-MLX",
category: "GuidedGenerationLoop"
)
private static let logger = MLXLogger(label: "GuidedGenerationLoop")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like because of how MLXLogger works, everything that uses it ends up in the mlx-swift subsystem. I wonder, as more repos adopt MLXLogger, if this is going to get a bit messy.

I see that we're using categories here, but there's no way, for example, to filter down to "everything from mlx-swift-lm". This isn't a major issue but may become annoying depending on the volume.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, and perhaps that would be a good enhancement for MLXLogger. It does match swift-log in that regard (just using a label).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it seems Linux doesn't surface categories at all, so output from MLXLogger on Linux may be very nondescript.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have the label only (it is just printfs). If we were to add an optional category then the printf logger could show that as well.


/// Result of a single generation step.
enum StepResult {
Expand Down
45 changes: 0 additions & 45 deletions Libraries/MLXGuidedGeneration/Linux/Logger.swift

This file was deleted.

3 changes: 1 addition & 2 deletions Libraries/MLXLMCommon/InferenceState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ package struct InferenceStatePreparationReport {
package var succeeded: Bool { failures.isEmpty }
}

private let inferenceStateLogger = Logger(
subsystem: "mlx-swift-lm", category: "inference-state")
private let inferenceStateLogger = MLXLogger(label: "inference-state")

/// Prepare a language model after checkpoint loading or an explicit topology
/// update.
Expand Down
45 changes: 0 additions & 45 deletions Libraries/MLXLMCommon/Linux/Logger.swift

This file was deleted.

6 changes: 3 additions & 3 deletions Libraries/MLXLMCommon/ParoQuant/ParoQuantLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import MLX
import MLXNN

private let logger = Logger(subsystem: "mlx-swift-lm", category: "paroquant")
private let logger = MLXLogger(label: "paroquant")

// MARK: - Detection

Expand Down Expand Up @@ -790,8 +790,8 @@ public func loadParoQuantModel<T: LanguageModel>(
phaseTimes
.map { String(format: "%@=%.2fs", $0.0, $0.1) }
.joined(separator: " ")
logger.notice(
"ParoQuant load phases: \(breakdown, privacy: .public) total=\(String(format: "%.2f", totalSeconds), privacy: .public)s"
logger.info(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that the .info log level isn't saved to disk. If we think any of this stuff might be used for retrospective debugging, that's something to consider.

There's a limitation in MLXLogger though - if we wanted to write these to disk, the next level up is "warning" which maps to OSLogType's .error, which is probably too strong.

I'm not sure if it was intended that
a) nothing in MLXLogger maps to OSLogType.default (where os.Logger.notice used to go), and
b) MLXLogger.warning maps to OSLogType.error

In any case, these are questions about MLXLogger itself. I don't think anything we're losing in persistent logging is too critical, except perhaps the "not enough disk space" one, that one could be interesting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True and I think your last comment is correct: this is about MLXLogger (mostly) and what it supports.

In this case I think info is what we want, or maybe even debug -- this is just logging about what is going on, not a signal that there was a problem. Yes, you might want it in debugging situations, but in that case the info behavior is probably what you want.

Anyway, good call out -- it is a change in behavior and I agree warning is not the right word here.

"ParoQuant load phases: \(breakdown) total=\(String(format: "%.2f", totalSeconds))s"
)

// 12b. Persist the Prepared Checkpoint in the background when this load
Expand Down
17 changes: 8 additions & 9 deletions Libraries/MLXLMCommon/ParoQuant/PreparedCheckpoint.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Foundation
import MLX
import os

private let logger = Logger(subsystem: "mlx-swift-lm", category: "paroquant")
private let logger = MLXLogger(label: "paroquant")

/// Prepared Checkpoint — the once-converted MLX-native form of a PARO
/// checkpoint, stored beside the original so later loads skip the AutoAWQ
Expand Down Expand Up @@ -143,14 +142,14 @@ public enum ParoQuantPreparedCheckpoint {
Manifest.self, from: Data(manifestJSON.utf8)),
stored == manifest
else {
logger.notice("Prepared Checkpoint is stale — re-converting")
logger.info("Prepared Checkpoint is stale — re-converting")
try? FileManager.default.removeItem(at: url)
return nil
}
return arrays
} catch {
logger.warning(
"Prepared Checkpoint unreadable (\(String(describing: error), privacy: .public)) — re-converting"
"Prepared Checkpoint unreadable (\(String(describing: error))) — re-converting"
)
try? FileManager.default.removeItem(at: url)
return nil
Expand Down Expand Up @@ -186,8 +185,8 @@ public enum ParoQuantPreparedCheckpoint {
importantUsage > 0
? importantUsage : Int64(capacity?.volumeAvailableCapacity ?? 0)
if free > 0, free < estimatedBytes * freeSpaceSafetyFactor {
logger.notice(
"Prepared Checkpoint write skipped — free space \(free, privacy: .public)B < \(freeSpaceSafetyFactor, privacy: .public)× estimated \(estimatedBytes, privacy: .public)B"
logger.info(
"Prepared Checkpoint write skipped — free space \(free)B < \(freeSpaceSafetyFactor)× estimated \(estimatedBytes)B"
)
return
}
Expand All @@ -204,12 +203,12 @@ public enum ParoQuantPreparedCheckpoint {
try? fm.removeItem(at: url)
try fm.moveItem(at: tmpURL, to: url)
let seconds = (clock.now - start) / .seconds(1)
logger.notice(
"Prepared Checkpoint written: \(estimatedBytes, privacy: .public)B in \(String(format: "%.1f", seconds), privacy: .public)s"
logger.info(
"Prepared Checkpoint written: \(estimatedBytes)B in \(String(format: "%.1f", seconds))s"
)
} catch {
logger.warning(
"Prepared Checkpoint write failed (\(String(describing: error), privacy: .public)) — next load converts again"
"Prepared Checkpoint write failed (\(String(describing: error))) — next load converts again"
)
try? fm.removeItem(at: tmpURL)
}
Expand Down
5 changes: 3 additions & 2 deletions Libraries/MLXLMCommon/TokenLoopHandler.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright © 2026 Apple Inc.

import MLX

/// Controls whether the generation loop continues.
public enum TokenLoopDisposition: Sendable {
/// Continue generating tokens.
Expand Down Expand Up @@ -66,8 +68,7 @@ extension TokenLoopHandler {
public struct TextToolTokenLoopHandler: TokenLoopHandler {
public typealias Output = Generation

private static let logger = Logger(
subsystem: "mlx-swift-lm", category: "TokenStreamProtocol")
private static let logger = MLXLogger(label: "TokenStreamProtocol")
private var decoder: any TokenStreamDecoder

public init(
Expand Down
Loading