tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

softplus.https.any.js (19564B)


      1 // META: title=test WebNN API softplus operation
      2 // META: global=window
      3 // META: variant=?cpu
      4 // META: variant=?gpu
      5 // META: variant=?npu
      6 // META: script=../resources/utils.js
      7 // META: timeout=long
      8 
      9 'use strict';
     10 
     11 // https://www.w3.org/TR/webnn/#api-mlgraphbuilder-softplus-method
     12 // Compute the softplus function of the input tensor. The calculation follows
     13 // the expression ln(1 + exp(x)).
     14 //
     15 // MLOperand softplus(MLOperand input);
     16 
     17 const softplusTests = [
     18  {
     19    'name': 'softplus float32 1D constant tensor',
     20    'graph': {
     21      'inputs': {
     22        'softplusInput': {
     23          'data': [
     24            5.626614570617676,   5.167487144470215, 4.0146355628967285,
     25            9.480032920837402,   9.989937782287598, 7.065441131591797,
     26            2.132680892944336,   8.187150955200195, 5.169976234436035,
     27            2.1044998168945312,  3.523329496383667, 4.136340618133545,
     28            1.741871953010559,   5.145224094390869, 5.015515327453613,
     29            0.04590393602848053, 2.957089900970459, 3.959244728088379,
     30            5.517927169799805,   7.192322254180908, 8.764925003051758,
     31            1.373470425605774,   8.930668830871582, 8.660283088684082
     32          ],
     33          'descriptor': {shape: [24], dataType: 'float32'},
     34          'constant': true
     35        }
     36      },
     37      'operators': [{
     38        'name': 'softplus',
     39        'arguments': [{'input': 'softplusInput'}],
     40        'outputs': 'softplusOutput'
     41      }],
     42      'expectedOutputs': {
     43        'softplusOutput': {
     44          'data': [
     45            5.630208969116211,  5.1731696128845215, 4.032524108886719,
     46            9.480109214782715,  9.989983558654785,  7.0662946701049805,
     47            2.2446866035461426, 8.187429428100586,  5.175644874572754,
     48            2.219529390335083,  3.552403688430786,  4.152195453643799,
     49            1.903303623199463,  5.151034355163574,  5.022127628326416,
     50            0.7163625359535217, 3.007754325866699,  3.978142499923706,
     51            5.521933078765869,  7.1930742263793945, 8.765081405639648,
     52            1.5991919040679932, 8.930801391601562,  8.660456657409668
     53          ],
     54          'descriptor': {shape: [24], dataType: 'float32'}
     55        }
     56      }
     57    }
     58  },
     59  {
     60    'name': 'softplus float32 0D tensor',
     61    'graph': {
     62      'inputs': {
     63        'softplusInput': {
     64          'data': [5.626614570617676],
     65          'descriptor': {shape: [], dataType: 'float32'}
     66        }
     67      },
     68      'operators': [{
     69        'name': 'softplus',
     70        'arguments': [{'input': 'softplusInput'}],
     71        'outputs': 'softplusOutput'
     72      }],
     73      'expectedOutputs': {
     74        'softplusOutput': {
     75          'data': [5.630208969116211],
     76          'descriptor': {shape: [], dataType: 'float32'}
     77        }
     78      }
     79    }
     80  },
     81  {
     82    'name': 'softplus float32 1D tensor',
     83    'graph': {
     84      'inputs': {
     85        'softplusInput': {
     86          'data': [
     87            5.626614570617676,   5.167487144470215, 4.0146355628967285,
     88            9.480032920837402,   9.989937782287598, 7.065441131591797,
     89            2.132680892944336,   8.187150955200195, 5.169976234436035,
     90            2.1044998168945312,  3.523329496383667, 4.136340618133545,
     91            1.741871953010559,   5.145224094390869, 5.015515327453613,
     92            0.04590393602848053, 2.957089900970459, 3.959244728088379,
     93            5.517927169799805,   7.192322254180908, 8.764925003051758,
     94            1.373470425605774,   8.930668830871582, 8.660283088684082
     95          ],
     96          'descriptor': {shape: [24], dataType: 'float32'}
     97        }
     98      },
     99      'operators': [{
    100        'name': 'softplus',
    101        'arguments': [{'input': 'softplusInput'}],
    102        'outputs': 'softplusOutput'
    103      }],
    104      'expectedOutputs': {
    105        'softplusOutput': {
    106          'data': [
    107            5.630208969116211,  5.1731696128845215, 4.032524108886719,
    108            9.480109214782715,  9.989983558654785,  7.0662946701049805,
    109            2.2446866035461426, 8.187429428100586,  5.175644874572754,
    110            2.219529390335083,  3.552403688430786,  4.152195453643799,
    111            1.903303623199463,  5.151034355163574,  5.022127628326416,
    112            0.7163625359535217, 3.007754325866699,  3.978142499923706,
    113            5.521933078765869,  7.1930742263793945, 8.765081405639648,
    114            1.5991919040679932, 8.930801391601562,  8.660456657409668
    115          ],
    116          'descriptor': {shape: [24], dataType: 'float32'}
    117        }
    118      }
    119    }
    120  },
    121  {
    122    'name': 'softplus float32 2D tensor',
    123    'graph': {
    124      'inputs': {
    125        'softplusInput': {
    126          'data': [
    127            5.626614570617676,   5.167487144470215, 4.0146355628967285,
    128            9.480032920837402,   9.989937782287598, 7.065441131591797,
    129            2.132680892944336,   8.187150955200195, 5.169976234436035,
    130            2.1044998168945312,  3.523329496383667, 4.136340618133545,
    131            1.741871953010559,   5.145224094390869, 5.015515327453613,
    132            0.04590393602848053, 2.957089900970459, 3.959244728088379,
    133            5.517927169799805,   7.192322254180908, 8.764925003051758,
    134            1.373470425605774,   8.930668830871582, 8.660283088684082
    135          ],
    136          'descriptor': {shape: [4, 6], dataType: 'float32'}
    137        }
    138      },
    139      'operators': [{
    140        'name': 'softplus',
    141        'arguments': [{'input': 'softplusInput'}],
    142        'outputs': 'softplusOutput'
    143      }],
    144      'expectedOutputs': {
    145        'softplusOutput': {
    146          'data': [
    147            5.630208969116211,  5.1731696128845215, 4.032524108886719,
    148            9.480109214782715,  9.989983558654785,  7.0662946701049805,
    149            2.2446866035461426, 8.187429428100586,  5.175644874572754,
    150            2.219529390335083,  3.552403688430786,  4.152195453643799,
    151            1.903303623199463,  5.151034355163574,  5.022127628326416,
    152            0.7163625359535217, 3.007754325866699,  3.978142499923706,
    153            5.521933078765869,  7.1930742263793945, 8.765081405639648,
    154            1.5991919040679932, 8.930801391601562,  8.660456657409668
    155          ],
    156          'descriptor': {shape: [4, 6], dataType: 'float32'}
    157        }
    158      }
    159    }
    160  },
    161  {
    162    'name': 'softplus float32 3D tensor',
    163    'graph': {
    164      'inputs': {
    165        'softplusInput': {
    166          'data': [
    167            5.626614570617676,   5.167487144470215, 4.0146355628967285,
    168            9.480032920837402,   9.989937782287598, 7.065441131591797,
    169            2.132680892944336,   8.187150955200195, 5.169976234436035,
    170            2.1044998168945312,  3.523329496383667, 4.136340618133545,
    171            1.741871953010559,   5.145224094390869, 5.015515327453613,
    172            0.04590393602848053, 2.957089900970459, 3.959244728088379,
    173            5.517927169799805,   7.192322254180908, 8.764925003051758,
    174            1.373470425605774,   8.930668830871582, 8.660283088684082
    175          ],
    176          'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
    177        }
    178      },
    179      'operators': [{
    180        'name': 'softplus',
    181        'arguments': [{'input': 'softplusInput'}],
    182        'outputs': 'softplusOutput'
    183      }],
    184      'expectedOutputs': {
    185        'softplusOutput': {
    186          'data': [
    187            5.630208969116211,  5.1731696128845215, 4.032524108886719,
    188            9.480109214782715,  9.989983558654785,  7.0662946701049805,
    189            2.2446866035461426, 8.187429428100586,  5.175644874572754,
    190            2.219529390335083,  3.552403688430786,  4.152195453643799,
    191            1.903303623199463,  5.151034355163574,  5.022127628326416,
    192            0.7163625359535217, 3.007754325866699,  3.978142499923706,
    193            5.521933078765869,  7.1930742263793945, 8.765081405639648,
    194            1.5991919040679932, 8.930801391601562,  8.660456657409668
    195          ],
    196          'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
    197        }
    198      }
    199    }
    200  },
    201  {
    202    'name': 'softplus float32 4D tensor',
    203    'graph': {
    204      'inputs': {
    205        'softplusInput': {
    206          'data': [
    207            5.626614570617676,   5.167487144470215, 4.0146355628967285,
    208            9.480032920837402,   9.989937782287598, 7.065441131591797,
    209            2.132680892944336,   8.187150955200195, 5.169976234436035,
    210            2.1044998168945312,  3.523329496383667, 4.136340618133545,
    211            1.741871953010559,   5.145224094390869, 5.015515327453613,
    212            0.04590393602848053, 2.957089900970459, 3.959244728088379,
    213            5.517927169799805,   7.192322254180908, 8.764925003051758,
    214            1.373470425605774,   8.930668830871582, 8.660283088684082
    215          ],
    216          'descriptor': {shape: [1, 2, 3, 4], dataType: 'float32'}
    217        }
    218      },
    219      'operators': [{
    220        'name': 'softplus',
    221        'arguments': [{'input': 'softplusInput'}],
    222        'outputs': 'softplusOutput'
    223      }],
    224      'expectedOutputs': {
    225        'softplusOutput': {
    226          'data': [
    227            5.630208969116211,  5.1731696128845215, 4.032524108886719,
    228            9.480109214782715,  9.989983558654785,  7.0662946701049805,
    229            2.2446866035461426, 8.187429428100586,  5.175644874572754,
    230            2.219529390335083,  3.552403688430786,  4.152195453643799,
    231            1.903303623199463,  5.151034355163574,  5.022127628326416,
    232            0.7163625359535217, 3.007754325866699,  3.978142499923706,
    233            5.521933078765869,  7.1930742263793945, 8.765081405639648,
    234            1.5991919040679932, 8.930801391601562,  8.660456657409668
    235          ],
    236          'descriptor': {shape: [1, 2, 3, 4], dataType: 'float32'}
    237        }
    238      }
    239    }
    240  },
    241  {
    242    'name': 'softplus float32 5D tensor',
    243    'graph': {
    244      'inputs': {
    245        'softplusInput': {
    246          'data': [
    247            5.626614570617676,   5.167487144470215, 4.0146355628967285,
    248            9.480032920837402,   9.989937782287598, 7.065441131591797,
    249            2.132680892944336,   8.187150955200195, 5.169976234436035,
    250            2.1044998168945312,  3.523329496383667, 4.136340618133545,
    251            1.741871953010559,   5.145224094390869, 5.015515327453613,
    252            0.04590393602848053, 2.957089900970459, 3.959244728088379,
    253            5.517927169799805,   7.192322254180908, 8.764925003051758,
    254            1.373470425605774,   8.930668830871582, 8.660283088684082
    255          ],
    256          'descriptor': {shape: [1, 2, 1, 3, 4], dataType: 'float32'}
    257        }
    258      },
    259      'operators': [{
    260        'name': 'softplus',
    261        'arguments': [{'input': 'softplusInput'}],
    262        'outputs': 'softplusOutput'
    263      }],
    264      'expectedOutputs': {
    265        'softplusOutput': {
    266          'data': [
    267            5.630208969116211,  5.1731696128845215, 4.032524108886719,
    268            9.480109214782715,  9.989983558654785,  7.0662946701049805,
    269            2.2446866035461426, 8.187429428100586,  5.175644874572754,
    270            2.219529390335083,  3.552403688430786,  4.152195453643799,
    271            1.903303623199463,  5.151034355163574,  5.022127628326416,
    272            0.7163625359535217, 3.007754325866699,  3.978142499923706,
    273            5.521933078765869,  7.1930742263793945, 8.765081405639648,
    274            1.5991919040679932, 8.930801391601562,  8.660456657409668
    275          ],
    276          'descriptor': {shape: [1, 2, 1, 3, 4], dataType: 'float32'}
    277        }
    278      }
    279    }
    280  },
    281 
    282  // float16 tests
    283  {
    284    'name': 'softplus float16 1D constant tensor',
    285    'graph': {
    286      'inputs': {
    287        'softplusInput': {
    288          'data': [
    289            5.625,        5.16796875,  4.015625,    9.4765625,  9.9921875,
    290            7.06640625,   2.1328125,   8.1875,      5.171875,   2.10546875,
    291            3.5234375,    4.13671875,  1.7421875,   5.14453125, 5.015625,
    292            0.0458984375, 2.95703125,  3.958984375, 5.51953125, 7.19140625,
    293            8.765625,     1.373046875, 8.9296875,   8.6640625
    294          ],
    295          'descriptor': {shape: [24], dataType: 'float16'},
    296          'constant': true
    297        }
    298      },
    299      'operators': [{
    300        'name': 'softplus',
    301        'arguments': [{'input': 'softplusInput'}],
    302        'outputs': 'softplusOutput'
    303      }],
    304      'expectedOutputs': {
    305        'softplusOutput': {
    306          'data': [
    307            5.62890625,    5.171875,     4.03515625,   9.4765625,  9.9921875,
    308            7.06640625,    2.244140625,  8.1875,       5.17578125, 2.220703125,
    309            3.552734375,   4.15234375,   1.9033203125, 5.1484375,  5.0234375,
    310            0.71630859375, 3.0078125,    3.978515625,  5.5234375,  7.19140625,
    311            8.765625,      1.5986328125, 8.9296875,    8.6640625
    312          ],
    313          'descriptor': {shape: [24], dataType: 'float16'}
    314        }
    315      }
    316    }
    317  },
    318  {
    319    'name': 'softplus float16 0D tensor',
    320    'graph': {
    321      'inputs': {
    322        'softplusInput':
    323            {'data': [5.625], 'descriptor': {shape: [], dataType: 'float16'}}
    324      },
    325      'operators': [{
    326        'name': 'softplus',
    327        'arguments': [{'input': 'softplusInput'}],
    328        'outputs': 'softplusOutput'
    329      }],
    330      'expectedOutputs': {
    331        'softplusOutput': {
    332          'data': [5.62890625],
    333          'descriptor': {shape: [], dataType: 'float16'}
    334        }
    335      }
    336    }
    337  },
    338  {
    339    'name': 'softplus float16 1D tensor',
    340    'graph': {
    341      'inputs': {
    342        'softplusInput': {
    343          'data': [
    344            5.625,        5.16796875,  4.015625,    9.4765625,  9.9921875,
    345            7.06640625,   2.1328125,   8.1875,      5.171875,   2.10546875,
    346            3.5234375,    4.13671875,  1.7421875,   5.14453125, 5.015625,
    347            0.0458984375, 2.95703125,  3.958984375, 5.51953125, 7.19140625,
    348            8.765625,     1.373046875, 8.9296875,   8.6640625
    349          ],
    350          'descriptor': {shape: [24], dataType: 'float16'}
    351        }
    352      },
    353      'operators': [{
    354        'name': 'softplus',
    355        'arguments': [{'input': 'softplusInput'}],
    356        'outputs': 'softplusOutput'
    357      }],
    358      'expectedOutputs': {
    359        'softplusOutput': {
    360          'data': [
    361            5.62890625,    5.171875,     4.03515625,   9.4765625,  9.9921875,
    362            7.06640625,    2.244140625,  8.1875,       5.17578125, 2.220703125,
    363            3.552734375,   4.15234375,   1.9033203125, 5.1484375,  5.0234375,
    364            0.71630859375, 3.0078125,    3.978515625,  5.5234375,  7.19140625,
    365            8.765625,      1.5986328125, 8.9296875,    8.6640625
    366          ],
    367          'descriptor': {shape: [24], dataType: 'float16'}
    368        }
    369      }
    370    }
    371  },
    372  {
    373    'name': 'softplus float16 2D tensor',
    374    'graph': {
    375      'inputs': {
    376        'softplusInput': {
    377          'data': [
    378            5.625,        5.16796875,  4.015625,    9.4765625,  9.9921875,
    379            7.06640625,   2.1328125,   8.1875,      5.171875,   2.10546875,
    380            3.5234375,    4.13671875,  1.7421875,   5.14453125, 5.015625,
    381            0.0458984375, 2.95703125,  3.958984375, 5.51953125, 7.19140625,
    382            8.765625,     1.373046875, 8.9296875,   8.6640625
    383          ],
    384          'descriptor': {shape: [4, 6], dataType: 'float16'}
    385        }
    386      },
    387      'operators': [{
    388        'name': 'softplus',
    389        'arguments': [{'input': 'softplusInput'}],
    390        'outputs': 'softplusOutput'
    391      }],
    392      'expectedOutputs': {
    393        'softplusOutput': {
    394          'data': [
    395            5.62890625,    5.171875,     4.03515625,   9.4765625,  9.9921875,
    396            7.06640625,    2.244140625,  8.1875,       5.17578125, 2.220703125,
    397            3.552734375,   4.15234375,   1.9033203125, 5.1484375,  5.0234375,
    398            0.71630859375, 3.0078125,    3.978515625,  5.5234375,  7.19140625,
    399            8.765625,      1.5986328125, 8.9296875,    8.6640625
    400          ],
    401          'descriptor': {shape: [4, 6], dataType: 'float16'}
    402        }
    403      }
    404    }
    405  },
    406  {
    407    'name': 'softplus float16 3D tensor',
    408    'graph': {
    409      'inputs': {
    410        'softplusInput': {
    411          'data': [
    412            5.625,        5.16796875,  4.015625,    9.4765625,  9.9921875,
    413            7.06640625,   2.1328125,   8.1875,      5.171875,   2.10546875,
    414            3.5234375,    4.13671875,  1.7421875,   5.14453125, 5.015625,
    415            0.0458984375, 2.95703125,  3.958984375, 5.51953125, 7.19140625,
    416            8.765625,     1.373046875, 8.9296875,   8.6640625
    417          ],
    418          'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
    419        }
    420      },
    421      'operators': [{
    422        'name': 'softplus',
    423        'arguments': [{'input': 'softplusInput'}],
    424        'outputs': 'softplusOutput'
    425      }],
    426      'expectedOutputs': {
    427        'softplusOutput': {
    428          'data': [
    429            5.62890625,    5.171875,     4.03515625,   9.4765625,  9.9921875,
    430            7.06640625,    2.244140625,  8.1875,       5.17578125, 2.220703125,
    431            3.552734375,   4.15234375,   1.9033203125, 5.1484375,  5.0234375,
    432            0.71630859375, 3.0078125,    3.978515625,  5.5234375,  7.19140625,
    433            8.765625,      1.5986328125, 8.9296875,    8.6640625
    434          ],
    435          'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
    436        }
    437      }
    438    }
    439  },
    440  {
    441    'name': 'softplus float16 4D tensor',
    442    'graph': {
    443      'inputs': {
    444        'softplusInput': {
    445          'data': [
    446            5.625,        5.16796875,  4.015625,    9.4765625,  9.9921875,
    447            7.06640625,   2.1328125,   8.1875,      5.171875,   2.10546875,
    448            3.5234375,    4.13671875,  1.7421875,   5.14453125, 5.015625,
    449            0.0458984375, 2.95703125,  3.958984375, 5.51953125, 7.19140625,
    450            8.765625,     1.373046875, 8.9296875,   8.6640625
    451          ],
    452          'descriptor': {shape: [1, 2, 3, 4], dataType: 'float16'}
    453        }
    454      },
    455      'operators': [{
    456        'name': 'softplus',
    457        'arguments': [{'input': 'softplusInput'}],
    458        'outputs': 'softplusOutput'
    459      }],
    460      'expectedOutputs': {
    461        'softplusOutput': {
    462          'data': [
    463            5.62890625,    5.171875,     4.03515625,   9.4765625,  9.9921875,
    464            7.06640625,    2.244140625,  8.1875,       5.17578125, 2.220703125,
    465            3.552734375,   4.15234375,   1.9033203125, 5.1484375,  5.0234375,
    466            0.71630859375, 3.0078125,    3.978515625,  5.5234375,  7.19140625,
    467            8.765625,      1.5986328125, 8.9296875,    8.6640625
    468          ],
    469          'descriptor': {shape: [1, 2, 3, 4], dataType: 'float16'}
    470        }
    471      }
    472    }
    473  },
    474  {
    475    'name': 'softplus float16 5D tensor',
    476    'graph': {
    477      'inputs': {
    478        'softplusInput': {
    479          'data': [
    480            5.625,        5.16796875,  4.015625,    9.4765625,  9.9921875,
    481            7.06640625,   2.1328125,   8.1875,      5.171875,   2.10546875,
    482            3.5234375,    4.13671875,  1.7421875,   5.14453125, 5.015625,
    483            0.0458984375, 2.95703125,  3.958984375, 5.51953125, 7.19140625,
    484            8.765625,     1.373046875, 8.9296875,   8.6640625
    485          ],
    486          'descriptor': {shape: [1, 2, 1, 3, 4], dataType: 'float16'}
    487        }
    488      },
    489      'operators': [{
    490        'name': 'softplus',
    491        'arguments': [{'input': 'softplusInput'}],
    492        'outputs': 'softplusOutput'
    493      }],
    494      'expectedOutputs': {
    495        'softplusOutput': {
    496          'data': [
    497            5.62890625,    5.171875,     4.03515625,   9.4765625,  9.9921875,
    498            7.06640625,    2.244140625,  8.1875,       5.17578125, 2.220703125,
    499            3.552734375,   4.15234375,   1.9033203125, 5.1484375,  5.0234375,
    500            0.71630859375, 3.0078125,    3.978515625,  5.5234375,  7.19140625,
    501            8.765625,      1.5986328125, 8.9296875,    8.6640625
    502          ],
    503          'descriptor': {shape: [1, 2, 1, 3, 4], dataType: 'float16'}
    504        }
    505      }
    506    }
    507  }
    508 ];
    509 
    510 webnn_conformance_test(
    511    softplusTests, buildAndExecuteGraph, getPrecisionTolerance);