dequantizeLinear.https.any.js (42339B)
1 // META: title=test WebNN API dequantizeLinear 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 // Calculate a low precision integer operand 12 // (typically uint8 with a zero-point bias) to floating point: 13 // output = (input - zeroPoint) * scale. 14 // 15 // MLOperand dequantizeLinear( 16 // MLOperand input, MLOperand scale, MLOperand zeroPoint, 17 // optional MLOperatorOptions options = {}); 18 19 20 const getDequantizeLinearPrecisionTolerance = (graphResources) => { 21 const toleranceValueDict = {float32: 1, float16: 1}; 22 const expectedDataType = 23 getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs); 24 return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]}; 25 }; 26 27 const dequantizeLinearTests = [ 28 // float32 tests 29 { 30 'name': 'dequantizeLinear int8 0D tensor with float32 0D scale', 31 'graph': { 32 'inputs': { 33 'dequantizeLinearInput': { 34 'data': [123], 35 'descriptor': {shape: [], dataType: 'int8'}, 36 'constant': false 37 }, 38 'dequantizeLinearScale': { 39 'data': [1.1202747821807861], 40 'descriptor': {shape: [], dataType: 'float32'}, 41 'constant': true 42 }, 43 'dequantizeLinearZeroPoint': { 44 'data': [3], 45 'descriptor': {shape: [], dataType: 'int8'}, 46 'constant': true 47 } 48 }, 49 'operators': [{ 50 'name': 'dequantizeLinear', 51 'arguments': [ 52 {'input': 'dequantizeLinearInput'}, 53 {'scale': 'dequantizeLinearScale'}, 54 {'zeroPoint': 'dequantizeLinearZeroPoint'} 55 ], 56 'outputs': 'dequantizeLinearOutput' 57 }], 58 'expectedOutputs': { 59 'dequantizeLinearOutput': { 60 'data': [134.43296813964844], 61 'descriptor': {shape: [], dataType: 'float32'} 62 } 63 } 64 } 65 }, 66 { 67 'name': 68 'dequantizeLinear int8 0D constant tensor with float32 0D scale', 69 'graph': { 70 'inputs': { 71 'dequantizeLinearInput': { 72 'data': [123], 73 'descriptor': {shape: [], dataType: 'int8'}, 74 'constant': true 75 }, 76 'dequantizeLinearScale': { 77 'data': [1.1202747821807861], 78 'descriptor': {shape: [], dataType: 'float32'}, 79 'constant': true 80 }, 81 'dequantizeLinearZeroPoint': { 82 'data': [3], 83 'descriptor': {shape: [], dataType: 'int8'}, 84 'constant': true 85 } 86 }, 87 'operators': [{ 88 'name': 'dequantizeLinear', 89 'arguments': [ 90 {'input': 'dequantizeLinearInput'}, 91 {'scale': 'dequantizeLinearScale'}, 92 {'zeroPoint': 'dequantizeLinearZeroPoint'} 93 ], 94 'outputs': 'dequantizeLinearOutput' 95 }], 96 'expectedOutputs': { 97 'dequantizeLinearOutput': { 98 'data': [134.43296813964844], 99 'descriptor': {shape: [], dataType: 'float32'} 100 } 101 } 102 } 103 }, 104 { 105 'name': 'dequantizeLinear uint8 1D constant tensor with float32 1D scale', 106 'graph': { 107 'inputs': { 108 'dequantizeLinearInput': { 109 'data': [12, 24, 35, 123], 110 'descriptor': {shape: [4], dataType: 'uint8'}, 111 'constant': true 112 }, 113 'dequantizeLinearScale': { 114 'data': [ 115 9.343092918395996, 116 0.2800687253475189, 117 4.617084980010986, 118 1.1202747821807861, 119 ], 120 'descriptor': {shape: [4], dataType: 'float32'}, 121 'constant': true 122 }, 123 'dequantizeLinearZeroPoint': { 124 'data': [128, 128, 128, 128], 125 'descriptor': {shape: [4], dataType: 'uint8'}, 126 'constant': true 127 } 128 }, 129 'operators': [{ 130 'name': 'dequantizeLinear', 131 'arguments': [ 132 {'input': 'dequantizeLinearInput'}, 133 {'scale': 'dequantizeLinearScale'}, 134 {'zeroPoint': 'dequantizeLinearZeroPoint'} 135 ], 136 'outputs': 'dequantizeLinearOutput' 137 }], 138 'expectedOutputs': { 139 'dequantizeLinearOutput': { 140 'data': [ 141 -1083.798828125, -29.127147674560547, -429.388916015625, 142 -5.601373672485352 143 ], 144 'descriptor': {shape: [4], dataType: 'float32'} 145 } 146 } 147 } 148 }, 149 { 150 'name': 151 'dequantizeLinear uint8 1D tensor with float32 1D scale, implicit block_size = 2', 152 'graph': { 153 'inputs': { 154 'dequantizeLinearInput': { 155 'data': [12, 24, 35, 123], 156 'descriptor': {shape: [4], dataType: 'uint8'}, 157 'constant': false 158 }, 159 'dequantizeLinearScale': { 160 'data': [ 161 9.343092918395996, 162 4.617084980010986, 163 ], 164 'descriptor': {shape: [2], dataType: 'float32'}, 165 'constant': true 166 }, 167 'dequantizeLinearZeroPoint': { 168 'data': [128, 110], 169 'descriptor': {shape: [2], dataType: 'uint8'}, 170 'constant': true 171 } 172 }, 173 'operators': [{ 174 'name': 'dequantizeLinear', 175 'arguments': [ 176 {'input': 'dequantizeLinearInput'}, 177 {'scale': 'dequantizeLinearScale'}, 178 {'zeroPoint': 'dequantizeLinearZeroPoint'} 179 ], 180 'outputs': 'dequantizeLinearOutput' 181 }], 182 'expectedOutputs': { 183 'dequantizeLinearOutput': { 184 'data': [ 185 -1083.798828125, -971.681640625, -346.2813720703125, 186 60.0221061706543 187 ], 188 'descriptor': {shape: [4], dataType: 'float32'} 189 } 190 } 191 } 192 }, 193 { 194 'name': 195 'dequantizeLinear int8 4D tensor broadcasting float32 4D scale and int8 4D zeroPoint', 196 'graph': { 197 'inputs': { 198 'dequantizeLinearInput': { 199 'data': [-124, 0, 23, 122], 200 'descriptor': {shape: [1, 1, 2, 2], dataType: 'int8'}, 201 'constant': false 202 }, 203 'dequantizeLinearScale': { 204 'data': [0.2800687253475189, 4.617084980010986], 205 'descriptor': {shape: [1, 1, 2, 1], dataType: 'float32'}, 206 'constant': true 207 }, 208 'dequantizeLinearZeroPoint': { 209 'data': [12, 12], 210 'descriptor': {shape: [1, 1, 2, 1], dataType: 'int8'}, 211 'constant': true 212 } 213 }, 214 'operators': [{ 215 'name': 'dequantizeLinear', 216 'arguments': [ 217 {'input': 'dequantizeLinearInput'}, 218 {'scale': 'dequantizeLinearScale'}, 219 {'zeroPoint': 'dequantizeLinearZeroPoint'} 220 ], 221 'outputs': 'dequantizeLinearOutput' 222 }], 223 'expectedOutputs': { 224 'dequantizeLinearOutput': { 225 'data': [ 226 -38.08934783935547, -3.3608245849609375, 50.787933349609375, 227 507.87933349609375 228 ], 229 'descriptor': {shape: [1, 1, 2, 2], dataType: 'float32'} 230 } 231 } 232 } 233 }, 234 { 235 'name': 236 'dequantizeLinear int8 2D tensor with float32 2D scale, block_size = [3, 2]', 237 'graph': { 238 'inputs': { 239 'dequantizeLinearInput': { 240 'data': [ 241 -124, 0, 23, 122, 12, 23, 45, 36, 67, 78, -22, 0, 242 -34, -45, -56, -67, 89, 30, 12, 23, 56, 67, 56, -12 243 ], 244 'descriptor': {shape: [6, 4], dataType: 'int8'}, 245 'constant': false 246 }, 247 'dequantizeLinearScale': { 248 'data': [ 249 0.2800687253475189, 4.617084980010986, 1.2800687253475189, 250 3.617084980010986 251 ], 252 'descriptor': {shape: [2, 2], dataType: 'float32'}, 253 'constant': true 254 }, 255 'dequantizeLinearZeroPoint': { 256 'data': [1, 3, 5, 12], 257 'descriptor': {shape: [2, 2], dataType: 'int8'}, 258 'constant': true 259 } 260 }, 261 'operators': [{ 262 'name': 'dequantizeLinear', 263 'arguments': [ 264 {'input': 'dequantizeLinearInput'}, 265 {'scale': 'dequantizeLinearScale'}, 266 {'zeroPoint': 'dequantizeLinearZeroPoint'} 267 ], 268 'outputs': 'dequantizeLinearOutput' 269 }], 270 'expectedOutputs': { 271 'dequantizeLinearOutput': { 272 'data': [ 273 -35.00859069824219, 274 -0.2800687253475189, 275 92.3416976928711, 276 549.43310546875, 277 3.0807559490203857, 278 6.1615118980407715, 279 193.91757202148438, 280 152.36380004882812, 281 18.484535217285156, 282 21.565292358398438, 283 -115.4271240234375, 284 -13.851255416870117, 285 -49.92267990112305, 286 -64.0034408569336, 287 -245.96177673339844, 288 -285.7497253417969, 289 107.52577209472656, 290 32.0017204284668, 291 0, 292 39.787933349609375, 293 65.28350830078125, 294 79.36426544189453, 295 159.1517333984375, 296 -86.81004333496094 297 ], 298 'descriptor': {shape: [6, 4], dataType: 'float32'} 299 } 300 } 301 } 302 }, 303 { 304 'name': 305 'dequantizeLinear uint4 1D tensor of even size with float32 1D scale', 306 'graph': { 307 'inputs': { 308 'dequantizeLinearInput': { 309 'data': [15, 0], 310 'descriptor': {shape: [2], dataType: 'uint4'}, 311 'constant': false 312 }, 313 'dequantizeLinearScale': { 314 'data': [1.1202747821807861, 1.1202747821807861], 315 'descriptor': {shape: [2], dataType: 'float32'}, 316 'constant': true 317 }, 318 'dequantizeLinearZeroPoint': { 319 'data': [0, 1], 320 'descriptor': {shape: [2], dataType: 'uint4'}, 321 'constant': true 322 } 323 }, 324 'operators': [{ 325 'name': 'dequantizeLinear', 326 'arguments': [ 327 {'input': 'dequantizeLinearInput'}, 328 {'scale': 'dequantizeLinearScale'}, 329 {'zeroPoint': 'dequantizeLinearZeroPoint'} 330 ], 331 'outputs': 'dequantizeLinearOutput' 332 }], 333 'expectedOutputs': { 334 'dequantizeLinearOutput': { 335 'data': [16.804121017456055, -1.1202747821807861], 336 'descriptor': {shape: [2], dataType: 'float32'} 337 } 338 } 339 } 340 }, 341 { 342 'name': 343 'dequantizeLinear uint4 1D tensor of odd size with float32 1D scale', 344 'graph': { 345 'inputs': { 346 'dequantizeLinearInput': { 347 'data': [10, 12, 14], 348 'descriptor': {shape: [3], dataType: 'uint4'}, 349 'constant': false 350 }, 351 'dequantizeLinearScale': { 352 'data': [1.1202747821807861], 353 'descriptor': {shape: [1], dataType: 'float32'}, 354 'constant': true 355 }, 356 'dequantizeLinearZeroPoint': { 357 'data': [2], 358 'descriptor': {shape: [1], dataType: 'uint4'}, 359 'constant': true 360 } 361 }, 362 'operators': [{ 363 'name': 'dequantizeLinear', 364 'arguments': [ 365 {'input': 'dequantizeLinearInput'}, 366 {'scale': 'dequantizeLinearScale'}, 367 {'zeroPoint': 'dequantizeLinearZeroPoint'} 368 ], 369 'outputs': 'dequantizeLinearOutput' 370 }], 371 'expectedOutputs': { 372 'dequantizeLinearOutput': { 373 'data': [8.962198257446289, 11.202747344970703, 13.443297386169434], 374 'descriptor': {shape: [3], dataType: 'float32'} 375 } 376 } 377 } 378 }, 379 { 380 'name': 381 'dequantizeLinear uint4 4D tensor with broadcasting float32 4D scale and uint4 4D zeroPoint', 382 'graph': { 383 'inputs': { 384 'dequantizeLinearInput': { 385 'data': [0, 1, 10, 15], 386 'descriptor': {shape: [1, 1, 2, 2], dataType: 'uint4'}, 387 'constant': false 388 }, 389 'dequantizeLinearScale': { 390 'data': [ 391 9.343092918395996, 392 4.617084980010986, 393 ], 394 'descriptor': {shape: [1, 1, 2, 1], dataType: 'float32'}, 395 'constant': true 396 }, 397 'dequantizeLinearZeroPoint': { 398 'data': [2, 3], 399 'descriptor': {shape: [1, 1, 2, 1], dataType: 'uint4'}, 400 'constant': true 401 } 402 }, 403 'operators': [{ 404 'name': 'dequantizeLinear', 405 'arguments': [ 406 {'input': 'dequantizeLinearInput'}, 407 {'scale': 'dequantizeLinearScale'}, 408 {'zeroPoint': 'dequantizeLinearZeroPoint'} 409 ], 410 'outputs': 'dequantizeLinearOutput' 411 }], 412 'expectedOutputs': { 413 'dequantizeLinearOutput': { 414 'data': [ 415 -18.686185836791992, -9.343092918395996, 32.31959533691406, 416 55.40502166748047 417 ], 418 'descriptor': {shape: [1, 1, 2, 2], dataType: 'float32'} 419 } 420 } 421 } 422 }, 423 { 424 'name': 425 'dequantizeLinear uint4 3D tensor with float32 3D scale, block_size = [1, 1, 2]', 426 'graph': { 427 'inputs': { 428 'dequantizeLinearInput': { 429 'data': [0, 1, 10, 15], 430 'descriptor': {shape: [1, 1, 4], dataType: 'uint4'}, 431 'constant': false 432 }, 433 'dequantizeLinearScale': { 434 'data': [ 435 9.343092918395996, 436 4.617084980010986, 437 ], 438 'descriptor': {shape: [1, 1, 2], dataType: 'float32'}, 439 'constant': true 440 }, 441 'dequantizeLinearZeroPoint': { 442 'data': [2, 3], 443 'descriptor': {shape: [1, 1, 2], dataType: 'uint4'}, 444 'constant': true 445 } 446 }, 447 'operators': [{ 448 'name': 'dequantizeLinear', 449 'arguments': [ 450 {'input': 'dequantizeLinearInput'}, 451 {'scale': 'dequantizeLinearScale'}, 452 {'zeroPoint': 'dequantizeLinearZeroPoint'} 453 ], 454 'outputs': 'dequantizeLinearOutput' 455 }], 456 'expectedOutputs': { 457 'dequantizeLinearOutput': { 458 'data': [ 459 -18.686185836791992, -9.343092918395996, 32.31959533691406, 460 55.40502166748047 461 ], 462 'descriptor': {shape: [1, 1, 4], dataType: 'float32'} 463 } 464 } 465 } 466 }, 467 { 468 'name': 469 'dequantizeLinear int4 1D tensor of even size with float32 1D scale', 470 'graph': { 471 'inputs': { 472 'dequantizeLinearInput': { 473 'data': [-8, -3], 474 'descriptor': {shape: [2], dataType: 'int4'}, 475 'constant': false 476 }, 477 'dequantizeLinearScale': { 478 'data': [1.1202747821807861, 1.1202747821807861], 479 'descriptor': {shape: [2], dataType: 'float32'}, 480 'constant': true 481 }, 482 'dequantizeLinearZeroPoint': { 483 'data': [0, -2], 484 'descriptor': {shape: [2], dataType: 'int4'}, 485 'constant': true 486 } 487 }, 488 'operators': [{ 489 'name': 'dequantizeLinear', 490 'arguments': [ 491 {'input': 'dequantizeLinearInput'}, 492 {'scale': 'dequantizeLinearScale'}, 493 {'zeroPoint': 'dequantizeLinearZeroPoint'} 494 ], 495 'outputs': 'dequantizeLinearOutput' 496 }], 497 'expectedOutputs': { 498 'dequantizeLinearOutput': { 499 'data': [-8.962198257446289, -1.1202747821807861], 500 'descriptor': {shape: [2], dataType: 'float32'} 501 } 502 } 503 } 504 }, 505 { 506 'name': 'dequantizeLinear int4 1D tensor of odd size with float32 1D scale', 507 'graph': { 508 'inputs': { 509 'dequantizeLinearInput': { 510 'data': [-1, 7, 0], 511 'descriptor': {shape: [3], dataType: 'int4'}, 512 'constant': false 513 }, 514 'dequantizeLinearScale': { 515 'data': [1.1202747821807861], 516 'descriptor': {shape: [1], dataType: 'float32'}, 517 'constant': true 518 }, 519 'dequantizeLinearZeroPoint': { 520 'data': [-3], 521 'descriptor': {shape: [1], dataType: 'int4'}, 522 'constant': true 523 } 524 }, 525 'operators': [{ 526 'name': 'dequantizeLinear', 527 'arguments': [ 528 {'input': 'dequantizeLinearInput'}, 529 {'scale': 'dequantizeLinearScale'}, 530 {'zeroPoint': 'dequantizeLinearZeroPoint'} 531 ], 532 'outputs': 'dequantizeLinearOutput' 533 }], 534 'expectedOutputs': { 535 'dequantizeLinearOutput': { 536 'data': [2.2405495643615723, 11.202747344970703, 3.3608243465423584], 537 'descriptor': {shape: [3], dataType: 'float32'} 538 } 539 } 540 } 541 }, 542 { 543 'name': 544 'per-tensor dequantizeLinear for int4 4D tensor with float32 4D scale', 545 'graph': { 546 'inputs': { 547 'dequantizeLinearInput': { 548 'data': [0, -1, -6, 1], 549 'descriptor': {shape: [1, 1, 2, 2], dataType: 'int4'}, 550 'constant': false 551 }, 552 'dequantizeLinearScale': { 553 'data': [ 554 1.1202747821807861, 4.617084980010986, 6.2405495643615723, 555 3.841923713684082 556 ], 557 'descriptor': {shape: [1, 1, 2, 2], dataType: 'float32'}, 558 'constant': true 559 }, 560 'dequantizeLinearZeroPoint': { 561 'data': [2, -3, -5, 4], 562 'descriptor': {shape: [1, 1, 2, 2], dataType: 'int4'}, 563 'constant': true 564 } 565 }, 566 'operators': [{ 567 'name': 'dequantizeLinear', 568 'arguments': [ 569 {'input': 'dequantizeLinearInput'}, 570 {'scale': 'dequantizeLinearScale'}, 571 {'zeroPoint': 'dequantizeLinearZeroPoint'} 572 ], 573 'outputs': 'dequantizeLinearOutput' 574 }], 575 'expectedOutputs': { 576 'dequantizeLinearOutput': { 577 'data': [ 578 -2.2405495643615723, 9.234169960021973, -6.240549564361572, 579 -11.525771141052246 580 ], 581 'descriptor': {shape: [1, 1, 2, 2], dataType: 'float32'} 582 } 583 } 584 } 585 }, 586 { 587 'name': 'dequantizeLinear int32 1D tensor with float32 1D scale', 588 'graph': { 589 'inputs': { 590 'dequantizeLinearInput': { 591 'data': [12345, 23946213], 592 'descriptor': {shape: [2], dataType: 'int32'}, 593 'constant': false 594 }, 595 'dequantizeLinearScale': { 596 'data': [1.1202747821807861, 0.2800687253475189], 597 'descriptor': {shape: [2], dataType: 'float32'}, 598 'constant': true 599 }, 600 'dequantizeLinearZeroPoint': { 601 'data': [32345, -2445234], 602 'descriptor': {shape: [2], dataType: 'int32'}, 603 'constant': true 604 } 605 }, 606 'operators': [{ 607 'name': 'dequantizeLinear', 608 'arguments': [ 609 {'input': 'dequantizeLinearInput'}, 610 {'scale': 'dequantizeLinearScale'}, 611 {'zeroPoint': 'dequantizeLinearZeroPoint'} 612 ], 613 'outputs': 'dequantizeLinearOutput' 614 }], 615 'expectedOutputs': { 616 'dequantizeLinearOutput': { 617 'data': [-22405.495643615723, 7391418.921366602], 618 'descriptor': {shape: [2], dataType: 'float32'} 619 } 620 } 621 } 622 }, 623 { 624 'name': 'dequantizeLinear with float32 3D scale as an intermediate node', 625 'graph': { 626 'inputs': { 627 'dequantizeLinearInput': { 628 'data': [34, 23], 629 'descriptor': {shape: [2, 1], dataType: 'int32'}, 630 'constant': false 631 }, 632 'dequantizeLinearScale': { 633 'data': [1.1202747821807861, 0.2800687253475189], 634 'descriptor': {shape: [1, 1, 2], dataType: 'float32'}, 635 'constant': true 636 }, 637 'dequantizeLinearZeroPoint': { 638 'data': [35, -24], 639 'descriptor': {shape: [1, 1, 2], dataType: 'int32'}, 640 'constant': true 641 } 642 }, 643 'operators': [ 644 { 645 'name': 'transpose', 646 'arguments': [ 647 {'input': 'dequantizeLinearInput'}, { 648 'options': { 649 'permutation': [1, 0], 650 } 651 } 652 ], 653 'outputs': 'transposeOutput' 654 }, 655 { 656 'name': 'reshape', 657 'arguments': [{'input': 'transposeOutput'}, {'newShape': [1, 1, 2]}], 658 'outputs': 'reshapeOutput' 659 }, 660 { 661 'name': 'dequantizeLinear', 662 'arguments': [ 663 {'input': 'reshapeOutput'}, {'scale': 'dequantizeLinearScale'}, 664 {'zeroPoint': 'dequantizeLinearZeroPoint'} 665 ], 666 'outputs': 'dequantizeLinearOutput' 667 } 668 ], 669 'expectedOutputs': { 670 'dequantizeLinearOutput': { 671 'data': [-1.1202747821807861, 13.163229942321777], 672 'descriptor': {shape: [1, 1, 2], dataType: 'float32'} 673 } 674 } 675 } 676 }, 677 , 678 { 679 'name': 680 'quantizeLinear then dequantizeLinear with different float32 scale and int8 zeroPoint', 681 'graph': { 682 'inputs': { 683 'quantizeLinearInput': { 684 'data': [-1.1202747821807861, 13.163229942321777], 685 'descriptor': {shape: [2], dataType: 'float32'}, 686 'constant': false 687 }, 688 'quantizeLinearScale': { 689 'data': [0.1202747821807861, 1.2800687253475189], 690 'descriptor': {shape: [2], dataType: 'float32'}, 691 'constant': true 692 }, 693 'quantizeLinearZeroPoint': { 694 'data': [12, -21], 695 'descriptor': {shape: [2], dataType: 'int8'}, 696 'constant': true 697 }, 698 'dequantizeLinearScale': { 699 'data': [1.1202747821807861, 0.2800687253475189], 700 'descriptor': {shape: [2], dataType: 'float32'}, 701 'constant': true 702 }, 703 'dequantizeLinearZeroPoint': { 704 'data': [35, -24], 705 'descriptor': {shape: [2], dataType: 'int8'}, 706 'constant': true 707 } 708 }, 709 'operators': [ 710 { 711 'name': 'quantizeLinear', 712 'arguments': [ 713 {'input': 'quantizeLinearInput'}, {'scale': 'quantizeLinearScale'}, 714 {'zeroPoint': 'quantizeLinearZeroPoint'} 715 ], 716 'outputs': 'quantizeLinearOutput' 717 }, 718 { 719 'name': 'dequantizeLinear', 720 'arguments': [ 721 {'input': 'quantizeLinearOutput'}, 722 {'scale': 'dequantizeLinearScale'}, 723 {'zeroPoint': 'dequantizeLinearZeroPoint'} 724 ], 725 'outputs': 'dequantizeLinearOutput' 726 } 727 ], 728 'expectedOutputs': { 729 'dequantizeLinearOutput': { 730 'data': [-35.848793029785156, 3.6408934593200684], 731 'descriptor': {shape: [2], dataType: 'float32'} 732 } 733 } 734 } 735 }, 736 737 // float16 tests 738 { 739 'name': 'dequantizeLinear int8 0D tensor with float16 0D scale', 740 'graph': { 741 'inputs': { 742 'dequantizeLinearInput': { 743 'data': [123], 744 'descriptor': {'shape': [], 'dataType': 'int8'}, 745 'constant': false 746 }, 747 'dequantizeLinearScale': { 748 'data': [1.1201171875], 749 'descriptor': {'shape': [], 'dataType': 'float16'}, 750 'constant': true 751 }, 752 'dequantizeLinearZeroPoint': { 753 'data': [3], 754 'descriptor': {'shape': [], 'dataType': 'int8'}, 755 'constant': true 756 } 757 }, 758 'operators': [{ 759 'name': 'dequantizeLinear', 760 'arguments': [ 761 {'input': 'dequantizeLinearInput'}, 762 {'scale': 'dequantizeLinearScale'}, 763 {'zeroPoint': 'dequantizeLinearZeroPoint'} 764 ], 765 'outputs': 'dequantizeLinearOutput' 766 }], 767 'expectedOutputs': { 768 'dequantizeLinearOutput': { 769 'data': [134.375], 770 'descriptor': {'shape': [], 'dataType': 'float16'} 771 } 772 } 773 } 774 }, 775 { 776 'name': 777 'dequantizeLinear int8 0D constant tensor with float16 0D scale', 778 'graph': { 779 'inputs': { 780 'dequantizeLinearInput': { 781 'data': [123], 782 'descriptor': {'shape': [], 'dataType': 'int8'}, 783 'constant': true 784 }, 785 'dequantizeLinearScale': { 786 'data': [1.1201171875], 787 'descriptor': {'shape': [], 'dataType': 'float16'}, 788 'constant': true 789 }, 790 'dequantizeLinearZeroPoint': { 791 'data': [3], 792 'descriptor': {'shape': [], 'dataType': 'int8'}, 793 'constant': true 794 } 795 }, 796 'operators': [{ 797 'name': 'dequantizeLinear', 798 'arguments': [ 799 {'input': 'dequantizeLinearInput'}, 800 {'scale': 'dequantizeLinearScale'}, 801 {'zeroPoint': 'dequantizeLinearZeroPoint'} 802 ], 803 'outputs': 'dequantizeLinearOutput' 804 }], 805 'expectedOutputs': { 806 'dequantizeLinearOutput': { 807 'data': [134.375], 808 'descriptor': {'shape': [], 'dataType': 'float16'} 809 } 810 } 811 } 812 }, 813 { 814 'name': 'dequantizeLinear uint8 1D tensor with float16 1D scale', 815 'graph': { 816 'inputs': { 817 'dequantizeLinearInput': { 818 'data': [12, 24, 35, 123], 819 'descriptor': {'shape': [4], 'dataType': 'uint8'}, 820 'constant': false 821 }, 822 'dequantizeLinearScale': { 823 'data': [9.34375, 0.280029296875, 4.6171875, 1.1201171875], 824 'descriptor': {'shape': [4], 'dataType': 'float16'}, 825 'constant': true 826 }, 827 'dequantizeLinearZeroPoint': { 828 'data': [128, 128, 128, 128], 829 'descriptor': {'shape': [4], 'dataType': 'uint8'}, 830 'constant': true 831 } 832 }, 833 'operators': [{ 834 'name': 'dequantizeLinear', 835 'arguments': [ 836 {'input': 'dequantizeLinearInput'}, 837 {'scale': 'dequantizeLinearScale'}, 838 {'zeroPoint': 'dequantizeLinearZeroPoint'} 839 ], 840 'outputs': 'dequantizeLinearOutput' 841 }], 842 'expectedOutputs': { 843 'dequantizeLinearOutput': { 844 'data': [-1084, -29.125, -429.5, -5.6015625], 845 'descriptor': {'shape': [4], 'dataType': 'float16'} 846 } 847 } 848 } 849 }, 850 { 851 'name': 852 'dequantizeLinear uint8 1D tensor with float16 1D scale, implicit block_size = 2', 853 'graph': { 854 'inputs': { 855 'dequantizeLinearInput': { 856 'data': [12, 24, 35, 123], 857 'descriptor': {'shape': [4], 'dataType': 'uint8'}, 858 'constant': false 859 }, 860 'dequantizeLinearScale': { 861 'data': [9.34375, 4.6171875], 862 'descriptor': {'shape': [2], 'dataType': 'float16'}, 863 'constant': true 864 }, 865 'dequantizeLinearZeroPoint': { 866 'data': [128, 110], 867 'descriptor': {'shape': [2], 'dataType': 'uint8'}, 868 'constant': true 869 } 870 }, 871 'operators': [{ 872 'name': 'dequantizeLinear', 873 'arguments': [ 874 {'input': 'dequantizeLinearInput'}, 875 {'scale': 'dequantizeLinearScale'}, 876 {'zeroPoint': 'dequantizeLinearZeroPoint'} 877 ], 878 'outputs': 'dequantizeLinearOutput' 879 }], 880 'expectedOutputs': { 881 'dequantizeLinearOutput': { 882 'data': [-1084, -972, -346.25, 60.03125], 883 'descriptor': {'shape': [4], 'dataType': 'float16'} 884 } 885 } 886 } 887 }, 888 { 889 'name': 890 'dequantizeLinear int8 4D tensor broadcasting float16 4D scale and int8 4D zeroPoint', 891 'graph': { 892 'inputs': { 893 'dequantizeLinearInput': { 894 'data': [-124, 0, 23, 122], 895 'descriptor': {'shape': [1, 1, 2, 2], 'dataType': 'int8'}, 896 'constant': false 897 }, 898 'dequantizeLinearScale': { 899 'data': [0.280029296875, 4.6171875], 900 'descriptor': {'shape': [1, 1, 2, 1], 'dataType': 'float16'}, 901 'constant': true 902 }, 903 'dequantizeLinearZeroPoint': { 904 'data': [12, 12], 905 'descriptor': {'shape': [1, 1, 2, 1], 'dataType': 'int8'}, 906 'constant': true 907 } 908 }, 909 'operators': [{ 910 'name': 'dequantizeLinear', 911 'arguments': [ 912 {'input': 'dequantizeLinearInput'}, 913 {'scale': 'dequantizeLinearScale'}, 914 {'zeroPoint': 'dequantizeLinearZeroPoint'} 915 ], 916 'outputs': 'dequantizeLinearOutput' 917 }], 918 'expectedOutputs': { 919 'dequantizeLinearOutput': { 920 'data': [-38.09375, -3.359375, 50.78125, 508], 921 'descriptor': {'shape': [1, 1, 2, 2], 'dataType': 'float16'} 922 } 923 } 924 } 925 }, 926 { 927 'name': 928 'dequantizeLinear int8 2D tensor with float16 2D scale, block_size = [3, 2]', 929 'graph': { 930 'inputs': { 931 'dequantizeLinearInput': { 932 'data': [ 933 -124, 0, 23, 122, 12, 23, 45, 36, 67, 78, -22, 0, 934 -34, -45, -56, -67, 89, 30, 12, 23, 56, 67, 56, -12 935 ], 936 'descriptor': {'shape': [6, 4], 'dataType': 'int8'}, 937 'constant': false 938 }, 939 'dequantizeLinearScale': { 940 'data': [0.280029296875, 4.6171875, 1.2802734375, 3.6171875], 941 'descriptor': {'shape': [2, 2], 'dataType': 'float16'}, 942 'constant': true 943 }, 944 'dequantizeLinearZeroPoint': { 945 'data': [1, 3, 5, 12], 946 'descriptor': {'shape': [2, 2], 'dataType': 'int8'}, 947 'constant': true 948 } 949 }, 950 'operators': [{ 951 'name': 'dequantizeLinear', 952 'arguments': [ 953 {'input': 'dequantizeLinearInput'}, 954 {'scale': 'dequantizeLinearScale'}, 955 {'zeroPoint': 'dequantizeLinearZeroPoint'} 956 ], 957 'outputs': 'dequantizeLinearOutput' 958 }], 959 'expectedOutputs': { 960 'dequantizeLinearOutput': { 961 'data': [ 962 -35, -0.280029296875, 92.375, 549.5, 3.080078125, 963 6.16015625, 193.875, 152.375, 18.484375, 21.5625, 964 -115.4375, -13.8515625, -49.9375, -64, -246, 965 -285.75, 107.5625, 32, 0, 39.78125, 966 65.3125, 79.375, 159.125, -86.8125 967 ], 968 'descriptor': {'shape': [6, 4], 'dataType': 'float16'} 969 } 970 } 971 } 972 }, 973 { 974 'name': 975 'dequantizeLinear uint4 1D tensor of even size with float16 1D scale', 976 'graph': { 977 'inputs': { 978 'dequantizeLinearInput': { 979 'data': [15, 0], 980 'descriptor': {'shape': [2], 'dataType': 'uint4'}, 981 'constant': false 982 }, 983 'dequantizeLinearScale': { 984 'data': [1.1201171875, 1.1201171875], 985 'descriptor': {'shape': [2], 'dataType': 'float16'}, 986 'constant': true 987 }, 988 'dequantizeLinearZeroPoint': { 989 'data': [0, 1], 990 'descriptor': {'shape': [2], 'dataType': 'uint4'}, 991 'constant': true 992 } 993 }, 994 'operators': [{ 995 'name': 'dequantizeLinear', 996 'arguments': [ 997 {'input': 'dequantizeLinearInput'}, 998 {'scale': 'dequantizeLinearScale'}, 999 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1000 ], 1001 'outputs': 'dequantizeLinearOutput' 1002 }], 1003 'expectedOutputs': { 1004 'dequantizeLinearOutput': { 1005 'data': [16.796875, -1.1201171875], 1006 'descriptor': {'shape': [2], 'dataType': 'float16'} 1007 } 1008 } 1009 } 1010 }, 1011 { 1012 'name': 1013 'dequantizeLinear uint4 1D tensor of odd size with float16 1D scale', 1014 'graph': { 1015 'inputs': { 1016 'dequantizeLinearInput': { 1017 'data': [10, 12, 14], 1018 'descriptor': {'shape': [3], 'dataType': 'uint4'}, 1019 'constant': false 1020 }, 1021 'dequantizeLinearScale': { 1022 'data': [1.1201171875], 1023 'descriptor': {'shape': [1], 'dataType': 'float16'}, 1024 'constant': true 1025 }, 1026 'dequantizeLinearZeroPoint': { 1027 'data': [2], 1028 'descriptor': {'shape': [1], 'dataType': 'uint4'}, 1029 'constant': true 1030 } 1031 }, 1032 'operators': [{ 1033 'name': 'dequantizeLinear', 1034 'arguments': [ 1035 {'input': 'dequantizeLinearInput'}, 1036 {'scale': 'dequantizeLinearScale'}, 1037 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1038 ], 1039 'outputs': 'dequantizeLinearOutput' 1040 }], 1041 'expectedOutputs': { 1042 'dequantizeLinearOutput': { 1043 'data': [8.9609375, 11.203125, 13.4375], 1044 'descriptor': {'shape': [3], 'dataType': 'float16'} 1045 } 1046 } 1047 } 1048 }, 1049 { 1050 'name': 1051 'dequantizeLinear uint4 4D tensor with broadcasting float16 4D scale and uint4 4D zeroPoint', 1052 'graph': { 1053 'inputs': { 1054 'dequantizeLinearInput': { 1055 'data': [0, 1, 10, 15], 1056 'descriptor': {'shape': [1, 1, 2, 2], 'dataType': 'uint4'}, 1057 'constant': false 1058 }, 1059 'dequantizeLinearScale': { 1060 'data': [9.34375, 4.6171875], 1061 'descriptor': {'shape': [1, 1, 2, 1], 'dataType': 'float16'}, 1062 'constant': true 1063 }, 1064 'dequantizeLinearZeroPoint': { 1065 'data': [2, 3], 1066 'descriptor': {'shape': [1, 1, 2, 1], 'dataType': 'uint4'}, 1067 'constant': true 1068 } 1069 }, 1070 'operators': [{ 1071 'name': 'dequantizeLinear', 1072 'arguments': [ 1073 {'input': 'dequantizeLinearInput'}, 1074 {'scale': 'dequantizeLinearScale'}, 1075 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1076 ], 1077 'outputs': 'dequantizeLinearOutput' 1078 }], 1079 'expectedOutputs': { 1080 'dequantizeLinearOutput': { 1081 'data': [-18.6875, -9.34375, 32.3125, 55.40625], 1082 'descriptor': {'shape': [1, 1, 2, 2], 'dataType': 'float16'} 1083 } 1084 } 1085 } 1086 }, 1087 { 1088 'name': 1089 'dequantizeLinear uint4 3D tensor with float16 3D scale, block_size = [1, 1, 2]', 1090 'graph': { 1091 'inputs': { 1092 'dequantizeLinearInput': { 1093 'data': [0, 1, 10, 15], 1094 'descriptor': {'shape': [1, 1, 4], 'dataType': 'uint4'}, 1095 'constant': false 1096 }, 1097 'dequantizeLinearScale': { 1098 'data': [9.34375, 4.6171875], 1099 'descriptor': {'shape': [1, 1, 2], 'dataType': 'float16'}, 1100 'constant': true 1101 }, 1102 'dequantizeLinearZeroPoint': { 1103 'data': [2, 3], 1104 'descriptor': {'shape': [1, 1, 2], 'dataType': 'uint4'}, 1105 'constant': true 1106 } 1107 }, 1108 'operators': [{ 1109 'name': 'dequantizeLinear', 1110 'arguments': [ 1111 {'input': 'dequantizeLinearInput'}, 1112 {'scale': 'dequantizeLinearScale'}, 1113 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1114 ], 1115 'outputs': 'dequantizeLinearOutput' 1116 }], 1117 'expectedOutputs': { 1118 'dequantizeLinearOutput': { 1119 'data': [-18.6875, -9.34375, 32.3125, 55.40625], 1120 'descriptor': {'shape': [1, 1, 4], 'dataType': 'float16'} 1121 } 1122 } 1123 } 1124 }, 1125 { 1126 'name': 1127 'dequantizeLinear int4 1D tensor of even size with float16 1D scale', 1128 'graph': { 1129 'inputs': { 1130 'dequantizeLinearInput': { 1131 'data': [-8, -3], 1132 'descriptor': {'shape': [2], 'dataType': 'int4'}, 1133 'constant': false 1134 }, 1135 'dequantizeLinearScale': { 1136 'data': [1.1201171875, 1.1201171875], 1137 'descriptor': {'shape': [2], 'dataType': 'float16'}, 1138 'constant': true 1139 }, 1140 'dequantizeLinearZeroPoint': { 1141 'data': [0, -2], 1142 'descriptor': {'shape': [2], 'dataType': 'int4'}, 1143 'constant': true 1144 } 1145 }, 1146 'operators': [{ 1147 'name': 'dequantizeLinear', 1148 'arguments': [ 1149 {'input': 'dequantizeLinearInput'}, 1150 {'scale': 'dequantizeLinearScale'}, 1151 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1152 ], 1153 'outputs': 'dequantizeLinearOutput' 1154 }], 1155 'expectedOutputs': { 1156 'dequantizeLinearOutput': { 1157 'data': [-8.9609375, -1.1201171875], 1158 'descriptor': {'shape': [2], 'dataType': 'float16'} 1159 } 1160 } 1161 } 1162 }, 1163 { 1164 'name': 'dequantizeLinear int4 1D tensor of odd size with float16 1D scale', 1165 'graph': { 1166 'inputs': { 1167 'dequantizeLinearInput': { 1168 'data': [-1, 7, 0], 1169 'descriptor': {'shape': [3], 'dataType': 'int4'}, 1170 'constant': false 1171 }, 1172 'dequantizeLinearScale': { 1173 'data': [1.1201171875], 1174 'descriptor': {'shape': [1], 'dataType': 'float16'}, 1175 'constant': true 1176 }, 1177 'dequantizeLinearZeroPoint': { 1178 'data': [-3], 1179 'descriptor': {'shape': [1], 'dataType': 'int4'}, 1180 'constant': true 1181 } 1182 }, 1183 'operators': [{ 1184 'name': 'dequantizeLinear', 1185 'arguments': [ 1186 {'input': 'dequantizeLinearInput'}, 1187 {'scale': 'dequantizeLinearScale'}, 1188 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1189 ], 1190 'outputs': 'dequantizeLinearOutput' 1191 }], 1192 'expectedOutputs': { 1193 'dequantizeLinearOutput': { 1194 'data': [2.240234375, 11.203125, 3.359375], 1195 'descriptor': {'shape': [3], 'dataType': 'float16'} 1196 } 1197 } 1198 } 1199 }, 1200 { 1201 'name': 1202 'per-tensor dequantizeLinear for int4 4D tensor with float16 4D scale', 1203 'graph': { 1204 'inputs': { 1205 'dequantizeLinearInput': { 1206 'data': [0, -1, -6, 1], 1207 'descriptor': {'shape': [1, 1, 2, 2], 'dataType': 'int4'}, 1208 'constant': false 1209 }, 1210 'dequantizeLinearScale': { 1211 'data': [1.1201171875, 4.6171875, 6.2421875, 3.841796875], 1212 'descriptor': {'shape': [1, 1, 2, 2], 'dataType': 'float16'}, 1213 'constant': true 1214 }, 1215 'dequantizeLinearZeroPoint': { 1216 'data': [2, -3, -5, 4], 1217 'descriptor': {'shape': [1, 1, 2, 2], 'dataType': 'int4'}, 1218 'constant': true 1219 } 1220 }, 1221 'operators': [{ 1222 'name': 'dequantizeLinear', 1223 'arguments': [ 1224 {'input': 'dequantizeLinearInput'}, 1225 {'scale': 'dequantizeLinearScale'}, 1226 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1227 ], 1228 'outputs': 'dequantizeLinearOutput' 1229 }], 1230 'expectedOutputs': { 1231 'dequantizeLinearOutput': { 1232 'data': [-2.240234375, 9.234375, -6.2421875, -11.5234375], 1233 'descriptor': {'shape': [1, 1, 2, 2], 'dataType': 'float16'} 1234 } 1235 } 1236 } 1237 }, 1238 { 1239 'name': 'dequantizeLinear int32 1D tensor with float16 1D scale', 1240 'graph': { 1241 'inputs': { 1242 'dequantizeLinearInput': { 1243 'data': [12345, 65504], 1244 'descriptor': {'shape': [2], 'dataType': 'int32'}, 1245 'constant': false 1246 }, 1247 'dequantizeLinearScale': { 1248 'data': [1.1201171875, 0.280029296875], 1249 'descriptor': {'shape': [2], 'dataType': 'float16'}, 1250 'constant': true 1251 }, 1252 'dequantizeLinearZeroPoint': { 1253 'data': [32345, 0], 1254 'descriptor': {'shape': [2], 'dataType': 'int32'}, 1255 'constant': true 1256 } 1257 }, 1258 'operators': [{ 1259 'name': 'dequantizeLinear', 1260 'arguments': [ 1261 {'input': 'dequantizeLinearInput'}, 1262 {'scale': 'dequantizeLinearScale'}, 1263 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1264 ], 1265 'outputs': 'dequantizeLinearOutput' 1266 }], 1267 'expectedOutputs': { 1268 'dequantizeLinearOutput': { 1269 'data': [-22400, 18336], 1270 'descriptor': {'shape': [2], 'dataType': 'float16'} 1271 } 1272 } 1273 } 1274 }, 1275 { 1276 'name': 'dequantizeLinear with float16 3D scale as an intermediate node', 1277 'graph': { 1278 'inputs': { 1279 'dequantizeLinearInput': { 1280 'data': [34, 23], 1281 'descriptor': {'shape': [2, 1], 'dataType': 'int32'}, 1282 'constant': false 1283 }, 1284 'dequantizeLinearScale': { 1285 'data': [1.1201171875, 0.280029296875], 1286 'descriptor': {'shape': [1, 1, 2], 'dataType': 'float16'}, 1287 'constant': true 1288 }, 1289 'dequantizeLinearZeroPoint': { 1290 'data': [35, -24], 1291 'descriptor': {'shape': [1, 1, 2], 'dataType': 'int32'}, 1292 'constant': true 1293 } 1294 }, 1295 'operators': [ 1296 { 1297 'name': 'transpose', 1298 'arguments': [ 1299 {'input': 'dequantizeLinearInput'}, 1300 {'options': {'permutation': [1, 0]}} 1301 ], 1302 'outputs': 'transposeOutput' 1303 }, 1304 { 1305 'name': 'reshape', 1306 'arguments': [{'input': 'transposeOutput'}, {'newShape': [1, 1, 2]}], 1307 'outputs': 'reshapeOutput' 1308 }, 1309 { 1310 'name': 'dequantizeLinear', 1311 'arguments': [ 1312 {'input': 'reshapeOutput'}, {'scale': 'dequantizeLinearScale'}, 1313 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1314 ], 1315 'outputs': 'dequantizeLinearOutput' 1316 } 1317 ], 1318 'expectedOutputs': { 1319 'dequantizeLinearOutput': { 1320 'data': [-1.1201171875, 13.1640625], 1321 'descriptor': {'shape': [1, 1, 2], 'dataType': 'float16'} 1322 } 1323 } 1324 } 1325 }, 1326 { 1327 'name': 1328 'quantizeLinear then dequantizeLinear with different float16 scale and int8 zeroPoint', 1329 'graph': { 1330 'inputs': { 1331 'quantizeLinearInput': { 1332 'data': [-1.1201171875, 13.1640625], 1333 'descriptor': {'shape': [2], 'dataType': 'float16'}, 1334 'constant': false 1335 }, 1336 'quantizeLinearScale': { 1337 'data': [0.12030029296875, 1.2802734375], 1338 'descriptor': {'shape': [2], 'dataType': 'float16'}, 1339 'constant': true 1340 }, 1341 'quantizeLinearZeroPoint': { 1342 'data': [12, -21], 1343 'descriptor': {'shape': [2], 'dataType': 'int8'}, 1344 'constant': true 1345 }, 1346 'dequantizeLinearScale': { 1347 'data': [1.1201171875, 0.280029296875], 1348 'descriptor': {'shape': [2], 'dataType': 'float16'}, 1349 'constant': true 1350 }, 1351 'dequantizeLinearZeroPoint': { 1352 'data': [35, -24], 1353 'descriptor': {'shape': [2], 'dataType': 'int8'}, 1354 'constant': true 1355 } 1356 }, 1357 'operators': [ 1358 { 1359 'name': 'quantizeLinear', 1360 'arguments': [ 1361 {'input': 'quantizeLinearInput'}, {'scale': 'quantizeLinearScale'}, 1362 {'zeroPoint': 'quantizeLinearZeroPoint'} 1363 ], 1364 'outputs': 'quantizeLinearOutput' 1365 }, 1366 { 1367 'name': 'dequantizeLinear', 1368 'arguments': [ 1369 {'input': 'quantizeLinearOutput'}, 1370 {'scale': 'dequantizeLinearScale'}, 1371 {'zeroPoint': 'dequantizeLinearZeroPoint'} 1372 ], 1373 'outputs': 'dequantizeLinearOutput' 1374 } 1375 ], 1376 'expectedOutputs': { 1377 'dequantizeLinearOutput': { 1378 'data': [-35.84375, 3.640625], 1379 'descriptor': {'shape': [2], 'dataType': 'float16'} 1380 } 1381 } 1382 } 1383 } 1384 ]; 1385 1386 webnn_conformance_test( 1387 dequantizeLinearTests, buildAndExecuteGraph, 1388 getDequantizeLinearPrecisionTolerance);