-
Notifications
You must be signed in to change notification settings - Fork 123
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
switch swift-tokenizers to main, remove some workarounds #26
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,54 +67,13 @@ public func loadTokenizer(configuration: ModelConfiguration) async throws -> Tok | |
tokenizerConfig = Config(dictionary) | ||
} | ||
|
||
// workaround: some merges can't be split on space in BPETokenizer | ||
if let tokenizerClass = tokenizerConfig.tokenizerClass?.stringValue { | ||
switch tokenizerClass { | ||
case "T5Tokenizer": | ||
break | ||
default: | ||
tokenizerData = discardUnhandledMerges(tokenizerData: tokenizerData) | ||
} | ||
} | ||
|
||
let impl = try PreTrainedTokenizer( | ||
tokenizerConfig: tokenizerConfig, tokenizerData: tokenizerData) | ||
|
||
return Tokenizer(tokenizer: impl, tokenizerConfig: tokenizerConfig) | ||
} | ||
|
||
public func discardUnhandledMerges(tokenizerData: Config) -> Config { | ||
// see https://github.com/ml-explore/mlx-swift-examples/issues/1 | ||
// and https://github.com/huggingface/swift-transformers/issues/51 | ||
|
||
if let model = tokenizerData.model { | ||
if let merges = model.dictionary["merges"] as? [String] { | ||
// discard any merges that can't be split on a space | ||
// (required by BPETokenizer) | ||
let newMerges = | ||
merges | ||
.filter { | ||
$0.split(separator: " ").count == 2 | ||
} | ||
|
||
if newMerges.count != merges.count { | ||
var newModel = model.dictionary | ||
newModel["merges"] = newMerges | ||
|
||
var newTokenizerData = tokenizerData.dictionary | ||
newTokenizerData["model"] = newModel | ||
|
||
return Config(newTokenizerData) | ||
} | ||
} | ||
} | ||
|
||
return tokenizerData | ||
} | ||
|
||
/// overrides for TokenizerModel/knownTokenizers | ||
let replacementTokenizers = [ | ||
"CodeLlamaTokenizer": "LlamaTokenizer", | ||
"GemmaTokenizer": "PreTrainedTokenizer", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are now entries in knownTokenizers: |
||
"Qwen2Tokenizer": "PreTrainedTokenizer", | ||
"Qwen2Tokenizer": "PreTrainedTokenizer" | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,8 +59,8 @@ | |
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/huggingface/swift-transformers", | ||
"state" : { | ||
"revision" : "564442fba36b0b694d730a62d0593e5f54043b55", | ||
"version" : "0.1.2" | ||
"branch" : "main", | ||
"revision" : "24605a8c0cc974bec5b94a6752eb687bae77db31" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch to main of swift-transformers, track a particular commit hash (the current head) -- we can move this forward as changes come in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pushed tag |
||
} | ||
} | ||
], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed in:
Removing workaround