intel / webml-polyfill

Deprecated, the Web Neural Network Polyfill project has been moved to https://github.com/webmachinelearning/webnn-polyfill
Apache License 2.0
161 stars 42 forks source link

[webgl2] The output doesn't match the expected value for SOFTMAX operation #90

Closed BruceDai closed 6 years ago

BruceDai commented 6 years ago

Test Env: Chromium Version : nightly build 65.0.3324.0 (revision f9e1a31) OS : Mac OS webml-polyfill: commit be6d3ef

Expected Result: Set input_value is [1.0, 2.0, 10.0, 20.0], the output should be [0.25, 0.25, 0.25, 0.25] for SOFTMAX operation

Actual Result: The output doesn't match the expected:

AssertionError: expected false to be true
    at r.<anonymous> (cts/test/cts-all.js:2214:14)

output_expect: [0.25, 0.25, 0.25, 0.25] actual output:

0: 5.602543762250889e-9
1: 1.5229300487362707e-8
2: 0.000045397864596452564
3: 0.9999545812606812

How to reproduce:

  1. Launch chromium and disable the WebML
  2. Access to https://brucedai.github.io/nt/test/cts-all.html?backend=webgl2
  3. See the test: check result for Softmax float example/1

Test Case: https://raw.githubusercontent.com/BruceDai/nt/master/test/cts/test/cts-all.js:

it('check result for Softmax float example/1', async function() {
    let model = await nn.createModel(options);
    let operandIndex = 0;

    let input_value = [1.0, 2.0, 10.0, 20.0];
    let output_expect = [0.25, 0.25, 0.25, 0.25];

    let type1 = {type: nn.FLOAT32, dimensions: [1e-06]};
    let type1_length = product(type1.dimensions);
    let type0 = {type: nn.TENSOR_FLOAT32, dimensions: [1, 4]};
    let type0_length = product(type0.dimensions);

    let input = operandIndex++;
    model.addOperand(type0);
    let beta = operandIndex++;
    model.addOperand(type1);
    let output = operandIndex++;
    model.addOperand(type0);

    model.setOperandValue(beta, new Float32Array([1e-06]));
    model.addOperation(nn.SOFTMAX, [input, beta], [output]);

    model.identifyInputsAndOutputs([input], [output]);
    await model.finish();

    let compilation = await model.createCompilation();
    compilation.setPreference(nn.PREFER_FAST_SINGLE_ANSWER);
    await compilation.finish();

    let execution = await compilation.createExecution();

    let input_input = new Float32Array(input_value);
    execution.setInput(0, input_input);

    let output_output = new Float32Array(type0_length);
    execution.setOutput(0, output_output);

    await execution.startCompute();

    for (let i = 0; i < type0_length; ++i) {
      assert.isTrue(almostEqualCTS(output_output[i], output_expect[i]));
    }
  });
Christywl commented 6 years ago

Run the tests with the latest commit and update the results:

Test Env: Chromium Version : nightly build 65.0.3324.0 (revision 81edd55) OS : Mac OS webml-polyfill: commit ee18609

  1. The test in the description: check result for Softmax float example/1 --> failed due to #95, not this issue
  2. Another three tests failed due to this similar issue:
    check result for Depthwise conv2d float example             
    check result for Depthwise conv2d float large 2 weights as inputs example
    check result for Depthwise conv2d float weights as inputs example
GreyZzzzzzXh commented 6 years ago

Fixed. Parameter beta was unused in Softmax. Rerun and it works now.