tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

Kernel 'Erf' not registered for backend 'wasm' running a Transformer model

Open finiteautomata opened this issue 3 years ago • 1 comments

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): Yes, I have written custom code

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 22.04

  • TensorFlow.js installed from (npm or script link): npm

  • TensorFlow.js version (use command below): 3.19.0

  • Browser version: Chrome 104.0.5112.79 (Official Build) (64-bit)

  • Tensorflow.js Converter Version: 3.19.0

Describe the current behavior

I'm trying to run a Tf.js model converted from a huggingface/transformers model using the wasm backend. I made it work with JS backend, however, it fails running in the other case.

Describe the expected behavior

It should run ok

Standalone code to reproduce the issue

// Import @tensorflow/tfjs or @tensorflow/tfjs-core
const tf = require('@tensorflow/tfjs');
const {loadGraphModel} = require('@tensorflow/tfjs-converter');

require('@tensorflow/tfjs-backend-wasm');

tf.setBackend('wasm').then(() => main());

async function main() {
    console.log("Loading model...");
    const model = await loadGraphModel("https://raw.githubusercontent.com/finiteautomata/ner-leg-no-lfs/main/model.json");

    console.log("Done loading");
    inputIds = tf.tensor(
        Array(512).fill(1), undefined, "int32"
    );
    attentionMask = tf.tensor(
        Array(512).fill(1), undefined, "int32"
    );

    let modelInput = {
        "input_ids": inputIds.reshape([1, -1]),
        "attention_mask": attentionMask.reshape([1, -1]),
    }

    return model.predict(modelInput).squeeze(0);
}

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

/home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-backend-wasm/dist/tf-backend-wasm.node.js:6596
                    throw ex;
                    ^

Error: Kernel 'Erf' not registered for backend 'wasm'
    at Engine.runKernel (/home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4517:19)
    at erf_ (/home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:15506:19)
    at Object.erf__op [as erf] (/home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:11912:29)
    at executeOp$i (/home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:26755:25)
    at /home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:29088:50
    at /home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4445:22
    at Engine.scopedRun (/home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4455:23)
    at Engine.tidy (/home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4444:21)
    at tidy (/home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:8905:19)
    at /home/jmperez/projects/wasm-spectacles/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:29088:24

finiteautomata avatar Aug 09 '22 22:08 finiteautomata

It is not supported in wasm backend , currently it is supported in webgl and NodeJS only.

rthadur avatar Aug 09 '22 22:08 rthadur

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

google-ml-butler[bot] avatar Aug 16 '22 22:08 google-ml-butler[bot]

Closing as stale. Please @mention us if this needs more attention.

google-ml-butler[bot] avatar Aug 23 '22 23:08 google-ml-butler[bot]