ml-explore / mlx-swift-examples

Examples using MLX Swift
MIT License
1.03k stars 111 forks source link

Prepare for strict concurrency in Swift 6 #82

Closed DePasqualeOrg closed 3 months ago

DePasqualeOrg commented 5 months 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 5 months ago

Yes, should be easy enough!

DePasqualeOrg commented 5 months 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 5 months ago

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

davidkoski commented 5 months ago

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

davidkoski commented 5 months 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.