Skip to content

mlx-swift-examples prep for mlx-swift-lm 3.x release#468

Merged
davidkoski merged 4 commits intomainfrom
mlx-swift-lm-3
Apr 17, 2026
Merged

mlx-swift-examples prep for mlx-swift-lm 3.x release#468
davidkoski merged 4 commits intomainfrom
mlx-swift-lm-3

Conversation

@davidkoski
Copy link
Copy Markdown
Collaborator

@davidkoski davidkoski commented Apr 6, 2026

Proposed changes

This is preparation for the mlx-swift-lm 3.x release (new APIs). This is ready to go. I need to pick up the tag when it is ready.

FYI @DePasqualeOrg

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)

from: #hubDownloader(),
using: #huggingFaceTokenizerLoader(),
configuration: modelConfiguration
) { value in
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Along with linking the HuggingFace libraries, this is the pattern for adopting the new API.

let downloader = #hubDownloader()

let resolved = try await resolve(
configuration: modelConfiguration, from: downloader, useLatest: false
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is a little more complex because it separates out the download from the load. resolve() will download and produce resolved urls that can be loaded.

Comment on lines +146 to +147
let downloader = #hubDownloader()
let loader = #huggingFaceTokenizerLoader()
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't work yet -- there is a local Progress type that conflicts with the use in the macro. See ml-explore/mlx-swift-lm#189

Comment on lines +72 to +79
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = " --download ~/Downloads/huggingface"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--model mlx-community/GLM-4.7-Flash-4bit --max-tokens 5000 --prompt &quot;Testing, testing&#x2026; Who are you? Identify yourself&quot;"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

  • remove, from local testing

Comment on lines +127 to +133
<EnvironmentVariables>
<EnvironmentVariable
key = "METAL_DEVICE_WRAPPER_TYPE"
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
Copy link
Copy Markdown
Collaborator Author

@davidkoski davidkoski Apr 6, 2026

Choose a reason for hiding this comment

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

  • remove

Comment on lines +168 to +169
@Flag(name: .customLong("tool-time"), help: "Enable time telling tool")
var useTimeTool = false
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A way to try the tool integration -- this has better support now.

Comment on lines +221 to +222
// TODO maybe just use ChatSession here?
let x = try await call(toolCall: toolCall)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

  • replace with ChatSession? it has the tool call loop already implemented

Comment on lines +190 to +202
let cache =
if let download = args.args.download {
HubCache(cacheDirectory: download)
} else {
HubCache.default
}

let parts = output.components(separatedBy: "/")
guard parts.count == 2 else {
fatalError("output must be org/name, e.g. mlx-community/mistral-lora: \(output)")
}
let repo = Repo.ID(namespace: parts[0], name: parts[1])
outputURL = cache.repoDirectory(repo: repo, kind: .model)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Maybe tis should be a call to resolve()?

Copy link
Copy Markdown
Member

@angeloskath angeloskath left a comment

Choose a reason for hiding this comment

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

Looks good.

There is a random edit in the tutorial so I left a comment for it but otherwise 👍

Comment thread Tools/Tutorial/Tutorial.swift Outdated

// make an array of shape [2, 2] filled with ones
let y = MLXArray.ones([2, 2])
let y = MLXArray.ones([2, 2], type: Float.self)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't that be the default?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, actually it is -- I think I picked this up when building against this:

There is a thread of investigation there, but in the end I am not convinced it is really what is going on.

@davidkoski davidkoski merged commit 357c97f into main Apr 17, 2026
2 checks passed
@davidkoski davidkoski deleted the mlx-swift-lm-3 branch April 17, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants