Skip to content
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

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

Open
liliquan0118 opened this issue Oct 3, 2024 · 0 comments

Comments

@liliquan0118
Copy link

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

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04, Macos 13.3 (22E252)
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow.js installed from (npm or script link): script link
  • TensorFlow.js version (use command below): 4.2.0
  • Browser version: Chrome Version 128.0.6613.86 (Official Build) (arm64)
  • Tensorflow.js Converter Version:

Describe the current behavior

        var x = [[[[-55252060.67834425],[-1395532753.3313174]],[[-1900887873.4283361],[1849199511.8539329]],[[-1651120644.9821556],[-717316274.5133562]]],[[[-1754143039.4744146],[-2037571445.5318842]],[[-876734283.0695686],[-1016013282.997565]],[[-1694713818.8164597],[5020083.504110336]]],[[[-696668774.0993726],[-1483492892.0050337]],[[-1312138111.135326],[1846275055.781304]],[[518421122.0682273],[1958117639.8003435]]]]
        var filter = [[[[1107800912.167666,-401586498.55178046]],[[-1711291031.3875177,1599554396.700231]],[[165709470.48837948,2001406787.0437903]]],[[[-1552451395.552168,21471914.956653118]],[[306168927.977036,821458758.7275877]],[[-1299505118.87527,-1314603671.687303]]],[[[394925353.1093707,629851142.9898896]],[[1446504391.7575645,1137950560.3345184]],[[1590637973.598412,1357443995.2777972]]]]
        var stride = [1,1]
        var pad = "same"
        var dataFormat = "NHWC"
        var dilation = 2
        var result = tf.conv2d(x, filter,stride,pad,dataFormat,dilation);
        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 on CPU backend:
image

Output on WebGL backend:
image

Output on WASM backend:
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/[email protected]/dist/tf.js"> </script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf-backend-wasm.js"></script>
</head>
<body>

<script>
    async function conv2d(backend){
        await tf.setBackend(backend);
        await tf.ready() 
        var x = [[[[-55252060.67834425],[-1395532753.3313174]],[[-1900887873.4283361],[1849199511.8539329]],[[-1651120644.9821556],[-717316274.5133562]]],[[[-1754143039.4744146],[-2037571445.5318842]],[[-876734283.0695686],[-1016013282.997565]],[[-1694713818.8164597],[5020083.504110336]]],[[[-696668774.0993726],[-1483492892.0050337]],[[-1312138111.135326],[1846275055.781304]],[[518421122.0682273],[1958117639.8003435]]]]
        var filter = [[[[1107800912.167666,-401586498.55178046]],[[-1711291031.3875177,1599554396.700231]],[[165709470.48837948,2001406787.0437903]]],[[[-1552451395.552168,21471914.956653118]],[[306168927.977036,821458758.7275877]],[[-1299505118.87527,-1314603671.687303]]],[[[394925353.1093707,629851142.9898896]],[[1446504391.7575645,1137950560.3345184]],[[1590637973.598412,1357443995.2777972]]]]
        var stride = [1,1]
        var pad = "same"
        var dataFormat = "NHWC"
        var dilation = 2
        var result = await tf.conv2d(x, filter,stride,pad,dataFormat,dilation);
        await console.log("the result of ", tf.getBackend(), "is:\n" );
        await result.print();
    }
    async function test() {
        await conv2d("cpu");
        await conv2d("webgl");
        await conv2d("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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants