gelu.https.any.js (20101B)
1 // META: title=test WebNN API gelu 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-gelu-method 12 // Compute the gaussian error linear unit function (GELU) of the input tensor. 13 // The calculation follows the expression 0.5 * x * (1 + erf(x / sqrt(2))). 14 // 15 // MLOperand gelu(MLOperand input); 16 17 const geluTests = [ 18 { 19 'name': 'gelu float32 0D scalar', 20 'graph': { 21 'inputs': { 22 'geluInput': { 23 'data': [-0.044885843992233276], 24 'descriptor': {shape: [], dataType: 'float32'} 25 } 26 }, 27 'operators': [{ 28 'name': 'gelu', 29 'arguments': [{'input': 'geluInput'}], 30 'outputs': 'geluOutput' 31 }], 32 'expectedOutputs': { 33 'geluOutput': { 34 'data': [-0.021639423444867134], 35 'descriptor': {shape: [], dataType: 'float32'} 36 } 37 } 38 } 39 }, 40 { 41 'name': 'gelu float16 0D scalar', 42 'graph': { 43 'inputs': { 44 'geluInput': { 45 'data': [-0.044891357421875], 46 'descriptor': {shape: [], dataType: 'float16'} 47 } 48 }, 49 'operators': [{ 50 'name': 'gelu', 51 'arguments': [{'input': 'geluInput'}], 52 'outputs': 'geluOutput' 53 }], 54 'expectedOutputs': { 55 'geluOutput': { 56 'data': [-0.021636962890625], 57 'descriptor': {shape: [], dataType: 'float16'} 58 } 59 } 60 } 61 }, 62 { 63 'name': 'gelu float32 1D tensor', 64 'graph': { 65 'inputs': { 66 'geluInput': { 67 'data': [ 68 0.878292441368103, -0.09706497937440872, 0.1367187649011612, 69 0.46406492590904236, -0.26635801792144775, -0.8252315521240234, 70 0.8530909419059753, 0.3846154808998108, 0.6772316694259644, 71 -0.4811072051525116, 0.2983909249305725, 0.6777864098548889, 72 -0.526228129863739, 0.3497541546821594, -0.12918996810913086, 73 0.5853934288024902, -0.8950720429420471, 0.028302494436502457, 74 -0.09901237487792969, -0.8838679790496826, -0.596120297908783, 75 0.31863871216773987, 0.4794037640094757, -0.06489315629005432 76 ], 77 'descriptor': {shape: [24], dataType: 'float32'} 78 } 79 }, 80 'operators': [{ 81 'name': 'gelu', 82 'arguments': [{'input': 'geluInput'}], 83 'outputs': 'geluOutput' 84 }], 85 'expectedOutputs': { 86 'geluOutput': { 87 'data': [ 88 0.7115113139152527, -0.0447796992957592, 0.07579325884580612, 89 0.3149605691432953, -0.10520657151937485, -0.16885890066623688, 90 0.6851989030838013, 0.24989959597587585, 0.508513331413269, 91 -0.1516546905040741, 0.18419598042964935, 0.509049117565155, 92 -0.15753419697284698, 0.22270187735557556, -0.05795508995652199, 93 0.42198580503463745, -0.1659233123064041, 0.014470770955085754, 94 -0.04560155048966408, -0.1665063202381134, -0.1642593890428543, 95 0.19914908707141876, 0.3279957175254822, -0.030767757445573807 96 ], 97 'descriptor': {shape: [24], dataType: 'float32'} 98 } 99 } 100 } 101 }, 102 { 103 'name': 'gelu float32 1D constant tensor', 104 'graph': { 105 'inputs': { 106 'geluInput': { 107 'data': [ 108 0.878292441368103, -0.09706497937440872, 0.1367187649011612, 109 0.46406492590904236, -0.26635801792144775, -0.8252315521240234, 110 0.8530909419059753, 0.3846154808998108, 0.6772316694259644, 111 -0.4811072051525116, 0.2983909249305725, 0.6777864098548889, 112 -0.526228129863739, 0.3497541546821594, -0.12918996810913086, 113 0.5853934288024902, -0.8950720429420471, 0.028302494436502457, 114 -0.09901237487792969, -0.8838679790496826, -0.596120297908783, 115 0.31863871216773987, 0.4794037640094757, -0.06489315629005432 116 ], 117 'descriptor': {shape: [24], dataType: 'float32'}, 118 'constant': true 119 } 120 }, 121 'operators': [{ 122 'name': 'gelu', 123 'arguments': [{'input': 'geluInput'}], 124 'outputs': 'geluOutput' 125 }], 126 'expectedOutputs': { 127 'geluOutput': { 128 'data': [ 129 0.7115113139152527, -0.0447796992957592, 0.07579325884580612, 130 0.3149605691432953, -0.10520657151937485, -0.16885890066623688, 131 0.6851989030838013, 0.24989959597587585, 0.508513331413269, 132 -0.1516546905040741, 0.18419598042964935, 0.509049117565155, 133 -0.15753419697284698, 0.22270187735557556, -0.05795508995652199, 134 0.42198580503463745, -0.1659233123064041, 0.014470770955085754, 135 -0.04560155048966408, -0.1665063202381134, -0.1642593890428543, 136 0.19914908707141876, 0.3279957175254822, -0.030767757445573807 137 ], 138 'descriptor': {shape: [24], dataType: 'float32'} 139 } 140 } 141 } 142 }, 143 { 144 'name': 'gelu float16 1D tensor', 145 'graph': { 146 'inputs': { 147 'geluInput': { 148 'data': [ 149 0.87841796875, -0.0970458984375, 0.13671875, 150 0.464111328125, -0.266357421875, -0.8251953125, 151 0.85302734375, 0.384521484375, 0.67724609375, 152 -0.481201171875, 0.29833984375, 0.677734375, 153 -0.5263671875, 0.349853515625, -0.129150390625, 154 0.58544921875, -0.89501953125, 0.0283050537109375, 155 -0.0989990234375, -0.8837890625, -0.59619140625, 156 0.318603515625, 0.4794921875, -0.06488037109375 157 ], 158 'descriptor': {shape: [24], dataType: 'float16'} 159 } 160 }, 161 'operators': [{ 162 'name': 'gelu', 163 'arguments': [{'input': 'geluInput'}], 164 'outputs': 'geluOutput' 165 }], 166 'expectedOutputs': { 167 'geluOutput': { 168 'data': [ 169 0.71142578125, -0.044769287109375, 0.0758056640625, 170 0.31494140625, -0.105224609375, -0.1688232421875, 171 0.68505859375, 0.2498779296875, 0.50830078125, 172 -0.151611328125, 0.1842041015625, 0.5087890625, 173 -0.1575927734375, 0.2227783203125, -0.057952880859375, 174 0.422119140625, -0.1658935546875, 0.01447296142578125, 175 -0.04559326171875, -0.16650390625, -0.164306640625, 176 0.1990966796875, 0.328125, -0.03076171875 177 ], 178 'descriptor': {shape: [24], dataType: 'float16'} 179 } 180 } 181 } 182 }, 183 { 184 'name': 'gelu float32 2D tensor', 185 'graph': { 186 'inputs': { 187 'geluInput': { 188 'data': [ 189 0.878292441368103, -0.09706497937440872, 0.1367187649011612, 190 0.46406492590904236, -0.26635801792144775, -0.8252315521240234, 191 0.8530909419059753, 0.3846154808998108, 0.6772316694259644, 192 -0.4811072051525116, 0.2983909249305725, 0.6777864098548889, 193 -0.526228129863739, 0.3497541546821594, -0.12918996810913086, 194 0.5853934288024902, -0.8950720429420471, 0.028302494436502457, 195 -0.09901237487792969, -0.8838679790496826, -0.596120297908783, 196 0.31863871216773987, 0.4794037640094757, -0.06489315629005432 197 ], 198 'descriptor': {shape: [4, 6], dataType: 'float32'} 199 } 200 }, 201 'operators': [{ 202 'name': 'gelu', 203 'arguments': [{'input': 'geluInput'}], 204 'outputs': 'geluOutput' 205 }], 206 'expectedOutputs': { 207 'geluOutput': { 208 'data': [ 209 0.7115113139152527, -0.0447796992957592, 0.07579325884580612, 210 0.3149605691432953, -0.10520657151937485, -0.16885890066623688, 211 0.6851989030838013, 0.24989959597587585, 0.508513331413269, 212 -0.1516546905040741, 0.18419598042964935, 0.509049117565155, 213 -0.15753419697284698, 0.22270187735557556, -0.05795508995652199, 214 0.42198580503463745, -0.1659233123064041, 0.014470770955085754, 215 -0.04560155048966408, -0.1665063202381134, -0.1642593890428543, 216 0.19914908707141876, 0.3279957175254822, -0.030767757445573807 217 ], 218 'descriptor': {shape: [4, 6], dataType: 'float32'} 219 } 220 } 221 } 222 }, 223 { 224 'name': 'gelu float16 2D tensor', 225 'graph': { 226 'inputs': { 227 'geluInput': { 228 'data': [ 229 0.87841796875, -0.0970458984375, 0.13671875, 230 0.464111328125, -0.266357421875, -0.8251953125, 231 0.85302734375, 0.384521484375, 0.67724609375, 232 -0.481201171875, 0.29833984375, 0.677734375, 233 -0.5263671875, 0.349853515625, -0.129150390625, 234 0.58544921875, -0.89501953125, 0.0283050537109375, 235 -0.0989990234375, -0.8837890625, -0.59619140625, 236 0.318603515625, 0.4794921875, -0.06488037109375 237 ], 238 'descriptor': {shape: [4, 6], dataType: 'float16'} 239 } 240 }, 241 'operators': [{ 242 'name': 'gelu', 243 'arguments': [{'input': 'geluInput'}], 244 'outputs': 'geluOutput' 245 }], 246 'expectedOutputs': { 247 'geluOutput': { 248 'data': [ 249 0.71142578125, -0.044769287109375, 0.0758056640625, 250 0.31494140625, -0.105224609375, -0.1688232421875, 251 0.68505859375, 0.2498779296875, 0.50830078125, 252 -0.151611328125, 0.1842041015625, 0.5087890625, 253 -0.1575927734375, 0.2227783203125, -0.057952880859375, 254 0.422119140625, -0.1658935546875, 0.01447296142578125, 255 -0.04559326171875, -0.16650390625, -0.164306640625, 256 0.1990966796875, 0.328125, -0.03076171875 257 ], 258 'descriptor': {shape: [4, 6], dataType: 'float16'} 259 } 260 } 261 } 262 }, 263 { 264 'name': 'gelu float32 3D tensor', 265 'graph': { 266 'inputs': { 267 'geluInput': { 268 'data': [ 269 0.878292441368103, -0.09706497937440872, 0.1367187649011612, 270 0.46406492590904236, -0.26635801792144775, -0.8252315521240234, 271 0.8530909419059753, 0.3846154808998108, 0.6772316694259644, 272 -0.4811072051525116, 0.2983909249305725, 0.6777864098548889, 273 -0.526228129863739, 0.3497541546821594, -0.12918996810913086, 274 0.5853934288024902, -0.8950720429420471, 0.028302494436502457, 275 -0.09901237487792969, -0.8838679790496826, -0.596120297908783, 276 0.31863871216773987, 0.4794037640094757, -0.06489315629005432 277 ], 278 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 279 } 280 }, 281 'operators': [{ 282 'name': 'gelu', 283 'arguments': [{'input': 'geluInput'}], 284 'outputs': 'geluOutput' 285 }], 286 'expectedOutputs': { 287 'geluOutput': { 288 'data': [ 289 0.7115113139152527, -0.0447796992957592, 0.07579325884580612, 290 0.3149605691432953, -0.10520657151937485, -0.16885890066623688, 291 0.6851989030838013, 0.24989959597587585, 0.508513331413269, 292 -0.1516546905040741, 0.18419598042964935, 0.509049117565155, 293 -0.15753419697284698, 0.22270187735557556, -0.05795508995652199, 294 0.42198580503463745, -0.1659233123064041, 0.014470770955085754, 295 -0.04560155048966408, -0.1665063202381134, -0.1642593890428543, 296 0.19914908707141876, 0.3279957175254822, -0.030767757445573807 297 ], 298 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 299 } 300 } 301 } 302 }, 303 { 304 'name': 'gelu float16 3D tensor', 305 'graph': { 306 'inputs': { 307 'geluInput': { 308 'data': [ 309 0.87841796875, -0.0970458984375, 0.13671875, 310 0.464111328125, -0.266357421875, -0.8251953125, 311 0.85302734375, 0.384521484375, 0.67724609375, 312 -0.481201171875, 0.29833984375, 0.677734375, 313 -0.5263671875, 0.349853515625, -0.129150390625, 314 0.58544921875, -0.89501953125, 0.0283050537109375, 315 -0.0989990234375, -0.8837890625, -0.59619140625, 316 0.318603515625, 0.4794921875, -0.06488037109375 317 ], 318 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 319 } 320 }, 321 'operators': [{ 322 'name': 'gelu', 323 'arguments': [{'input': 'geluInput'}], 324 'outputs': 'geluOutput' 325 }], 326 'expectedOutputs': { 327 'geluOutput': { 328 'data': [ 329 0.71142578125, -0.044769287109375, 0.0758056640625, 330 0.31494140625, -0.105224609375, -0.1688232421875, 331 0.68505859375, 0.2498779296875, 0.50830078125, 332 -0.151611328125, 0.1842041015625, 0.5087890625, 333 -0.1575927734375, 0.2227783203125, -0.057952880859375, 334 0.422119140625, -0.1658935546875, 0.01447296142578125, 335 -0.04559326171875, -0.16650390625, -0.164306640625, 336 0.1990966796875, 0.328125, -0.03076171875 337 ], 338 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 339 } 340 } 341 } 342 }, 343 { 344 'name': 'gelu float32 4D tensor', 345 'graph': { 346 'inputs': { 347 'geluInput': { 348 'data': [ 349 0.878292441368103, -0.09706497937440872, 0.1367187649011612, 350 0.46406492590904236, -0.26635801792144775, -0.8252315521240234, 351 0.8530909419059753, 0.3846154808998108, 0.6772316694259644, 352 -0.4811072051525116, 0.2983909249305725, 0.6777864098548889, 353 -0.526228129863739, 0.3497541546821594, -0.12918996810913086, 354 0.5853934288024902, -0.8950720429420471, 0.028302494436502457, 355 -0.09901237487792969, -0.8838679790496826, -0.596120297908783, 356 0.31863871216773987, 0.4794037640094757, -0.06489315629005432 357 ], 358 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 359 } 360 }, 361 'operators': [{ 362 'name': 'gelu', 363 'arguments': [{'input': 'geluInput'}], 364 'outputs': 'geluOutput' 365 }], 366 'expectedOutputs': { 367 'geluOutput': { 368 'data': [ 369 0.7115113139152527, -0.0447796992957592, 0.07579325884580612, 370 0.3149605691432953, -0.10520657151937485, -0.16885890066623688, 371 0.6851989030838013, 0.24989959597587585, 0.508513331413269, 372 -0.1516546905040741, 0.18419598042964935, 0.509049117565155, 373 -0.15753419697284698, 0.22270187735557556, -0.05795508995652199, 374 0.42198580503463745, -0.1659233123064041, 0.014470770955085754, 375 -0.04560155048966408, -0.1665063202381134, -0.1642593890428543, 376 0.19914908707141876, 0.3279957175254822, -0.030767757445573807 377 ], 378 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 379 } 380 } 381 } 382 }, 383 { 384 'name': 'gelu float16 4D tensor', 385 'graph': { 386 'inputs': { 387 'geluInput': { 388 'data': [ 389 0.87841796875, -0.0970458984375, 0.13671875, 390 0.464111328125, -0.266357421875, -0.8251953125, 391 0.85302734375, 0.384521484375, 0.67724609375, 392 -0.481201171875, 0.29833984375, 0.677734375, 393 -0.5263671875, 0.349853515625, -0.129150390625, 394 0.58544921875, -0.89501953125, 0.0283050537109375, 395 -0.0989990234375, -0.8837890625, -0.59619140625, 396 0.318603515625, 0.4794921875, -0.06488037109375 397 ], 398 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 399 } 400 }, 401 'operators': [{ 402 'name': 'gelu', 403 'arguments': [{'input': 'geluInput'}], 404 'outputs': 'geluOutput' 405 }], 406 'expectedOutputs': { 407 'geluOutput': { 408 'data': [ 409 0.71142578125, -0.044769287109375, 0.0758056640625, 410 0.31494140625, -0.105224609375, -0.1688232421875, 411 0.68505859375, 0.2498779296875, 0.50830078125, 412 -0.151611328125, 0.1842041015625, 0.5087890625, 413 -0.1575927734375, 0.2227783203125, -0.057952880859375, 414 0.422119140625, -0.1658935546875, 0.01447296142578125, 415 -0.04559326171875, -0.16650390625, -0.164306640625, 416 0.1990966796875, 0.328125, -0.03076171875 417 ], 418 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 419 } 420 } 421 } 422 }, 423 { 424 'name': 'gelu float32 5D tensor', 425 'graph': { 426 'inputs': { 427 'geluInput': { 428 'data': [ 429 0.878292441368103, -0.09706497937440872, 0.1367187649011612, 430 0.46406492590904236, -0.26635801792144775, -0.8252315521240234, 431 0.8530909419059753, 0.3846154808998108, 0.6772316694259644, 432 -0.4811072051525116, 0.2983909249305725, 0.6777864098548889, 433 -0.526228129863739, 0.3497541546821594, -0.12918996810913086, 434 0.5853934288024902, -0.8950720429420471, 0.028302494436502457, 435 -0.09901237487792969, -0.8838679790496826, -0.596120297908783, 436 0.31863871216773987, 0.4794037640094757, -0.06489315629005432 437 ], 438 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 439 } 440 }, 441 'operators': [{ 442 'name': 'gelu', 443 'arguments': [{'input': 'geluInput'}], 444 'outputs': 'geluOutput' 445 }], 446 'expectedOutputs': { 447 'geluOutput': { 448 'data': [ 449 0.7115113139152527, -0.0447796992957592, 0.07579325884580612, 450 0.3149605691432953, -0.10520657151937485, -0.16885890066623688, 451 0.6851989030838013, 0.24989959597587585, 0.508513331413269, 452 -0.1516546905040741, 0.18419598042964935, 0.509049117565155, 453 -0.15753419697284698, 0.22270187735557556, -0.05795508995652199, 454 0.42198580503463745, -0.1659233123064041, 0.014470770955085754, 455 -0.04560155048966408, -0.1665063202381134, -0.1642593890428543, 456 0.19914908707141876, 0.3279957175254822, -0.030767757445573807 457 ], 458 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 459 } 460 } 461 } 462 }, 463 { 464 'name': 'gelu float16 5D tensor', 465 'graph': { 466 'inputs': { 467 'geluInput': { 468 'data': [ 469 0.87841796875, -0.0970458984375, 0.13671875, 470 0.464111328125, -0.266357421875, -0.8251953125, 471 0.85302734375, 0.384521484375, 0.67724609375, 472 -0.481201171875, 0.29833984375, 0.677734375, 473 -0.5263671875, 0.349853515625, -0.129150390625, 474 0.58544921875, -0.89501953125, 0.0283050537109375, 475 -0.0989990234375, -0.8837890625, -0.59619140625, 476 0.318603515625, 0.4794921875, -0.06488037109375 477 ], 478 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 479 } 480 }, 481 'operators': [{ 482 'name': 'gelu', 483 'arguments': [{'input': 'geluInput'}], 484 'outputs': 'geluOutput' 485 }], 486 'expectedOutputs': { 487 'geluOutput': { 488 'data': [ 489 0.71142578125, -0.044769287109375, 0.0758056640625, 490 0.31494140625, -0.105224609375, -0.1688232421875, 491 0.68505859375, 0.2498779296875, 0.50830078125, 492 -0.151611328125, 0.1842041015625, 0.5087890625, 493 -0.1575927734375, 0.2227783203125, -0.057952880859375, 494 0.422119140625, -0.1658935546875, 0.01447296142578125, 495 -0.04559326171875, -0.16650390625, -0.164306640625, 496 0.1990966796875, 0.328125, -0.03076171875 497 ], 498 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 499 } 500 } 501 } 502 } 503 ]; 504 505 webnn_conformance_test(geluTests, buildAndExecuteGraph, getPrecisionTolerance);