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

Tokenizer behavior is different from Python transformers #96

Open
shinichy opened this issue May 8, 2024 · 0 comments
Open

Tokenizer behavior is different from Python transformers #96

shinichy opened this issue May 8, 2024 · 0 comments

Comments

@shinichy
Copy link

shinichy commented May 8, 2024

Hi, I found the tokenizer behavior different from Python transformers when I use Phi-3 model.

swift-transformers

func testTokenizer() async throws {
    let tokenizer = try await AutoTokenizer.from(pretrained: "mlx-community/Phi-3-mini-4k-instruct-4bit-no-q-embed")
    let inputIds = tokenizer(" Hi")
    print(inputIds)
    // output: [1, 6324]
}

Python transformers

from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("mlx-community/Phi-3-mini-4k-instruct-4bit-no-q-embed")
input_ids = tokenizer.encode(" Hi")
print(input_ids)
# output: [1, 29871, 6324]

Python transformers prepends 29871 () before 6324. It seems to be done by the normalizer. I debugged this issue and found that the normalizer is ignored when legacy is false at

if !isLegacy {
configDictionary.removeValue(forKey: "normalizer")
configDictionary["pre_tokenizer"] = ["type": "Metaspace", "replacement": sentencePieceUnderline, "add_prefix_space": true, "prepend_scheme": "first"]
}
.

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

No branches or pull requests

1 participant