-
Notifications
You must be signed in to change notification settings - Fork 921
TypeError: A float32 tensor's data must be type of function Float32Array() when running under jest #57
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
Comments
Well that is quite strange indeed. Does jest have a certain layout/structure that must be followed? Edit: After looking at their getting started docs, it does seem like it should be in a certain format. That said, the error message you get seems very unrelated. Could you try use the same structure they do, and see if it works then? |
Yeah, I get the same error after following the setup described in the getting started docs. I put the transformers code into the This is where the error comes from: https://github.com/microsoft/onnxruntime-openenclave/blob/bdc51bfe62822b2acd190c3bc98bfc92babf24e5/nodejs/lib/tensor-impl.ts#L100
and |
Is there a reason you are referencing the openenclave repo (which seems to be a public repo)? Isn't the correct source is located here? I'll try debugging on my side too 👍 |
That was a mistake linking to the openclave repo - I searched across github for org:microsoft "tensor's data must be type of" and that was the only reference. |
I figured out the source of this: https://backend.cafe/should-you-use-jest-as-a-testing-library jest creates a separate context to run in so it can provide features for testing (mocking, fake timers, etc.). By following the fix in the article:
the error above goes away. |
Well that is very interesting (and strange 👀)... Thanks for getting back to us! On another note, it would probably be quite good to use a solid testing framework (like Jest) for this library. So, it's good to get this problem sorted out haha! |
…shared in jest context isolation The way chromadb imports @xenova/transformers package in file chromadb/src/embeddings/TransformersEmbeddingFunction.ts:33 makes it result in random segment fault errors terminating the tests prematurely. This fix contains a code that bypasses chromadb package and directly uses the @xenova/transformers package Due to how jest isolates the context of each running test (huggingface/transformers.js#57, https://github.com/kayahr/jest-environment-node-single-context, jestjs/jest#2549) - it makes it impossible for onnxruntime-node package to validate the array passed as an input to it is actually an `instanceof Float32Array` type. The `instanceof` results in false because the globals are different between context. This commit shares the Float32Array global between each context.
…shared in jest context isolation (#2487) * Local embeddings function with Transformer.js API * added packages * Adds integration test, update naming and deps * Formatting * Fix random test fails due to segfault by chromadb & Float32Array not shared in jest context isolation The way chromadb imports @xenova/transformers package in file chromadb/src/embeddings/TransformersEmbeddingFunction.ts:33 makes it result in random segment fault errors terminating the tests prematurely. This fix contains a code that bypasses chromadb package and directly uses the @xenova/transformers package Due to how jest isolates the context of each running test (huggingface/transformers.js#57, https://github.com/kayahr/jest-environment-node-single-context, jestjs/jest#2549) - it makes it impossible for onnxruntime-node package to validate the array passed as an input to it is actually an `instanceof Float32Array` type. The `instanceof` results in false because the globals are different between context. This commit shares the Float32Array global between each context. * Update deps * Docs change * Add entrypoint * Fix concurrency * Docs update * Fix docs typo --------- Co-authored-by: l4b4r4b4b4 <[email protected]> Co-authored-by: Lucas Hänke de Cansino <[email protected]> Co-authored-by: jacoblee93 <[email protected]> Co-authored-by: Juraj Carnogursky <[email protected]>
Thanks for pointing me to the solution! In my case and to not change the logic of my other tests, I put it specifically on top of my test file concerned by the issue: /**
* @jest-environment jest-environment-node-single-context
*/
describe(...); |
Uh oh!
There was an error while loading. Please reload this page.
Given the following script:
This will execute without error when running the following from the shell
But if the same script is executed using jest, I receive the following error:
This appears to be related to the choice of the ONNX runtime. If this line: https://github.com/xenova/transformers.js/blob/main/src/backends/onnx.js#L10 is changed to
onnxruntime-web
(instead of onnxruntime-node). Executing underjest
will now succeed, so there appears to be some issue with jest + onnxruntime-node. In terms of resolution, one option would be to detect withinbackends/onnx.js
whether execution is being done under jest, which can be done by checkingprocess.env.JEST_WORKER_ID
(this will be populated when running under jest). In terms of root cause, I'm not sure where the actual bug is (jest or onnxruntime-node), but it would make the most sense for it to be resolved there if its possible to determine which package is responsible.Steps to reproduce:
test.js
The text was updated successfully, but these errors were encountered: