tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.51k stars 1.94k forks source link

The output of the tf.conv1d operation on the WASM backend is inconsistent with the output on the WebGL and CPU backends #8403

Open liliquan0118 opened 1 month ago

liliquan0118 commented 1 month ago

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

Describe the current behavior

        var x = [[1330577513.2161741,-1921359847.6188612,-1794069072.8702362]]
        var filter = [[[109025596.11600018,-1264649391.5241914],[-1340376825.4206982,-1400198575.229503],[1509516682.11521,1309531766.3778458]]]
        var stride = 3
        var pad = 0
        var dataFormat = "NWC"
        var dilation = 1
        var dimRoundingMode = "floor"
        var result = tf.conv1d(x, filter,stride,pad,dataFormat,dilation,dimRoundingMode)
        console.log("the result of ", tf.getBackend(), "is:\n" );
        result.print();

The output results are inconsistent when executing the above code snippets on different backends. Output:

image

Describe the expected behavior

The output should be consistent across all backends.

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/CodePen/any notebook.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bug00</title>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.2.0/dist/tf.js"> </script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@4.2.0/dist/tf-backend-wasm.js"></script>
</head>
<body>

<script>
    async function conv1d(backend){
        await tf.setBackend(backend);
        await tf.ready() 
        var x = [[1330577513.2161741,-1921359847.6188612,-1794069072.8702362]]
        var filter = [[[109025596.11600018,-1264649391.5241914],[-1340376825.4206982,-1400198575.229503],[1509516682.11521,1309531766.3778458]]]
        var stride = 3
        var pad = 0
        var dataFormat = "NWC"
        var dilation = 1
        var dimRoundingMode = "floor"
        var result = await tf.conv1d(x, filter,stride,pad,dataFormat,dilation,dimRoundingMode);
        await console.log("the result of ", tf.getBackend(), "is:\n" );
        await result.print();
    }
    async function test() {
        await conv1d("cpu");
        await conv1d("webgl");
        await conv1d("wasm");
    }

    test();
</script>
</body>
</html>

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.