-
Notifications
You must be signed in to change notification settings - Fork 71
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
[Efficiency] Inefficient to create encoders multiple times #51
Comments
This library already includes a caching mechanism. If you need to cache initialized TikToken objects, you can set a global variable in your own code. The |
@omar-scio sorry this is unrelated but would you mind telling why you have switched libs? I was comparing both and was curious when I saw yor comment. |
I encountered the same problem and it was also relatively slow omar-scio |
@reeveshen you need to use a singleton pattern and initialize it only once. You can use |
Yea we ended up needing to use Also came to this library since the other one @cemremengu didn't have the gpt4-o tokenizer at the time |
I noticed our tests were much slower when switching from https://github.com/tiktoken-go/tokenizer to this library. It seems to be because
tiktoken.EncodingForModel
is very slow (0.3s on my machine).Our I see that the source code is caching the encoding itself, but at this point, why not cache the
*Tiktoken
? That's what we did to fix this in our own codebase, and the latency went away.I can make a PR for this if there is not much time available for the maintainers.
The text was updated successfully, but these errors were encountered: