-
Notifications
You must be signed in to change notification settings - Fork 54
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
NPM package is very huge #68
Comments
@dqbd Even in JS version, there is an index file with all of the encoders inside (3MB+) and there are also separate encoder files in ranks directory and chunks.. why is that so? The "light" version doesn't do nothing about package size - the light version should include only the code for the tokenizer not the actual encoders - they can be loaded from CDN or from local directory.. |
Hi @anzemur! The unpackaged size reported by Consider the following code snippet, which can be successfully deployed Vercel on Hobby plan with 1 MB code size limit (as of 30/08/2023). import { Tiktoken } from "js-tiktoken/lite";
import cl100k_base from "js-tiktoken/ranks/cl100k_base";
export const config = { runtime: "edge" };
export default async function () {
const encoding = new Tiktoken(cl100k_base);
const tokens = encoding.encode("hello world");
return new Response(`${tokens}`);
} Ideally though, the ranks should be fetched via CDN, as seen in Langchain PR: langchain-ai/langchainjs#1239, which drops the bundle size down to 4.5kB (using |
Regarding extensions Assuming your initial question, you might be just zipping the entire project with |
@anzemur there is also another package you might consider to use https://github.com/niieani/gpt-tokenizer |
For anyone coming to this now, this is the new way to do it: import { Tiktoken } from 'js-tiktoken/lite'
const getTokenModel = async () => {
const response = await fetch('https://tiktoken.pages.dev/js/cl100k_base.json')
return await response.json()
}
const rank = await getTokenModel()
const tokenizer = new Tiktoken(rank)
const tokens = tokenizer.encode('Hello World').length You could also save the json file to your app directory and import it into the function. |
Could we release a lightweight js-tiktoken/lite package without the necessary tokenization tables? |
I just noticed that this package is around 13MB when unpackaged and I reached my AWS Lambda package size limit. This is absolutely too big for serverless deployment.
So my questions are:
The text was updated successfully, but these errors were encountered: