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

Huge memory consumsation of isWithinTokenLimit #35

Closed
aminsol opened this issue Oct 10, 2023 · 6 comments
Closed

Huge memory consumsation of isWithinTokenLimit #35

aminsol opened this issue Oct 10, 2023 · 6 comments
Labels

Comments

@aminsol
Copy link

aminsol commented Oct 10, 2023

I am experiencing 200MB increase after implementing gpt-tokenizer the only function that I am using from this library is isWithinTokenLimit. Here is an image of my memory consumtion before and after deployment.
Here is how I am using is

function getRequestTokenCount(req: ChatCompletionRequestMessage[]) {
  const extraTokensDueToPromptForEachMessage = 7
  return req.reduce((acc, curr) => {
    const tokensInText = isWithinTokenLimit(curr.content, Infinity) || 99999
    return acc + tokensInText + extraTokensDueToPromptForEachMessage
  }, 0)
}

image

@olboghgc
Copy link

olboghgc commented Jun 14, 2024

same here, what seems even more weird, is that it made me run out of memory by just importing it, not even using it

@niieani
Copy link
Owner

niieani commented Jul 18, 2024

hi @aminsol and @olboghgc, can you provide a little more context about the platform?
is this under node, bun, the browser?
are you using a bundler of any sort?
which GPT encoding are you trying use?

@olboghgc
Copy link

@niieani Node 18/typescript/babel 7.0.0 in a firebase cloud function, with gpt 3.5 and 4o(but that shouldn't really matter since a simple import already cause a spike in memory usage)

@olboghgc
Copy link

btw I was able to +/- ignore this issue by doing a conditional require so I don't always waste memory when I don't need to call it

Copy link

🎉 This issue has been resolved in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@niieani
Copy link
Owner

niieani commented Sep 20, 2024

New version (2.3.0) should have more than 4x smaller memory footprint (data for GPT-3.5-turbo tokenizer):

Package Version Load time (ms) Memory (Heap) consumption (MB) Total Memory (RSS) (MB) Encode Avg (ms) Decode Avg (ms)
gpt-tokenizer 2.2.3 253.04 45.83 150.42 0.0208 0.0033
gpt-tokenizer 2.3.0 44.58 9.65 35.76 0.0102 0.0025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants