-
Notifications
You must be signed in to change notification settings - Fork 38
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
avoid expensive initialization #18
Comments
We're experincing this as well -- requiring this package takes ~600ms on my M1 MBP:
Would it be hard to lazily require the encodings only once the first |
Same issue on my end. |
For Cloudflare Workers I suggest you look at this: |
To get around the 400ms startup time limit of Cloudflare Workers, I just import the library within fetch. export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const { encode } = await import('gpt-tokenizer');
// ....
}
} Regarding another suggested library by @thdoan, I couldn't get |
When designing the decision was made to make it possible for the tokenizer loadable synchronously. You could try to experiment with enabling v8's code cache introduced in node 22.1.0. It should start much faster with it enabled. Here's more info about this. We could also experiment with an alternative way of storing the encodings so that parsing is much simpler/easier on the resources. Would need to profile and see what is causing the bulk of the startup time right now. Suggestions and PRs welcome, as I'm constrained on time right now. |
fixes #18 (or at least attempts to do so)
fixes #18 chore: preliminary benchmarking tool feat: update tokenization format to make the package smaller docs: update README
fixes #18 chore: preliminary benchmarking tool feat: update tokenization format to make the package smaller docs: update README
🎉 This issue has been resolved in version 2.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
New version should be much faster to load and lighter (data for GPT-3.5-turbo tokenizer):
|
amazing work! |
Hello,
I'm using the following:
which seems to slow down the initialization, enough that I can't deploy to cloudflare workers with this library. Is there a way to lazily initialize things?
The text was updated successfully, but these errors were encountered: