identity.https.any.js (20333B)
1 // META: title=test WebNN API element-wise identity operation 2 // META: global=window,worker 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-unary 12 // Copy the value of the input tensor to the output tensor, element-wise. 13 // 14 // MLOperand identity(MLOperand input); 15 16 const identityTests = [ 17 { 18 'name': 'identity float32 0D scalar', 19 'graph': { 20 'inputs': { 21 'identityInput': { 22 'data': [-4.273642539978027], 23 'descriptor': {shape: [], dataType: 'float32'} 24 } 25 }, 26 'operators': [{ 27 'name': 'identity', 28 'arguments': [{'input': 'identityInput'}], 29 'outputs': 'identityOutput' 30 }], 31 'expectedOutputs': { 32 'identityOutput': { 33 'data': [-4.273642539978027], 34 'descriptor': {shape: [], dataType: 'float32'} 35 } 36 } 37 } 38 }, 39 { 40 'name': 'identity float32 1D constant tensor', 41 'graph': { 42 'inputs': { 43 'identityInput': { 44 'data': [ 45 0.377551406621933, -0.8890897631645203, 9.965806007385254, 46 7.964576244354248, -4.207889080047607, -3.7487030029296875, 47 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 48 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 49 9.076417922973633, 7.101912021636963, 1.4166420698165894, 50 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 51 -9.782458305358887, 5.496699810028076, -9.967339515686035, 52 -6.901016712188721, -2.8501904010772705, 3.279616355895996 53 ], 54 'descriptor': {shape: [24], dataType: 'float32'}, 55 'constant': true 56 } 57 }, 58 'operators': [{ 59 'name': 'identity', 60 'arguments': [{'input': 'identityInput'}], 61 'outputs': 'identityOutput' 62 }], 63 'expectedOutputs': { 64 'identityOutput': { 65 'data': [ 66 0.377551406621933, -0.8890897631645203, 9.965806007385254, 67 7.964576244354248, -4.207889080047607, -3.7487030029296875, 68 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 69 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 70 9.076417922973633, 7.101912021636963, 1.4166420698165894, 71 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 72 -9.782458305358887, 5.496699810028076, -9.967339515686035, 73 -6.901016712188721, -2.8501904010772705, 3.279616355895996 74 ], 75 'descriptor': {shape: [24], dataType: 'float32'} 76 } 77 } 78 } 79 }, 80 { 81 'name': 'identity float32 1D tensor', 82 'graph': { 83 'inputs': { 84 'identityInput': { 85 'data': [ 86 0.377551406621933, -0.8890897631645203, 9.965806007385254, 87 7.964576244354248, -4.207889080047607, -3.7487030029296875, 88 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 89 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 90 9.076417922973633, 7.101912021636963, 1.4166420698165894, 91 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 92 -9.782458305358887, 5.496699810028076, -9.967339515686035, 93 -6.901016712188721, -2.8501904010772705, 3.279616355895996 94 ], 95 'descriptor': {shape: [24], dataType: 'float32'} 96 } 97 }, 98 'operators': [{ 99 'name': 'identity', 100 'arguments': [{'input': 'identityInput'}], 101 'outputs': 'identityOutput' 102 }], 103 'expectedOutputs': { 104 'identityOutput': { 105 'data': [ 106 0.377551406621933, -0.8890897631645203, 9.965806007385254, 107 7.964576244354248, -4.207889080047607, -3.7487030029296875, 108 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 109 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 110 9.076417922973633, 7.101912021636963, 1.4166420698165894, 111 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 112 -9.782458305358887, 5.496699810028076, -9.967339515686035, 113 -6.901016712188721, -2.8501904010772705, 3.279616355895996 114 ], 115 'descriptor': {shape: [24], dataType: 'float32'} 116 } 117 } 118 } 119 }, 120 { 121 'name': 'identity float32 2D tensor', 122 'graph': { 123 'inputs': { 124 'identityInput': { 125 'data': [ 126 0.377551406621933, -0.8890897631645203, 9.965806007385254, 127 7.964576244354248, -4.207889080047607, -3.7487030029296875, 128 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 129 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 130 9.076417922973633, 7.101912021636963, 1.4166420698165894, 131 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 132 -9.782458305358887, 5.496699810028076, -9.967339515686035, 133 -6.901016712188721, -2.8501904010772705, 3.279616355895996 134 ], 135 'descriptor': {shape: [4, 6], dataType: 'float32'} 136 } 137 }, 138 'operators': [{ 139 'name': 'identity', 140 'arguments': [{'input': 'identityInput'}], 141 'outputs': 'identityOutput' 142 }], 143 'expectedOutputs': { 144 'identityOutput': { 145 'data': [ 146 0.377551406621933, -0.8890897631645203, 9.965806007385254, 147 7.964576244354248, -4.207889080047607, -3.7487030029296875, 148 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 149 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 150 9.076417922973633, 7.101912021636963, 1.4166420698165894, 151 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 152 -9.782458305358887, 5.496699810028076, -9.967339515686035, 153 -6.901016712188721, -2.8501904010772705, 3.279616355895996 154 ], 155 'descriptor': {shape: [4, 6], dataType: 'float32'} 156 } 157 } 158 } 159 }, 160 { 161 'name': 'identity float32 3D tensor', 162 'graph': { 163 'inputs': { 164 'identityInput': { 165 'data': [ 166 0.377551406621933, -0.8890897631645203, 9.965806007385254, 167 7.964576244354248, -4.207889080047607, -3.7487030029296875, 168 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 169 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 170 9.076417922973633, 7.101912021636963, 1.4166420698165894, 171 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 172 -9.782458305358887, 5.496699810028076, -9.967339515686035, 173 -6.901016712188721, -2.8501904010772705, 3.279616355895996 174 ], 175 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 176 } 177 }, 178 'operators': [{ 179 'name': 'identity', 180 'arguments': [{'input': 'identityInput'}], 181 'outputs': 'identityOutput' 182 }], 183 'expectedOutputs': { 184 'identityOutput': { 185 'data': [ 186 0.377551406621933, -0.8890897631645203, 9.965806007385254, 187 7.964576244354248, -4.207889080047607, -3.7487030029296875, 188 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 189 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 190 9.076417922973633, 7.101912021636963, 1.4166420698165894, 191 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 192 -9.782458305358887, 5.496699810028076, -9.967339515686035, 193 -6.901016712188721, -2.8501904010772705, 3.279616355895996 194 ], 195 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 196 } 197 } 198 } 199 }, 200 { 201 'name': 'identity float32 4D tensor', 202 'graph': { 203 'inputs': { 204 'identityInput': { 205 'data': [ 206 0.377551406621933, -0.8890897631645203, 9.965806007385254, 207 7.964576244354248, -4.207889080047607, -3.7487030029296875, 208 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 209 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 210 9.076417922973633, 7.101912021636963, 1.4166420698165894, 211 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 212 -9.782458305358887, 5.496699810028076, -9.967339515686035, 213 -6.901016712188721, -2.8501904010772705, 3.279616355895996 214 ], 215 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 216 } 217 }, 218 'operators': [{ 219 'name': 'identity', 220 'arguments': [{'input': 'identityInput'}], 221 'outputs': 'identityOutput' 222 }], 223 'expectedOutputs': { 224 'identityOutput': { 225 'data': [ 226 0.377551406621933, -0.8890897631645203, 9.965806007385254, 227 7.964576244354248, -4.207889080047607, -3.7487030029296875, 228 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 229 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 230 9.076417922973633, 7.101912021636963, 1.4166420698165894, 231 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 232 -9.782458305358887, 5.496699810028076, -9.967339515686035, 233 -6.901016712188721, -2.8501904010772705, 3.279616355895996 234 ], 235 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 236 } 237 } 238 } 239 }, 240 { 241 'name': 'identity float32 5D tensor', 242 'graph': { 243 'inputs': { 244 'identityInput': { 245 'data': [ 246 0.377551406621933, -0.8890897631645203, 9.965806007385254, 247 7.964576244354248, -4.207889080047607, -3.7487030029296875, 248 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 249 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 250 9.076417922973633, 7.101912021636963, 1.4166420698165894, 251 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 252 -9.782458305358887, 5.496699810028076, -9.967339515686035, 253 -6.901016712188721, -2.8501904010772705, 3.279616355895996 254 ], 255 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 256 } 257 }, 258 'operators': [{ 259 'name': 'identity', 260 'arguments': [{'input': 'identityInput'}], 261 'outputs': 'identityOutput' 262 }], 263 'expectedOutputs': { 264 'identityOutput': { 265 'data': [ 266 0.377551406621933, -0.8890897631645203, 9.965806007385254, 267 7.964576244354248, -4.207889080047607, -3.7487030029296875, 268 -2.5114004611968994, 5.777673244476318, -4.472823619842529, 269 -8.405767440795898, -3.8579723834991455, 6.036187648773193, 270 9.076417922973633, 7.101912021636963, 1.4166420698165894, 271 -5.644308567047119, -2.5986480712890625, -7.264847278594971, 272 -9.782458305358887, 5.496699810028076, -9.967339515686035, 273 -6.901016712188721, -2.8501904010772705, 3.279616355895996 274 ], 275 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 276 } 277 } 278 } 279 }, 280 281 // float16 tests 282 { 283 'name': 'identity float16 0D scalar', 284 'graph': { 285 'inputs': { 286 'identityInput': { 287 'data': [-4.2734375], 288 'descriptor': {shape: [], dataType: 'float16'} 289 } 290 }, 291 'operators': [{ 292 'name': 'identity', 293 'arguments': [{'input': 'identityInput'}], 294 'outputs': 'identityOutput' 295 }], 296 'expectedOutputs': { 297 'identityOutput': { 298 'data': [-4.2734375], 299 'descriptor': {shape: [], dataType: 'float16'} 300 } 301 } 302 } 303 }, 304 { 305 'name': 'identity float16 1D constant tensor', 306 'graph': { 307 'inputs': { 308 'identityInput': { 309 'data': [ 310 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 311 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 312 -4.47265625, -8.40625, -3.857421875, 6.03515625, 313 9.078125, 7.1015625, 1.4169921875, -5.64453125, 314 -2.599609375, -7.265625, -9.78125, 5.49609375, 315 -9.96875, -6.90234375, -2.849609375, 3.279296875 316 ], 317 'descriptor': {shape: [24], dataType: 'float16'}, 318 'constant': true 319 } 320 }, 321 'operators': [{ 322 'name': 'identity', 323 'arguments': [{'input': 'identityInput'}], 324 'outputs': 'identityOutput' 325 }], 326 'expectedOutputs': { 327 'identityOutput': { 328 'data': [ 329 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 330 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 331 -4.47265625, -8.40625, -3.857421875, 6.03515625, 332 9.078125, 7.1015625, 1.4169921875, -5.64453125, 333 -2.599609375, -7.265625, -9.78125, 5.49609375, 334 -9.96875, -6.90234375, -2.849609375, 3.279296875 335 ], 336 'descriptor': {shape: [24], dataType: 'float16'} 337 } 338 } 339 } 340 }, 341 { 342 'name': 'identity float16 1D tensor', 343 'graph': { 344 'inputs': { 345 'identityInput': { 346 'data': [ 347 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 348 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 349 -4.47265625, -8.40625, -3.857421875, 6.03515625, 350 9.078125, 7.1015625, 1.4169921875, -5.64453125, 351 -2.599609375, -7.265625, -9.78125, 5.49609375, 352 -9.96875, -6.90234375, -2.849609375, 3.279296875 353 ], 354 'descriptor': {shape: [24], dataType: 'float16'} 355 } 356 }, 357 'operators': [{ 358 'name': 'identity', 359 'arguments': [{'input': 'identityInput'}], 360 'outputs': 'identityOutput' 361 }], 362 'expectedOutputs': { 363 'identityOutput': { 364 'data': [ 365 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 366 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 367 -4.47265625, -8.40625, -3.857421875, 6.03515625, 368 9.078125, 7.1015625, 1.4169921875, -5.64453125, 369 -2.599609375, -7.265625, -9.78125, 5.49609375, 370 -9.96875, -6.90234375, -2.849609375, 3.279296875 371 ], 372 'descriptor': {shape: [24], dataType: 'float16'} 373 } 374 } 375 } 376 }, 377 { 378 'name': 'identity float16 2D tensor', 379 'graph': { 380 'inputs': { 381 'identityInput': { 382 'data': [ 383 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 384 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 385 -4.47265625, -8.40625, -3.857421875, 6.03515625, 386 9.078125, 7.1015625, 1.4169921875, -5.64453125, 387 -2.599609375, -7.265625, -9.78125, 5.49609375, 388 -9.96875, -6.90234375, -2.849609375, 3.279296875 389 ], 390 'descriptor': {shape: [4, 6], dataType: 'float16'} 391 } 392 }, 393 'operators': [{ 394 'name': 'identity', 395 'arguments': [{'input': 'identityInput'}], 396 'outputs': 'identityOutput' 397 }], 398 'expectedOutputs': { 399 'identityOutput': { 400 'data': [ 401 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 402 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 403 -4.47265625, -8.40625, -3.857421875, 6.03515625, 404 9.078125, 7.1015625, 1.4169921875, -5.64453125, 405 -2.599609375, -7.265625, -9.78125, 5.49609375, 406 -9.96875, -6.90234375, -2.849609375, 3.279296875 407 ], 408 'descriptor': {shape: [4, 6], dataType: 'float16'} 409 } 410 } 411 } 412 }, 413 { 414 'name': 'identity float16 3D tensor', 415 'graph': { 416 'inputs': { 417 'identityInput': { 418 'data': [ 419 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 420 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 421 -4.47265625, -8.40625, -3.857421875, 6.03515625, 422 9.078125, 7.1015625, 1.4169921875, -5.64453125, 423 -2.599609375, -7.265625, -9.78125, 5.49609375, 424 -9.96875, -6.90234375, -2.849609375, 3.279296875 425 ], 426 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 427 } 428 }, 429 'operators': [{ 430 'name': 'identity', 431 'arguments': [{'input': 'identityInput'}], 432 'outputs': 'identityOutput' 433 }], 434 'expectedOutputs': { 435 'identityOutput': { 436 'data': [ 437 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 438 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 439 -4.47265625, -8.40625, -3.857421875, 6.03515625, 440 9.078125, 7.1015625, 1.4169921875, -5.64453125, 441 -2.599609375, -7.265625, -9.78125, 5.49609375, 442 -9.96875, -6.90234375, -2.849609375, 3.279296875 443 ], 444 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 445 } 446 } 447 } 448 }, 449 { 450 'name': 'identity float16 4D tensor', 451 'graph': { 452 'inputs': { 453 'identityInput': { 454 'data': [ 455 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 456 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 457 -4.47265625, -8.40625, -3.857421875, 6.03515625, 458 9.078125, 7.1015625, 1.4169921875, -5.64453125, 459 -2.599609375, -7.265625, -9.78125, 5.49609375, 460 -9.96875, -6.90234375, -2.849609375, 3.279296875 461 ], 462 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 463 } 464 }, 465 'operators': [{ 466 'name': 'identity', 467 'arguments': [{'input': 'identityInput'}], 468 'outputs': 'identityOutput' 469 }], 470 'expectedOutputs': { 471 'identityOutput': { 472 'data': [ 473 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 474 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 475 -4.47265625, -8.40625, -3.857421875, 6.03515625, 476 9.078125, 7.1015625, 1.4169921875, -5.64453125, 477 -2.599609375, -7.265625, -9.78125, 5.49609375, 478 -9.96875, -6.90234375, -2.849609375, 3.279296875 479 ], 480 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 481 } 482 } 483 } 484 }, 485 { 486 'name': 'identity float16 5D tensor', 487 'graph': { 488 'inputs': { 489 'identityInput': { 490 'data': [ 491 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 492 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 493 -4.47265625, -8.40625, -3.857421875, 6.03515625, 494 9.078125, 7.1015625, 1.4169921875, -5.64453125, 495 -2.599609375, -7.265625, -9.78125, 5.49609375, 496 -9.96875, -6.90234375, -2.849609375, 3.279296875 497 ], 498 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 499 } 500 }, 501 'operators': [{ 502 'name': 'identity', 503 'arguments': [{'input': 'identityInput'}], 504 'outputs': 'identityOutput' 505 }], 506 'expectedOutputs': { 507 'identityOutput': { 508 'data': [ 509 0.37744140625, -0.88916015625, 9.96875, 7.96484375, 510 -4.20703125, -3.748046875, -2.51171875, 5.77734375, 511 -4.47265625, -8.40625, -3.857421875, 6.03515625, 512 9.078125, 7.1015625, 1.4169921875, -5.64453125, 513 -2.599609375, -7.265625, -9.78125, 5.49609375, 514 -9.96875, -6.90234375, -2.849609375, 3.279296875 515 ], 516 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 517 } 518 } 519 } 520 } 521 ]; 522 523 webnn_conformance_test( 524 identityTests, buildAndExecuteGraph, getZeroULPTolerance);