Skip to content

switch to MLXLogger - #702

Merged
davidkoski merged 3 commits into
mainfrom
mlx-logger
Oct 23, 2026
Merged

davidkoski merged 3 commits into
mainfrom
mlx-logger

Conversation

@davidkoski

Copy link
Copy Markdown
Member

Proposed changes

switch to MLXLogger -- we now have an os independent logging mechanism in MLX.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: none

.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.

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).

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.

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.

@davidkoski
davidkoski merged commit 5ae2635 into main Oct 23, 2026
5 checks passed
@davidkoski
davidkoski deleted the mlx-logger branch October 23, 2026 17:15
wballard added a commit to swissarmyhammer/mlx-swift-lm-old that referenced this pull request Oct 24, 2026
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>
davidkoski pushed a commit that referenced this pull request Nov 11, 2026
#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`.
aleroot added a commit to aleroot/mlx-swift-lm that referenced this pull request Nov 14, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants