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

recursive use of an object detected which would lead to unsafe aliasing in rust #119

Open
mogery opened this issue Aug 22, 2024 · 2 comments

Comments

@mogery
Copy link

mogery commented Aug 22, 2024

Hey, we're getting the following stack trace of this unhandled exception:

Error: recursive use of an object detected which would lead to unsafe aliasing in rust
  File "/app/node_modules/.pnpm/@[email protected]/node_modules/@dqbd/tiktoken/tiktoken_bg.cjs", line 432, col 11, in module.exports.__wbindgen_throw
    throw new Error(getStringFromWasm0(arg0, arg1));
  File "wasm://wasm/01569aca:wasm-function[1197]:0xb3cba"
  File "wasm://wasm/01569aca:wasm-function[1218]:0xb3dcb"
  File "wasm://wasm/01569aca:wasm-function[456]:0x9c989"
  File "/app/node_modules/.pnpm/@[email protected]/node_modules/@dqbd/tiktoken/tiktoken_bg.cjs", line 203, col 44, in TiktokenFinalization
    : new FinalizationRegistry(ptr => wasm.__wbg_tiktoken_free(ptr >>> 0));
  File "<anonymous>", in FinalizationRegistry.cleanupSome

We use tiktoken (@dqbd/[email protected]) in our project like so:

import { encoding_for_model } from "@dqbd/tiktoken";
import { TiktokenModel } from "@dqbd/tiktoken";

// This function calculates the number of tokens in a text string using GPT-3.5-turbo model
export function numTokensFromString(message: string, model: string): number {
  const encoder = encoding_for_model(model as TiktokenModel);

  // Encode the message into tokens
  const tokens = encoder.encode(message);

  // Free the encoder resources after use
  encoder.free();

  // Return the number of tokens
  return tokens.length;
}

Any clues what this might be related to?

@dougdellolio
Copy link

Also running into this issue. @mogery were you able to find any solution to this?

@mogery
Copy link
Author

mogery commented Nov 1, 2024

Not yet, unfortunately.

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

2 participants