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

Replace usage of Bundle.module to build outside SPM context #125

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

Conversation

a2they
Copy link

@a2they a2they commented Sep 20, 2024

Replacing Bundle.module with Bundle(for: self) to accommodate building transformers outside SPM context.

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

Very cool, thanks for showing how to do it! 🔥

Apologies for the delay in reviewing, it was a 🦙 week.

I'll check what's happening with the CI.

@@ -202,7 +202,8 @@ public class LanguageModelConfigurationFromHub {
}

static func fallbackTokenizerConfig(for modelType: String) -> Config? {
guard let url = Bundle.module.url(forResource: "\(modelType)_tokenizer_config", withExtension: "json") else { return nil }
let bundle = Bundle(for: self)
Copy link
Member

Choose a reason for hiding this comment

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

We could fix the tests doing something like:

Suggested change
let bundle = Bundle(for: self)
let bundle = NSClassFromString("XCTest") != nil ? Bundle.module : Bundle(for: self)

But upon additional testing I found that building a CLI that uses Tokenizers would not find the fallback configuration either.

Do you have any thoughts on that? Some additional ideas:

  • Iterate through the bundles and select the right one.
  • Create a bundle (or framework?) solely dedicated to hosting the resources.
  • Download the fallback configs from a well-known location in the Hub.

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