Skip to content

Update MLXChatExample for iOS Sandboxing #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rudrankriyam
Copy link
Contributor

On iOS, due to sandboxing, using the default hub gives an error along the line because it cannot store in the downloads directory:

You do not have permission to save the file "model-name" in the folder "mlx-community"

We can directly use the default parameter of HubApi() that stores under the documents directory, accessible on both iOS and macOS.

Also, I wonder the need for the default static value then?

/// Extension providing a default HubApi instance for downloading model files
extension HubApi {
    /// Default HubApi instance configured to download models to the user's Downloads directory
    /// under a 'huggingface' subdirectory.
    static let `default` = HubApi(
        downloadBase: URL.downloadsDirectory.appending(path: "huggingface"))
}

Thank you creating this example @ibrahimcetin!

@rudrankriyam
Copy link
Contributor Author

On second thoughts, would you prefer a OS dependent approach? Keep desired behavior of downloads folder on macOS, while documents for the rest OSes.

@ibrahimcetin
Copy link
Contributor

I’ve added this because my Documents directory syncs with iCloud, which caused all Hugging Face models to sync to my iCloud account. I didn’t test this on iOS, so I didn’t notice the issue earlier.

For now, using this workaround might be a better approach:

#if(os(macOS))
static let `default` = HubApi(
        downloadBase: URL.downloadsDirectory.appending(path: "huggingface"))
#elseif(os(iOS))
static let `default` = HubApi()
#endif

Later, we can improve the handling of this in HubApi for a more robust solution.

@rudrankriyam
Copy link
Contributor Author

Let's do it #else only so it takes care of visionOS as well

@ibrahimcetin
Copy link
Contributor

ibrahimcetin commented Apr 27, 2025

Thank you.

I think HubApi should use HF_HOME if configured or default huggingface path as a default on macOS. What do you think @rudrankriyam?

@rudrankriyam
Copy link
Contributor Author

I think the HF_HOME is for the token, and not the path to store the download? For a sample project, I would prefer keeping it to default and let the developers update the path according to their needs. What do you say?

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