layer_normalization.https.any.js (44601B)
1 // META: title=test WebNN API layerNormalization 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-layernorm 12 // Normalize the input using Layer-Normalization. 13 // 14 // dictionary MLLayerNormalizationOptions { 15 // MLOperand scale; 16 // MLOperand bias; 17 // sequence<[EnforceRange] unsigned long> axes; 18 // double epsilon = 1e-5; 19 // }; 20 // 21 // MLOperand layerNormalization( 22 // MLOperand input, optional MLLayerNormalizationOptions options = {}); 23 24 25 const getLayerNormPrecisionTolerance = (graphResources) => { 26 const toleranceValueDict = {float32: 14, float16: 30}; 27 const expectedDataType = 28 getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs); 29 return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]}; 30 }; 31 32 const layerNormTests = [ 33 { 34 'name': 'layerNormalization float32 0D tensor default options', 35 'graph': { 36 'inputs': { 37 'layerNormInput': { 38 'data': [-35.51446533203125], 39 'descriptor': {shape: [], dataType: 'float32'} 40 } 41 }, 42 'operators': [{ 43 'name': 'layerNormalization', 44 'arguments': [{'input': 'layerNormInput'}], 45 'outputs': 'layerNormOutput' 46 }], 47 'expectedOutputs': { 48 'layerNormOutput': 49 {'data': [0], 'descriptor': {shape: [], dataType: 'float32'}} 50 } 51 } 52 }, 53 { 54 'name': 'layerNormalization float32 2D tensor default options', 55 'graph': { 56 'inputs': { 57 'layerNormInput': { 58 'data': [ 59 -5.712825298309326, 1.4681644439697266, 6.143280029296875, 60 9.427258491516113, 2.0522539615631104, -8.829475402832031, 61 9.143593788146973, -7.643154144287109, -2.0325264930725098, 62 6.063992500305176, 4.094968318939209, 0.8910917043685913, 63 8.712732315063477, -0.0006124831270426512, 5.505736827850342, 64 -9.155109405517578, -9.89109992980957, 1.0480059385299683, 65 -5.925083637237549, 7.741676330566406, 0.700584352016449, 66 -5.662013530731201, 1.3204102516174316, 2.7849292755126953 67 ], 68 'descriptor': {shape: [4, 6], dataType: 'float32'} 69 } 70 }, 71 'operators': [{ 72 'name': 'layerNormalization', 73 'arguments': [{'input': 'layerNormInput'}], 74 'outputs': 'layerNormOutput' 75 }], 76 'expectedOutputs': { 77 'layerNormOutput': { 78 'data': [ 79 -1.0228718519210815, 0.11223962903022766, 0.8512431979179382, 80 1.3703473806381226, 0.20456767082214355, -1.5155260562896729, 81 1.3417094945907593, -1.705802321434021, -0.6872337460517883, 82 0.7826303243637085, 0.42516833543777466, -0.1564721316099167, 83 1.3518258333206177, 0.09107562154531479, 0.8877996206283569, 84 -1.2335057258605957, -1.3399975299835205, 0.2428021878004074, 85 -1.273769736289978, 1.58700692653656, 0.1131395623087883, 86 -1.2187029123306274, 0.2428838163614273, 0.5494423508644104 87 ], 88 'descriptor': {shape: [4, 6], dataType: 'float32'} 89 } 90 } 91 } 92 }, 93 { 94 'name': 'layerNormalization float32 2D tensor axes=[] and options.bias', 95 'graph': { 96 'inputs': { 97 'layerNormInput': { 98 'data': [ 99 -35.51446533203125, 54.735408782958984, 19.659019470214844, 100 -15.882678031921387, 65.48657989501953, 25.818492889404297, 101 97.55302429199219, -8.057161331176758, 62.9412956237793, 102 -48.91555404663086, 91.90644073486328, 46.67098617553711, 103 -74.85331726074219, 30.126361846923828, 26.13089370727539, 104 59.30270767211914, -60.361995697021484, 18.55615234375, 105 -88.03730773925781, -26.5667724609375, 70.81292724609375, 106 9.105611801147461, 56.66746139526367, 21.78444480895996 107 ], 108 'descriptor': {shape: [4, 6], dataType: 'float32'} 109 }, 110 'layerNormBias': { 111 'data': [7.862982749938965], 112 'descriptor': {shape: [], dataType: 'float32'} 113 } 114 }, 115 'operators': [{ 116 'name': 'layerNormalization', 117 'arguments': [ 118 {'input': 'layerNormInput'}, 119 {'options': {'axes': [], 'bias': 'layerNormBias'}} 120 ], 121 'outputs': 'layerNormOutput' 122 }], 123 'expectedOutputs': { 124 'layerNormOutput': { 125 'data': [ 126 7.862982749938965, 7.862982749938965, 7.862982749938965, 127 7.862982749938965, 7.862982749938965, 7.862982749938965, 128 7.862982749938965, 7.862982749938965, 7.862982749938965, 129 7.862982749938965, 7.862982749938965, 7.862982749938965, 130 7.862982749938965, 7.862982749938965, 7.862982749938965, 131 7.862982749938965, 7.862982749938965, 7.862982749938965, 132 7.862982749938965, 7.862982749938965, 7.862982749938965, 133 7.862982749938965, 7.862982749938965, 7.862982749938965 134 ], 135 'descriptor': {shape: [4, 6], dataType: 'float32'} 136 } 137 } 138 } 139 }, 140 { 141 'name': 'layerNormalization float32 2D tensor axes=[]', 142 'graph': { 143 'inputs': { 144 'layerNormInput': { 145 'data': [ 146 -35.51446533203125, 54.735408782958984, 19.659019470214844, 147 -15.882678031921387, 65.48657989501953, 25.818492889404297, 148 97.55302429199219, -8.057161331176758, 62.9412956237793, 149 -48.91555404663086, 91.90644073486328, 46.67098617553711, 150 -74.85331726074219, 30.126361846923828, 26.13089370727539, 151 59.30270767211914, -60.361995697021484, 18.55615234375, 152 -88.03730773925781, -26.5667724609375, 70.81292724609375, 153 9.105611801147461, 56.66746139526367, 21.78444480895996 154 ], 155 'descriptor': {shape: [4, 6], dataType: 'float32'} 156 } 157 }, 158 'operators': [{ 159 'name': 'layerNormalization', 160 'arguments': [{'input': 'layerNormInput'}, {'options': {'axes': []}}], 161 'outputs': 'layerNormOutput' 162 }], 163 'expectedOutputs': { 164 'layerNormOutput': { 165 'data': [ 166 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 167 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 168 ], 169 'descriptor': {shape: [4, 6], dataType: 'float32'} 170 } 171 } 172 } 173 }, 174 { 175 'name': 'layerNormalization float32 3D tensor default options', 176 'graph': { 177 'inputs': { 178 'layerNormInput': { 179 'data': [ 180 -35.51446533203125, 54.735408782958984, 19.659019470214844, 181 -15.882678031921387, 65.48657989501953, 25.818492889404297, 182 97.55302429199219, -8.057161331176758, 62.9412956237793, 183 -48.91555404663086, 91.90644073486328, 46.67098617553711, 184 -74.85331726074219, 30.126361846923828, 26.13089370727539, 185 59.30270767211914, -60.361995697021484, 18.55615234375, 186 -88.03730773925781, -26.5667724609375, 70.81292724609375, 187 9.105611801147461, 56.66746139526367, 21.78444480895996 188 ], 189 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 190 } 191 }, 192 'operators': [{ 193 'name': 'layerNormalization', 194 'arguments': [{'input': 'layerNormInput'}], 195 'outputs': 'layerNormOutput' 196 }], 197 'expectedOutputs': { 198 'layerNormOutput': { 199 'data': [ 200 -1.4057259559631348, 0.5396455526351929, -0.21643976867198944, 201 -0.9825550317764282, 0.7713912725448608, -0.08366990834474564, 202 1.46259605884552, -0.8138729333877563, 0.7165266871452332, 203 -1.6945916414260864, 1.3408818244934082, 0.3658137917518616, 204 -1.5234858989715576, 0.5162702202796936, 0.43863821029663086, 205 1.0831668376922607, -1.2419193983078003, 0.29146093130111694, 206 -1.7796510457992554, -0.5852779150009155, 1.3068104982376099, 207 0.10783683508634567, 1.0319640636444092, 0.35418668389320374 208 ], 209 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 210 } 211 } 212 } 213 }, 214 { 215 'name': 'layerNormalization float32 4D tensor default options', 216 'graph': { 217 'inputs': { 218 'layerNormInput': { 219 'data': [ 220 -35.51446533203125, 54.735408782958984, 19.659019470214844, 221 -15.882678031921387, 65.48657989501953, 25.818492889404297, 222 97.55302429199219, -8.057161331176758, 62.9412956237793, 223 -48.91555404663086, 91.90644073486328, 46.67098617553711, 224 -74.85331726074219, 30.126361846923828, 26.13089370727539, 225 59.30270767211914, -60.361995697021484, 18.55615234375, 226 -88.03730773925781, -26.5667724609375, 70.81292724609375, 227 9.105611801147461, 56.66746139526367, 21.78444480895996 228 ], 229 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 230 } 231 }, 232 'operators': [{ 233 'name': 'layerNormalization', 234 'arguments': [{'input': 'layerNormInput'}], 235 'outputs': 'layerNormOutput' 236 }], 237 'expectedOutputs': { 238 'layerNormOutput': { 239 'data': [ 240 -1.4057259559631348, 0.5396455526351929, -0.21643976867198944, 241 -0.9825550317764282, 0.7713912725448608, -0.08366990834474564, 242 1.46259605884552, -0.8138729333877563, 0.7165266871452332, 243 -1.6945916414260864, 1.3408818244934082, 0.3658137917518616, 244 -1.5234858989715576, 0.5162702202796936, 0.43863821029663086, 245 1.0831668376922607, -1.2419193983078003, 0.29146093130111694, 246 -1.7796510457992554, -0.5852779150009155, 1.3068104982376099, 247 0.10783683508634567, 1.0319640636444092, 0.35418668389320374 248 ], 249 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 250 } 251 } 252 } 253 }, 254 { 255 'name': 'layerNormalization float32 5D tensor default options', 256 'graph': { 257 'inputs': { 258 'layerNormInput': { 259 'data': [ 260 -35.51446533203125, 54.735408782958984, 19.659019470214844, 261 -15.882678031921387, 65.48657989501953, 25.818492889404297, 262 97.55302429199219, -8.057161331176758, 62.9412956237793, 263 -48.91555404663086, 91.90644073486328, 46.67098617553711, 264 -74.85331726074219, 30.126361846923828, 26.13089370727539, 265 59.30270767211914, -60.361995697021484, 18.55615234375, 266 -88.03730773925781, -26.5667724609375, 70.81292724609375, 267 9.105611801147461, 56.66746139526367, 21.78444480895996 268 ], 269 'descriptor': {shape: [2, 1, 2, 2, 3], dataType: 'float32'} 270 } 271 }, 272 'operators': [{ 273 'name': 'layerNormalization', 274 'arguments': [{'input': 'layerNormInput'}], 275 'outputs': 'layerNormOutput' 276 }], 277 'expectedOutputs': { 278 'layerNormOutput': { 279 'data': [ 280 -1.4057259559631348, 0.5396455526351929, -0.21643976867198944, 281 -0.9825550317764282, 0.7713912725448608, -0.08366990834474564, 282 1.46259605884552, -0.8138729333877563, 0.7165266871452332, 283 -1.6945916414260864, 1.3408818244934082, 0.3658137917518616, 284 -1.5234858989715576, 0.5162702202796936, 0.43863821029663086, 285 1.0831668376922607, -1.2419193983078003, 0.29146093130111694, 286 -1.7796510457992554, -0.5852779150009155, 1.3068104982376099, 287 0.10783683508634567, 1.0319640636444092, 0.35418668389320374 288 ], 289 'descriptor': {shape: [2, 1, 2, 2, 3], dataType: 'float32'} 290 } 291 } 292 } 293 }, 294 { 295 'name': 'layerNormalization float32 4D tensor options.scale', 296 'graph': { 297 'inputs': { 298 'layerNormInput': { 299 'data': [ 300 -35.51446533203125, 54.735408782958984, 19.659019470214844, 301 -15.882678031921387, 65.48657989501953, 25.818492889404297, 302 97.55302429199219, -8.057161331176758, 62.9412956237793, 303 -48.91555404663086, 91.90644073486328, 46.67098617553711, 304 -74.85331726074219, 30.126361846923828, 26.13089370727539, 305 59.30270767211914, -60.361995697021484, 18.55615234375, 306 -88.03730773925781, -26.5667724609375, 70.81292724609375, 307 9.105611801147461, 56.66746139526367, 21.78444480895996 308 ], 309 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 310 }, 311 'layerNormScale': { 312 'data': [ 313 -3.8228423595428467, -5.452458381652832, 0.6776165962219238, 314 -4.027037620544434, -3.7771618366241455, -9.327335357666016, 315 7.1816911697387695, 1.5054303407669067, 3.120894193649292, 316 0.5214731693267822, 2.6719748973846436, -3.571370840072632 317 ], 318 'descriptor': {shape: [1, 4, 3], dataType: 'float32'}, 319 'constant': true 320 } 321 }, 322 'operators': [{ 323 'name': 'layerNormalization', 324 'arguments': [ 325 {'input': 'layerNormInput'}, {'options': {'scale': 'layerNormScale'}} 326 ], 327 'outputs': 'layerNormOutput' 328 }], 329 'expectedOutputs': { 330 'layerNormOutput': { 331 'data': [ 332 5.373868465423584, -2.942394971847534, -0.14666318893432617, 333 3.9567861557006836, -2.9136698246002197, 0.780417263507843, 334 10.503913879394531, -1.225229024887085, 2.236203908920288, 335 -0.8836840987205505, 3.5828025341033936, -1.3064566850662231, 336 5.824046611785889, -2.814941883087158, 0.29722854495048523, 337 -4.3619537353515625, 4.6909308433532715, -2.7185537815093994, 338 -12.780903816223145, -0.8810951709747314, 4.0784173011779785, 339 0.05623401328921318, 2.7573819160461426, -1.2649319171905518 340 ], 341 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 342 } 343 } 344 } 345 }, 346 { 347 'name': 'layerNormalization float32 4D tensor options.bias', 348 'graph': { 349 'inputs': { 350 'layerNormInput': { 351 'data': [ 352 -35.51446533203125, 54.735408782958984, 19.659019470214844, 353 -15.882678031921387, 65.48657989501953, 25.818492889404297, 354 97.55302429199219, -8.057161331176758, 62.9412956237793, 355 -48.91555404663086, 91.90644073486328, 46.67098617553711, 356 -74.85331726074219, 30.126361846923828, 26.13089370727539, 357 59.30270767211914, -60.361995697021484, 18.55615234375, 358 -88.03730773925781, -26.5667724609375, 70.81292724609375, 359 9.105611801147461, 56.66746139526367, 21.78444480895996 360 ], 361 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 362 }, 363 'layerNormBias': { 364 'data': [ 365 7.862982749938965, -3.6603047847747803, -6.955524444580078, 366 -6.397322654724121, 3.268958568572998, -2.7498080730438232, 367 -4.080942153930664, -7.137991905212402, 8.465653419494629, 368 2.762545108795166, 0.8230442404747009, -3.827561378479004 369 ], 370 'descriptor': {shape: [1, 4, 3], dataType: 'float32'}, 371 'constant': true 372 } 373 }, 374 'operators': [{ 375 'name': 'layerNormalization', 376 'arguments': [ 377 {'input': 'layerNormInput'}, {'options': {'bias': 'layerNormBias'}} 378 ], 379 'outputs': 'layerNormOutput' 380 }], 381 'expectedOutputs': { 382 'layerNormOutput': { 383 'data': [ 384 6.45725679397583, -3.120659112930298, -7.171964168548584, 385 -7.37987756729126, 4.040349960327148, -2.8334779739379883, 386 -2.6183459758758545, -7.951864719390869, 9.182180404663086, 387 1.0679534673690796, 2.163926124572754, -3.461747646331787, 388 6.339496612548828, -3.1440346240997314, -6.516886234283447, 389 -5.314155578613281, 2.027039051055908, -2.4583470821380615, 390 -5.860593318939209, -7.723269939422607, 9.77246379852295, 391 2.8703818321228027, 1.8550082445144653, -3.473374605178833 392 ], 393 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 394 } 395 } 396 } 397 }, 398 { 399 'name': 'layerNormalization float32 4D tensor options.axes=[2]', 400 'graph': { 401 'inputs': { 402 'layerNormInput': { 403 'data': [ 404 -35.51446533203125, 54.735408782958984, 19.659019470214844, 405 -15.882678031921387, 65.48657989501953, 25.818492889404297, 406 97.55302429199219, -8.057161331176758, 62.9412956237793, 407 -48.91555404663086, 91.90644073486328, 46.67098617553711, 408 -74.85331726074219, 30.126361846923828, 26.13089370727539, 409 59.30270767211914, -60.361995697021484, 18.55615234375, 410 -88.03730773925781, -26.5667724609375, 70.81292724609375, 411 9.105611801147461, 56.66746139526367, 21.78444480895996 412 ], 413 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 414 } 415 }, 416 'operators': [{ 417 'name': 'layerNormalization', 418 'arguments': [{'input': 'layerNormInput'}, {'options': {'axes': [2]}}], 419 'outputs': 'layerNormOutput' 420 }], 421 'expectedOutputs': { 422 'layerNormOutput': { 423 'data': [ 424 -0.6012066006660461, 0.10132180899381638, -1.112992763519287, 425 -0.26228588819503784, 0.3943416476249695, -0.7543209195137024, 426 1.6960537433624268, -1.6100702285766602, 1.4073745012283325, 427 -0.8325613141059875, 1.114406704902649, 0.45993921160697937, 428 -0.8445013165473938, 0.6554933190345764, -0.3856155574321747, 429 1.3668763637542725, -1.3111618757247925, -0.7422532439231873, 430 -1.0618212223052979, -0.5766634941101074, 1.7181260585784912, 431 0.539446234703064, 1.2323321104049683, -0.5902572274208069 432 ], 433 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 434 } 435 } 436 } 437 }, 438 { 439 'name': 'layerNormalization float32 4D tensor options.epsilon', 440 'graph': { 441 'inputs': { 442 'layerNormInput': { 443 'data': [ 444 -35.51446533203125, 54.735408782958984, 19.659019470214844, 445 -15.882678031921387, 65.48657989501953, 25.818492889404297, 446 97.55302429199219, -8.057161331176758, 62.9412956237793, 447 -48.91555404663086, 91.90644073486328, 46.67098617553711, 448 -74.85331726074219, 30.126361846923828, 26.13089370727539, 449 59.30270767211914, -60.361995697021484, 18.55615234375, 450 -88.03730773925781, -26.5667724609375, 70.81292724609375, 451 9.105611801147461, 56.66746139526367, 21.78444480895996 452 ], 453 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 454 } 455 }, 456 'operators': [{ 457 'name': 'layerNormalization', 458 'arguments': 459 [{'input': 'layerNormInput'}, {'options': {'epsilon': 0.0001}}], 460 'outputs': 'layerNormOutput' 461 }], 462 'expectedOutputs': { 463 'layerNormOutput': { 464 'data': [ 465 -1.4057258367538452, 0.5396455526351929, -0.21643976867198944, 466 -0.9825550317764282, 0.7713912725448608, -0.08366990089416504, 467 1.46259605884552, -0.8138729333877563, 0.7165266871452332, 468 -1.6945916414260864, 1.3408817052841187, 0.3658137619495392, 469 -1.5234858989715576, 0.5162702202796936, 0.43863821029663086, 470 1.0831668376922607, -1.2419193983078003, 0.29146093130111694, 471 -1.7796509265899658, -0.5852779150009155, 1.3068104982376099, 472 0.10783682763576508, 1.0319639444351196, 0.35418668389320374 473 ], 474 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 475 } 476 } 477 } 478 }, 479 { 480 'name': 481 'layerNormalization float32 4D tensor options.scale and options.axes=[0, 2]', 482 'graph': { 483 'inputs': { 484 'layerNormInput': { 485 'data': [ 486 -35.51446533203125, 54.735408782958984, 19.659019470214844, 487 -15.882678031921387, 65.48657989501953, 25.818492889404297, 488 97.55302429199219, -8.057161331176758, 62.9412956237793, 489 -48.91555404663086, 91.90644073486328, 46.67098617553711, 490 -74.85331726074219, 30.126361846923828, 26.13089370727539, 491 59.30270767211914, -60.361995697021484, 18.55615234375, 492 -88.03730773925781, -26.5667724609375, 70.81292724609375, 493 9.105611801147461, 56.66746139526367, 21.78444480895996 494 ], 495 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 496 }, 497 'layerNormScale': { 498 'data': [ 499 8.72657299041748, -5.388210773468018, -6.811323165893555, 500 4.707905292510986, -4.705780029296875, -5.143046855926514, 501 -1.1115549802780151, 5.250569820404053 502 ], 503 'descriptor': {shape: [2, 4], dataType: 'float32'}, 504 'constant': true 505 } 506 }, 507 'operators': [{ 508 'name': 'layerNormalization', 509 'arguments': [ 510 {'input': 'layerNormInput'}, 511 {'options': {'scale': 'layerNormScale', 'axes': [0, 2]}} 512 ], 513 'outputs': 'layerNormOutput' 514 }], 515 'expectedOutputs': { 516 'layerNormOutput': { 517 'data': [ 518 -3.3744184970855713, 5.22746467590332, -7.580371856689453, 519 0.3324689269065857, -4.414334774017334, 2.973374605178833, 520 -12.369945526123047, 4.680946350097656, -9.247408866882324, 521 -2.8648624420166016, 6.40486478805542, 2.4516794681549072, 522 4.884079456329346, -0.44672244787216187, 2.521172285079956, 523 -6.083702564239502, 9.044846534729004, 4.759283065795898, 524 1.3962621688842773, 1.185346245765686, -1.959165334701538, 525 1.8479242324829102, 3.3530402183532715, -3.986907958984375 526 ], 527 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 528 } 529 } 530 } 531 }, 532 { 533 'name': 534 'layerNormalization float32 4D tensor options.bias and options.axes=[3, 1, 2]', 535 'graph': { 536 'inputs': { 537 'layerNormInput': { 538 'data': [ 539 -35.51446533203125, 54.735408782958984, 19.659019470214844, 540 -15.882678031921387, 65.48657989501953, 25.818492889404297, 541 97.55302429199219, -8.057161331176758, 62.9412956237793, 542 -48.91555404663086, 91.90644073486328, 46.67098617553711, 543 -74.85331726074219, 30.126361846923828, 26.13089370727539, 544 59.30270767211914, -60.361995697021484, 18.55615234375, 545 -88.03730773925781, -26.5667724609375, 70.81292724609375, 546 9.105611801147461, 56.66746139526367, 21.78444480895996 547 ], 548 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 549 }, 550 'layerNormBias': { 551 'data': [ 552 -0.1396923065185547, -6.156772136688232, 4.363296031951904, 553 8.8598051071167, 9.772650718688965, -3.4626545906066895, 554 9.744950294494629, -0.3958968222141266, -8.497353553771973, 555 6.172536849975586, -2.8930461406707764, 1.7220044136047363 556 ], 557 'descriptor': {shape: [3, 1, 4], dataType: 'float32'}, 558 'constant': true 559 } 560 }, 561 'operators': [{ 562 'name': 'layerNormalization', 563 'arguments': [ 564 {'input': 'layerNormInput'}, 565 {'options': {'bias': 'layerNormBias', 'axes': [3, 1, 2]}} 566 ], 567 'outputs': 'layerNormOutput' 568 }], 569 'expectedOutputs': { 570 'layerNormOutput': { 571 'data': [ 572 -1.5454182624816895, 10.312295913696289, -8.713793754577637, 573 -7.139327049255371, -2.691263198852539, 6.088866710662842, 574 5.825891971588135, 8.931077003479004, -2.1765193939208984, 575 7.165213584899902, 0.9449849724769592, 2.087818145751953, 576 -1.6631782054901123, 10.288921356201172, -8.058714866638184, 577 -5.073605060577393, -4.704574108123779, 6.463997840881348, 578 2.5836451053619385, 9.159672737121582, -1.5862356424331665, 579 8.967641830444336, 0.6360672116279602, 2.0761911869049072 580 ], 581 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 582 } 583 } 584 } 585 }, 586 { 587 'name': 'layerNormalization float32 4D tensor all options', 588 'graph': { 589 'inputs': { 590 'layerNormInput': { 591 'data': [ 592 -35.51446533203125, 54.735408782958984, 19.659019470214844, 593 -15.882678031921387, 65.48657989501953, 25.818492889404297, 594 97.55302429199219, -8.057161331176758, 62.9412956237793, 595 -48.91555404663086, 91.90644073486328, 46.67098617553711, 596 -74.85331726074219, 30.126361846923828, 26.13089370727539, 597 59.30270767211914, -60.361995697021484, 18.55615234375, 598 -88.03730773925781, -26.5667724609375, 70.81292724609375, 599 9.105611801147461, 56.66746139526367, 21.78444480895996 600 ], 601 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 602 }, 603 'layerNormScale': { 604 'data': [ 605 7.715926647186279, 1.7371079921722412, 9.13965129852295, 606 5.758823394775391, -2.8198351860046387, -0.6866958141326904 607 ], 608 'descriptor': {shape: [2, 3, 1], dataType: 'float32'}, 609 'constant': true 610 }, 611 'layerNormBias': { 612 'data': [ 613 -8.710672378540039, -7.642981052398682, 4.937538146972656, 614 -2.1876745223999023, -4.067612648010254, -6.836254596710205 615 ], 616 'descriptor': {shape: [2, 3, 1], dataType: 'float32'}, 617 'constant': true 618 } 619 }, 620 'operators': [{ 621 'name': 'layerNormalization', 622 'arguments': [ 623 {'input': 'layerNormInput'}, { 624 'options': { 625 'scale': 'layerNormScale', 626 'bias': 'layerNormBias', 627 'axes': [0, 3, 1], 628 'epsilon': 0.0001 629 } 630 } 631 ], 632 'outputs': 'layerNormOutput' 633 }], 634 'expectedOutputs': { 635 'layerNormOutput': { 636 'data': [ 637 -15.487034797668457, -5.628695964813232, 8.29687786102295, 638 -14.294686317443848, -5.639192581176758, 7.11608362197876, 639 0.7769554257392883, -8.346451759338379, 11.279659271240234, 640 -22.506288528442383, -5.173816204071045, 8.506545066833496, 641 -12.360523223876953, -5.77052116394043, -7.18900203704834, 642 3.6336634159088135, 0.8666883707046509, -6.884884357452393, 643 -11.648612976074219, -2.117840528488159, -7.396423816680908, 644 -4.869131088256836, -5.8111701011657715, -6.714934349060059 645 ], 646 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 647 } 648 } 649 } 650 }, 651 652 // float16 tests 653 { 654 'name': 'layerNormalization float16 2D tensor default options', 655 'graph': { 656 'inputs': { 657 'layerNormInput': { 658 'data': [ 659 -5.7109375, 1.4677734375, 660 6.14453125, 9.4296875, 661 2.052734375, -8.828125, 662 9.140625, -7.64453125, 663 -2.033203125, 6.0625, 664 4.09375, 0.89111328125, 665 8.7109375, -0.0006122589111328125, 666 5.50390625, -9.15625, 667 -9.890625, 1.0478515625, 668 -5.92578125, 7.7421875, 669 0.70068359375, -5.66015625, 670 1.3203125, 2.78515625 671 ], 672 'descriptor': {shape: [4, 6], dataType: 'float16'} 673 } 674 }, 675 'operators': [{ 676 'name': 'layerNormalization', 677 'arguments': [{'input': 'layerNormInput'}], 678 'outputs': 'layerNormOutput' 679 }], 680 'expectedOutputs': { 681 'layerNormOutput': { 682 'data': [ 683 -1.0224609375, 0.11199951171875, 0.85107421875, 1.3701171875, 684 0.2044677734375, -1.515625, 1.341796875, -1.7060546875, 685 -0.68701171875, 0.78271484375, 0.42529296875, -0.15625, 686 1.3515625, 0.0911865234375, 0.8876953125, -1.2333984375, 687 -1.33984375, 0.242919921875, -1.2744140625, 1.5869140625, 688 0.11309814453125, -1.21875, 0.2427978515625, 0.54931640625 689 ], 690 'descriptor': {shape: [4, 6], dataType: 'float16'} 691 } 692 } 693 } 694 }, 695 { 696 'name': 'layerNormalization float16 3D tensor default options', 697 'graph': { 698 'inputs': { 699 'layerNormInput': { 700 'data': [ 701 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 702 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 703 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 704 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 705 ], 706 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 707 } 708 }, 709 'operators': [{ 710 'name': 'layerNormalization', 711 'arguments': [{'input': 'layerNormInput'}], 712 'outputs': 'layerNormOutput' 713 }], 714 'expectedOutputs': { 715 'layerNormOutput': { 716 'data': [ 717 -1.4052734375, 0.5400390625, -0.216552734375, -0.982421875, 718 0.771484375, -0.08392333984375, 1.462890625, -0.81396484375, 719 0.71630859375, -1.6943359375, 1.341796875, 0.365234375, 720 -1.5234375, 0.51611328125, 0.4384765625, 1.0830078125, 721 -1.2421875, 0.291748046875, -1.7802734375, -0.5849609375, 722 1.306640625, 0.10797119140625, 1.03125, 0.354248046875 723 ], 724 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 725 } 726 } 727 } 728 }, 729 { 730 'name': 'layerNormalization float16 4D tensor default options', 731 'graph': { 732 'inputs': { 733 'layerNormInput': { 734 'data': [ 735 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 736 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 737 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 738 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 739 ], 740 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 741 } 742 }, 743 'operators': [{ 744 'name': 'layerNormalization', 745 'arguments': [{'input': 'layerNormInput'}], 746 'outputs': 'layerNormOutput' 747 }], 748 'expectedOutputs': { 749 'layerNormOutput': { 750 'data': [ 751 -1.4052734375, 0.5400390625, -0.216552734375, -0.982421875, 752 0.771484375, -0.08392333984375, 1.462890625, -0.81396484375, 753 0.71630859375, -1.6943359375, 1.341796875, 0.365234375, 754 -1.5234375, 0.51611328125, 0.4384765625, 1.0830078125, 755 -1.2421875, 0.291748046875, -1.7802734375, -0.5849609375, 756 1.306640625, 0.10797119140625, 1.03125, 0.354248046875 757 ], 758 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 759 } 760 } 761 } 762 }, 763 { 764 'name': 'layerNormalization float16 5D tensor default options', 765 'graph': { 766 'inputs': { 767 'layerNormInput': { 768 'data': [ 769 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 770 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 771 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 772 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 773 ], 774 'descriptor': {shape: [2, 1, 2, 2, 3], dataType: 'float16'} 775 } 776 }, 777 'operators': [{ 778 'name': 'layerNormalization', 779 'arguments': [{'input': 'layerNormInput'}], 780 'outputs': 'layerNormOutput' 781 }], 782 'expectedOutputs': { 783 'layerNormOutput': { 784 'data': [ 785 -1.4052734375, 0.5400390625, -0.216552734375, -0.982421875, 786 0.771484375, -0.08392333984375, 1.462890625, -0.81396484375, 787 0.71630859375, -1.6943359375, 1.341796875, 0.365234375, 788 -1.5234375, 0.51611328125, 0.4384765625, 1.0830078125, 789 -1.2421875, 0.291748046875, -1.7802734375, -0.5849609375, 790 1.306640625, 0.10797119140625, 1.03125, 0.354248046875 791 ], 792 'descriptor': {shape: [2, 1, 2, 2, 3], dataType: 'float16'} 793 } 794 } 795 } 796 }, 797 { 798 'name': 'layerNormalization float16 4D tensor options.scale', 799 'graph': { 800 'inputs': { 801 'layerNormInput': { 802 'data': [ 803 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 804 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 805 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 806 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 807 ], 808 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 809 }, 810 'layerNormScale': { 811 'data': [ 812 -3.822265625, -5.453125, 0.677734375, -4.02734375, -3.77734375, 813 -9.328125, 7.18359375, 1.505859375, 3.12109375, 0.521484375, 814 2.671875, -3.572265625 815 ], 816 'descriptor': {shape: [1, 4, 3], dataType: 'float16'}, 817 'constant': true 818 } 819 }, 820 'operators': [{ 821 'name': 'layerNormalization', 822 'arguments': [ 823 {'input': 'layerNormInput'}, {'options': {'scale': 'layerNormScale'}} 824 ], 825 'outputs': 'layerNormOutput' 826 }], 827 'expectedOutputs': { 828 'layerNormOutput': { 829 'data': [ 830 5.37109375, -2.943359375, -0.1468505859375, 3.95703125, 831 -2.9140625, 0.78271484375, 10.5078125, -1.2255859375, 832 2.236328125, -0.8837890625, 3.583984375, -1.3046875, 833 5.82421875, -2.814453125, 0.297119140625, -4.36328125, 834 4.69140625, -2.720703125, -12.7890625, -0.880859375, 835 4.078125, 0.056304931640625, 2.755859375, -1.265625 836 ], 837 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 838 } 839 } 840 } 841 }, 842 { 843 'name': 'layerNormalization float16 4D tensor options.bias', 844 'graph': { 845 'inputs': { 846 'layerNormInput': { 847 'data': [ 848 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 849 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 850 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 851 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 852 ], 853 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 854 }, 855 'layerNormBias': { 856 'data': [ 857 7.86328125, -3.66015625, -6.95703125, -6.3984375, 3.26953125, -2.75, 858 -4.08203125, -7.13671875, 8.46875, 2.76171875, 0.8232421875, 859 -3.828125 860 ], 861 'descriptor': {shape: [1, 4, 3], dataType: 'float16'}, 862 'constant': true 863 } 864 }, 865 'operators': [{ 866 'name': 'layerNormalization', 867 'arguments': [ 868 {'input': 'layerNormInput'}, {'options': {'bias': 'layerNormBias'}} 869 ], 870 'outputs': 'layerNormOutput' 871 }], 872 'expectedOutputs': { 873 'layerNormOutput': { 874 'data': [ 875 6.45703125, -3.12109375, -7.171875, -7.3828125, 4.04296875, 876 -2.833984375, -2.619140625, -7.94921875, 9.1875, 1.0673828125, 877 2.1640625, -3.462890625, 6.33984375, -3.14453125, -6.51953125, 878 -5.31640625, 2.02734375, -2.458984375, -5.86328125, -7.72265625, 879 9.7734375, 2.869140625, 1.8544921875, -3.474609375 880 ], 881 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 882 } 883 } 884 } 885 }, 886 { 887 'name': 'layerNormalization float16 4D tensor options.axes=[2]', 888 'graph': { 889 'inputs': { 890 'layerNormInput': { 891 'data': [ 892 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 893 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 894 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 895 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 896 ], 897 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 898 } 899 }, 900 'operators': [{ 901 'name': 'layerNormalization', 902 'arguments': [{'input': 'layerNormInput'}, {'options': {'axes': [2]}}], 903 'outputs': 'layerNormOutput' 904 }], 905 'expectedOutputs': { 906 'layerNormOutput': { 907 'data': [ 908 -0.60107421875, 0.10125732421875, -1.11328125, -0.262451171875, 909 0.394287109375, -0.75439453125, 1.6962890625, -1.6103515625, 910 1.4072265625, -0.83251953125, 1.1142578125, 0.45947265625, 911 -0.8447265625, 0.65576171875, -0.3857421875, 1.3671875, 912 -1.3115234375, -0.74169921875, -1.0615234375, -0.57666015625, 913 1.7177734375, 0.53955078125, 1.232421875, -0.59033203125 914 ], 915 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 916 } 917 } 918 } 919 }, 920 { 921 'name': 'layerNormalization float16 4D tensor options.epsilon', 922 'graph': { 923 'inputs': { 924 'layerNormInput': { 925 'data': [ 926 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 927 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 928 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 929 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 930 ], 931 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 932 } 933 }, 934 'operators': [{ 935 'name': 'layerNormalization', 936 'arguments': 937 [{'input': 'layerNormInput'}, {'options': {'epsilon': 0.0001}}], 938 'outputs': 'layerNormOutput' 939 }], 940 'expectedOutputs': { 941 'layerNormOutput': { 942 'data': [ 943 -1.4052734375, 0.5400390625, -0.216552734375, -0.982421875, 944 0.771484375, -0.08392333984375, 1.462890625, -0.81396484375, 945 0.71630859375, -1.6943359375, 1.341796875, 0.365234375, 946 -1.5234375, 0.51611328125, 0.4384765625, 1.0830078125, 947 -1.2421875, 0.291748046875, -1.7802734375, -0.5849609375, 948 1.306640625, 0.10797119140625, 1.03125, 0.354248046875 949 ], 950 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 951 } 952 } 953 } 954 }, 955 { 956 'name': 957 'layerNormalization float16 4D tensor options.scale and options.axes=[0, 2]', 958 'graph': { 959 'inputs': { 960 'layerNormInput': { 961 'data': [ 962 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 963 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 964 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 965 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 966 ], 967 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 968 }, 969 'layerNormScale': { 970 'data': [ 971 8.7265625, -5.38671875, -6.8125, 4.70703125, -4.70703125, 972 -5.14453125, -1.111328125, 5.25 973 ], 974 'descriptor': {shape: [2, 4], dataType: 'float16'}, 975 'constant': true 976 } 977 }, 978 'operators': [{ 979 'name': 'layerNormalization', 980 'arguments': [ 981 {'input': 'layerNormInput'}, 982 {'options': {'scale': 'layerNormScale', 'axes': [0, 2]}} 983 ], 984 'outputs': 'layerNormOutput' 985 }], 986 'expectedOutputs': { 987 'layerNormOutput': { 988 'data': [ 989 -3.37109375, 5.2265625, -7.58203125, 0.332275390625, 990 -4.4140625, 2.97265625, -12.375, 4.6796875, 991 -9.25, -2.86328125, 6.40625, 2.44921875, 992 4.88671875, -0.446044921875, 2.5234375, -6.0859375, 993 9.046875, 4.7578125, 1.396484375, 1.1845703125, 994 -1.958984375, 1.84765625, 3.349609375, -3.986328125 995 ], 996 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 997 } 998 } 999 } 1000 }, 1001 { 1002 'name': 1003 'layerNormalization float16 4D tensor options.bias and options.axes=[3, 1, 2]', 1004 'graph': { 1005 'inputs': { 1006 'layerNormInput': { 1007 'data': [ 1008 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 1009 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 1010 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 1011 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 1012 ], 1013 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 1014 }, 1015 'layerNormBias': { 1016 'data': [ 1017 -0.1396484375, -6.15625, 4.36328125, 8.859375, 9.7734375, 1018 -3.462890625, 9.7421875, -0.39599609375, -8.5, 6.171875, 1019 -2.892578125, 1.7216796875 1020 ], 1021 'descriptor': {shape: [3, 1, 4], dataType: 'float16'}, 1022 'constant': true 1023 } 1024 }, 1025 'operators': [{ 1026 'name': 'layerNormalization', 1027 'arguments': [ 1028 {'input': 'layerNormInput'}, 1029 {'options': {'bias': 'layerNormBias', 'axes': [3, 1, 2]}} 1030 ], 1031 'outputs': 'layerNormOutput' 1032 }], 1033 'expectedOutputs': { 1034 'layerNormOutput': { 1035 'data': [ 1036 -1.544921875, 10.3125, -8.71875, -7.140625, -2.69140625, 1037 6.08984375, 5.82421875, 8.9296875, -2.17578125, 7.1640625, 1038 0.9453125, 2.087890625, -1.6630859375, 10.2890625, -8.0625, 1039 -5.07421875, -4.703125, 6.46484375, 2.583984375, 9.15625, 1040 -1.5859375, 8.96875, 0.6357421875, 2.076171875 1041 ], 1042 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 1043 } 1044 } 1045 } 1046 }, 1047 { 1048 'name': 'layerNormalization float16 4D tensor all options', 1049 'graph': { 1050 'inputs': { 1051 'layerNormInput': { 1052 'data': [ 1053 -35.5, 54.75, 19.65625, -15.8828125, 65.5, 25.8125, 1054 97.5625, -8.0546875, 62.9375, -48.90625, 91.9375, 46.65625, 1055 -74.875, 30.125, 26.125, 59.3125, -60.375, 18.5625, 1056 -88.0625, -26.5625, 70.8125, 9.109375, 56.65625, 21.78125 1057 ], 1058 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 1059 }, 1060 'layerNormScale': { 1061 'data': [ 1062 7.71484375, 1.7373046875, 9.140625, 5.7578125, -2.8203125, 1063 -0.6865234375 1064 ], 1065 'descriptor': {shape: [2, 3, 1], dataType: 'float16'}, 1066 'constant': true 1067 }, 1068 'layerNormBias': { 1069 'data': [ 1070 -8.7109375, -7.64453125, 4.9375, -2.1875, -4.06640625, -6.8359375 1071 ], 1072 'descriptor': {shape: [2, 3, 1], dataType: 'float16'}, 1073 'constant': true 1074 } 1075 }, 1076 'operators': [{ 1077 'name': 'layerNormalization', 1078 'arguments': [ 1079 {'input': 'layerNormInput'}, { 1080 'options': { 1081 'scale': 'layerNormScale', 1082 'bias': 'layerNormBias', 1083 'axes': [0, 3, 1], 1084 'epsilon': 0.0001 1085 } 1086 } 1087 ], 1088 'outputs': 'layerNormOutput' 1089 }], 1090 'expectedOutputs': { 1091 'layerNormOutput': { 1092 'data': [ 1093 -15.484375, -5.62890625, 8.296875, -14.296875, -5.640625, 1094 7.11328125, 0.775390625, -8.3515625, 11.28125, -22.5, 1095 -5.17578125, 8.5, -12.359375, -5.76953125, -7.1875, 1096 3.6328125, 0.86865234375, -6.8828125, -11.6484375, -2.1171875, 1097 -7.39453125, -4.8671875, -5.80859375, -6.71484375 1098 ], 1099 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 1100 } 1101 } 1102 } 1103 } 1104 ]; 1105 1106 webnn_conformance_test( 1107 layerNormTests, buildAndExecuteGraph, getLayerNormPrecisionTolerance);