tensorflow / tfjs

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

The output of tf.cumsum on the backend WebGL is inconsistent with the backend CPU and Wasm #8390

Open liliquan0118 opened 9 hours ago

liliquan0118 commented 9 hours 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 For the input [[[[[-1672471149.7300975,-530795317.03471804,259467238.8455038],[-924418735.9632776,-387431584.8705478,-415332721.42645335]],[[-435959596.1325941,87270152.07599401,-1380249186.2709687],[135697473.1746831,1596028660.3554802,-1774734717.169803]],[[112865951.29565954,-1202194093.7355595,-1875974817.5995176],[273815920.2089586,676385360.0321517,-419237697.803566]]]] and axis=1,

the output of tf.cumsum on the backend CPU and Wasm is:

[ [ [ [ -1672471168, -530795328, 259467232 ], [ -924418752, -387431584, -415332736 ] ], [ [ -2108430720, -443525184, -1120781952 ], [ -788721280, 1208597120, -2190067456 ] ], [ [ -1995564800, -1645719296, -2996756736 ], [ -514905344, 1884982528, -2609305088 ] ] ] ]

However, the output on the backend WebGL is:

[ [ [ [ -1672471168, -530795328, 259467232 ], [ -924418752, -387431584, -415332736 ] ], [ [ -2108430720, -443525184, -1120781952 ], [ -788721280, 1208597120, -2190067456 ] ], [ [ -1995564800, -1645719296, -2996756736 ], [ -514905344, 1884982400, -2609305088 ] ] ]]

Describe the expected behavior

consistent on 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>
</head>
<body>
<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>
<script>
    function cos(backend){
        tf.setBackend(backend);
        tf.ready().then(()=>{var input=[[[[-1672471149.7300975,-530795317.03471804,259467238.8455038],[-924418735.9632776,-387431584.8705478,-415332721.42645335]],[[-435959596.1325941,87270152.07599401,-1380249186.2709687],[135697473.1746831,1596028660.3554802,-1774734717.169803]],[[112865951.29565954,-1202194093.7355595,-1875974817.5995176],[273815920.2089586,676385360.0321517,-419237697.803566]]]]
            const result = tf.cumsum(input,1);
            console.log("the result of ", backend, "is:\n" );
            result.print();
        })
    }
    async function test() {
        await cos("webgl");
        await cos("cpu");
        await cos("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.

shmishra99 commented 3 hours ago

Hi @liliquan0118 ,

I've executed the code snippet you provided, and I'm receiving the expected same output across all backends (CPU, WASM, WebGL). I'm running the snippet on macOS 14.7 and my chrome version is 129.0.66

Ouptput:

image