-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacOS 12.2.1 (21D62), M1
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: NA
- TensorFlow.js installed from (npm or script link): npm
- TensorFlow.js version (use command below): 3.18.0
- Browser version: NA
- Tensorflow.js Converter Version: NA
Describe the current behavior
When using tfjs for React Native, tfjs does not work when using hermes JavaScript engine. It works with the default jsc
engine.
It fails at instanceof Tensor
assertion, even though the constructor
is correctly identified as Tensor
:
Describe the expected behavior
tfjs should run without errors when using hermes
engine.
Standalone code to reproduce the issue
Minimum reproduction repo: https://github.com/paradite/tfjs-hermes-bug
- Install dependencies with
yarn
(it is not necessary to setup tfjs git submodule) - Run
npm run tfjs:node
- Runs tfjs code with Node.js
- Prints "result 2" without error
- Run
npm run tfjs:buildrun
- Bundles tfjs code with Metro
- Runs tfjs code with Hermes
- Gives the error "Uncaught Error: Argument 'x' passed to 'argMax' must be a Tensor or TensorLike, but got 'e'"
Other info / logs
I have tried a hacky fix and it seems to work:
Instead of using
if (x instanceof Tensor) {
assertDtype(parseAsDtype, x.dtype, argName, functionName);
return x;
}
, use
if (x instanceof Tensor || x.constructor.name === 'Tensor') {
assertDtype(parseAsDtype, x.dtype, argName, functionName);
return x;
}
mxmzb and a2f0