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

Use fallback config if class not defined #53

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/Hub/Hub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public class LanguageModelConfigurationFromHub {
// Try to guess the class if it's not present and the modelType is
if let _ = hubConfig.tokenizerClass?.stringValue { return hubConfig }
guard let modelType = try await modelType else { return hubConfig }

// If the config exists but doesn't contain a tokenizerClass, use a fallback config if we have it
if let fallbackConfig = Self.fallbackTokenizerConfig(for: modelType) {
let configuration = fallbackConfig.dictionary.merging(hubConfig.dictionary, uniquingKeysWith: { current, _ in current })
return Config(configuration)
}

// Guess by capitalizing
var configuration = hubConfig.dictionary
configuration["tokenizer_class"] = "\(modelType.capitalized)Tokenizer"
return Config(configuration)
Expand Down