ml-explore / mlx-swift-examples

Examples using MLX Swift
MIT License
462 stars 72 forks source link

Prepare for strict concurrency in Swift 6 #82

Open DePasqualeOrg opened 4 weeks ago

DePasqualeOrg commented 4 weeks ago

After setting "Strict Concurrency Checking" to "Complete" in my app's build settings in preparation for migrating to Swift 6, I get warnings about LLMModel, GenerateResult, GenerateParameters, and GenerateDisposition from mlx-libraries, which don't currently conform to the Sendable protocol. Is it possible to make these conform to Sendable?

davidkoski commented 4 weeks ago

Yes, should be easy enough!

DePasqualeOrg commented 4 weeks ago

I tried adding Sendable to LLMModel, but then I get this error and warning on the classes that implement it:

'Sendable' class 'LlamaModel' cannot inherit from another class other than 'NSObject' Non-final class 'LlamaModel' cannot conform to 'Sendable'; use '@unchecked Sendable'

DePasqualeOrg commented 4 weeks ago

https://github.com/ml-explore/mlx-swift-examples/pull/83

davidkoski commented 3 weeks ago

See also https://github.com/ml-explore/mlx-swift/pull/102

davidkoski commented 3 weeks ago

I think the tricky one here is LLMModel -- MLXArray is mutable and very much not thread safe. Should LLMModel be thread safe? We would need to make sure it never exposed bare MLXArrays, which it certainly does now.