-
Notifications
You must be signed in to change notification settings - Fork 912
Is it possible to run this in node? #4
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hi there. Yes, this is actually a known bug in onnx runtime web. (Similar problem to this: microsoft/onnxruntime#14445) You can fix it as follows: // 1. Fix "ReferenceError: self is not defined" bug when running directly with node
// https://github.com/microsoft/onnxruntime/issues/13072
global.self = global;
const { pipeline, env } = require('@xenova/transformers')
// 2. Disable spawning worker threads for testing.
// This is done by setting numThreads to 1
env.onnx.wasm.numThreads = 1
// 3. Continue as per usual:
// ... You can see a working example in the testing script: https://github.com/xenova/transformers.js/blob/main/tests/index.js (In that case, I also set There is seems to be a node-specific module for onnxruntime (https://www.npmjs.com/package/onnxruntime-node), but I haven't tested it. |
thanks, that made it work! are you planning to integrate onnxruntime-node in the future? would be cool to be able to choose |
(also seems like there's no caching when running this under node, so it redownloads the model every time) |
Yes, that is correct. At the moment, caching is only implemented with the Cache Web API, which is not available for node. I will hopefully add that functionality soon, so that it acts in a similar way to huggingface's system, which downloads it to your file system. In the meantime, I suggest you just download the model and place it in the |
Im getting the I have Importing using Any ideas how this would work in ts? |
Ah ok, those didn't work but it was hilarious. I'm actually using your tokenizer classes so that I may use onnxruntime-node without having to rewrite the tokenizer libraries for the various LLMs out there. This repo is awesome and you've been very responsive, so thanks so much for all the help! |
Great! 👍 No worries 😄 getting this version working out-of-the-box for node + typescript is on the TODO list :) |
I have this on the top of the file:
Actually CGPT suggested better approaches, since this will not fly in a strict: true codebase. |
I got this error when trying:
TypeError [ERR_WORKER_PATH]: The worker script or module filename must be an absolute path or a relative path starting with './' or '../'. Received "blob:nodedata:....
The text was updated successfully, but these errors were encountered: