Repository navigation
switch to MLXLogger - #702
Conversation
| .joined(separator: " ") | ||
| logger.notice( | ||
| "ParoQuant load phases: \(breakdown, privacy: .public) total=\(String(format: "%.2f", totalSeconds), privacy: .public)s" | ||
| logger.info( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
- you would see it in the console if you were debugging something
- if you were collecting a bug report from a user via
sysdiagnoseorlog collect, both of those will flush the in-memory logs to disk - if there is a need to change the policy there are a couple of mechanisms: https://developer.apple.com/documentation/os/customizing-logging-behavior-while-debugging
Anyway, good call out -- it is a change in behavior and I agree warning is not the right word here.
| subsystem: "com.apple.FoundationModels-MLX", | ||
| category: "GuidedGenerationLoop" | ||
| ) | ||
| private static let logger = MLXLogger(label: "GuidedGenerationLoop") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
True, and perhaps that would be a good enhancement for MLXLogger. It does match swift-log in that regard (just using a label).
| subsystem: "com.apple.FoundationModels-MLX", | ||
| category: "GuidedGenerationLoop" | ||
| ) | ||
| private static let logger = MLXLogger(label: "GuidedGenerationLoop") |
There was a problem hiding this comment.
Also, it seems Linux doesn't surface categories at all, so output from MLXLogger on Linux may be very nondescript.
There was a problem hiding this comment.
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.
Apply the upstream commits d02948b..991266a as a 3-way patch. CLAUDE.md is excluded. - 649f431 update for new TF32 comparison issues (ml-explore#721) - 5ae2635 switch to MLXLogger (ml-explore#702) - 260ada0 add ScriptedLogitsModel (ml-explore#719) - 0ea4465 MLXVLM: Fix Qwen3VL attention masks after cache rotation (ml-explore#706) - db2e7bf Expose request-scoped generation observations in ChatSession (ml-explore#714) - 991266a Clear the MLX buffer cache after each prefill chunk (ml-explore#710) Conflicts: - Package.swift: both sides add the same README exclude; kept ours. - ChatSession.swift: took upstream's transformer-based startGeneration and dropped the GenerationRun struct. Kept the fork's ReasoningHistory and thinkingEnabled capture. startGeneration takes an optional promptTokenCount, so the default path still counts the leading and checkpoint prefill tokens. No new hybrid or recurrent models, so the post-merge ArraysCache.advance checks do not apply. Tests: MLXLMTests 894 XCTest and 1753 Swift Testing tests pass. MLXGuidedGenerationTests 70, MLXFoundationModelsTests 374, CXGrammarTests 7, MLXHuggingFaceMacrosTests 5 pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#711 added a warning in ModelComponent.swift through `Logger(subsystem:category:)`. When its CI ran on Oct 19, MLXLMCommon/Linux/Logger.swift still declared `typealias Logger = os.Logger` for the whole module, so the file compiled without importing os. #702 then deleted that alias and moved the libraries to MLXLogger. #711 merged on Nov 10 with the checks from before #702, so main no longer builds: ModelComponent.swift:28:22: error: cannot find 'Logger' in scope Use `MLXLogger(label:)`, like every other logger in the libraries since #702. Importing os would also build, but it fails on Linux and skips the backend that apps install through `MLXLogger.factory`.
ModelMemory.model counted file-backed embedding tables as resident weights, although the system reads their pages on use and can reclaim them. Add ModelMemory.fileBacked, the bytes of model held in those tables, so callers can size wired-memory tickets and memory charts. Also log through MLXLogger, like the rest of the libraries since ml-explore#702.
Proposed changes
switch to MLXLogger -- we now have an os independent logging mechanism in MLX.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.