Skip to content
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

feat: add support for custom Hub endpoint #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sy1995
Copy link

@sy1995 sy1995 commented Jan 30, 2025

Description

This PR adds support for custom Hub endpoints to improve network reliability. Users can now specify a custom endpoint (e.g., https://hf-mirror.com) when loading a model, which helps address network quality issues.

Changes

  • Added a new loadContainer method in ModelFactory extension.
  • Updated documentation to reflect the new functionality.
  • Default endpoint is set to https://hf-mirror.com.


// Manually create a ModelContainer
return ModelContainer(context: context)
}
Copy link
Collaborator

@davidkoski davidkoski Feb 3, 2025

Choose a reason for hiding this comment

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

I don't think we should add a new method like this -- the non-default parameters will match the other method signatures and this may be hard to call.

I think a new property could be added to the ModelFactory protocol:

    var defaultHubApi: HubApi { get set }

and then the default implementations of these methods could be reworked like this:

    public func loadContainer(
        hub: HubApi? = nil, configuration: ModelConfiguration,
        progressHandler: @Sendable @escaping (Progress) -> Void = { _ in }
    ) async throws -> ModelContainer {
        try await _loadContainer(
            hub: hub ?? defaultHubApi, configuration: configuration, progressHandler: progressHandler)
    }

Then the caller can set a new default HubApi if they want.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, having access to mirrors sounds great but I think we should keep the default as it was. We can add an argument in the command line tools but I think app developers should decide if they want this specific mirror or not.

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