oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.25k stars 2.77k forks source link

Reliable segfault in Bun - running some transformers.js code #6089

Closed swyxio closed 1 year ago

swyxio commented 1 year ago

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Darwin 21.6.0 arm64 arm

What steps can reproduce the bug?

run bun segfault.js and the source of bun segfault.js contains:

import { pipeline } from "@xenova/transformers";
export class SmolVector {
  store = [];
  similarityFn = (a, b) => dot(a, b) / (norm(a) * norm(b));
  constructor(extractor) {
    (async () => {
      this.extractor =
        extractor ??
        (await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2"));
      console.log("hiiii");
    })();
  }
  async add(objects) {
    // in parallel, check if item already has an embedding, and if not, run it through extractor
    await Promise.all(
      objects.map(async (object) => {
        if (typeof object === "string") object = { chunk: object }; // reformat it
        object.id = object.id ?? randID();
        object.embedding =
          object.embedding ?? (await this.extractor(object.chunk).data);
        this.store.push(object);
      })
    );
  }
}

const myDB = new SmolVector();
await myDB.add([
  "strawberry",
  "mango",
  "pineapple",
  "duck",
  "dog",
  "horse",
  "armadillo",
]);

What is the expected behavior?

code should just run

What do you see instead?

image

Additional information

No response

Jarred-Sumner commented 1 year ago

Can you try upgrading to v1.0.3 and see if it reproduces? We fixed crashes like this in-between

swyxio commented 1 year ago

unfortunately yes image

Jarred-Sumner commented 1 year ago

Definitely a napi bug

wzulfikar commented 1 year ago

This should be duplicate of https://github.com/oven-sh/bun/issues/4619 (and perhaps https://github.com/oven-sh/bun/issues/3574)? Been keeping a tab on both because can't wait to try transformers with Bun ❤️

Electroid commented 1 year ago

Duplicate of https://github.com/oven-sh/bun/issues/4619