Repository: microsoft/onnxruntime
File: onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc (C++)

Code before:
      {},                            // output_padding
      vector<int64_t>{2, 1, 1, 14},  // output_shape
      vector<int64_t>{0, 0, 0, 0},   // pads
      vector<int64_t>{1, 1},         // strides
      vector<int64_t>{1, 1},         // dilations
      1,                             // group
      "NOTSET"                       // auto_pad
  };
  vector<float> X = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
                     10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f};
  vector<int64_t> X_shape = {2, 1, 1, 10};
  vector<float> W = {1.0f, 2.0f, 3.0f, 2.0f, 1.0f};
  vector<int64_t> W_shape = {1, 1, 1, 5};
  vector<float> B = {1.0f, 2.0f};
  vector<int64_t> B_shape = {1, 2};  // invalid bias rank (it should be 1-D)
  vector<int64_t> Y_shape = {2, 1, 1, 14};
  vector<float> expected_vals = {1.0f, 2.0f, 5.0f, 11.0f, 19.0f, 28.0f, 37.0f, 46.0f, 55.0f, 64.0f, 63.0f, 51.0f, 27.0f, 10.0f,
                                 11.0f, 32.0f, 65.0f, 91.0f, 109.0f, 118.0f, 127.0f, 136.0f, 145.0f, 154.0f, 143.0f, 111.0f, 57.0f, 20.0f};
  TestConvTransposeOp(attrs, {X, W, B}, {X_shape, W_shape, B_shape}, expected_vals, Y_shape,
                      OpTester::ExpectResult::kExpectFailure,
                      // Just ensure that it starts with the expected string.
                      "Bias shape is not compatible with number of output channels. "
                      "It should be a 1-D tensor with size num_output_channels(M).",
                      // The EP exclusions are along the same lines as ConvTranspose_InvalidKernelShape which
                      // also tests for invalid shapes. It also includes XnnPack which seems to have its own
                      // way of dealing with incorreclty shaped bias.
                      {kTensorrtExecutionProvider, kQnnExecutionProvider,
                       kDmlExecutionProvider, kXnnpackExecutionProvider,
                       kWebGpuExecutionProvider});  // Remove when https://github.com/microsoft/onnxruntime/issues/27210 is fixed
}

TEST(ConvTransposeTest, ConvTranspose_onnx) {
  ConvTransposeOpAttributes attrs = {
      vector<int64_t>{3, 3},        // kernel_shape
      {},                           // output_padding
      {},                           // output_shape
      vector<int64_t>{0, 0, 0, 0},  // pads
      vector<int64_t>{1, 1},        // strides
      vector<int64_t>{1, 1},        // dilations
      1,                            // group
      "NOTSET"                      // auto_pad
  };
  vector<float> X = {0., 1., 2., 3., 4., 5., 6., 7., 8.};
  vector<int64_t> X_shape = {1, 1, 3, 3};
  vector<float> W = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17.};
  vector<int64_t> W_shape = {1, 2, 3, 3};
  vector<int64_t> Y_shape = {1, 2, 5, 5};
  vector<float> expected_vals = {
      0.f, 0.f, 1.f, 4.f, 4.f,
      0.f, 6.f, 20.f, 26.f, 20.f,
      9.f, 36.f, 84.f, 84.f, 57.f,

Review comment (bug):
```suggestion
                      // way of dealing with incorrectly shaped bias.
```

Code after:
      {},                            // output_padding
      vector<int64_t>{2, 1, 1, 14},  // output_shape
      vector<int64_t>{0, 0, 0, 0},   // pads
      vector<int64_t>{1, 1},         // strides
      vector<int64_t>{1, 1},         // dilations
      1,                             // group
      "NOTSET"                       // auto_pad
  };
  vector<float> X = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
                     10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f};
  vector<int64_t> X_shape = {2, 1, 1, 10};
  vector<float> W = {1.0f, 2.0f, 3.0f, 2.0f, 1.0f};
  vector<int64_t> W_shape = {1, 1, 1, 5};
  vector<float> B = {1.0f, 2.0f};
  vector<int64_t> B_shape = {1, 2};  // invalid bias rank (it should be 1-D)
  vector<int64_t> Y_shape = {2, 1, 1, 14};
  vector<float> expected_vals = {1.0f, 2.0f, 5.0f, 11.0f, 19.0f, 28.0f, 37.0f, 46.0f, 55.0f, 64.0f, 63.0f, 51.0f, 27.0f, 10.0f,
                                 11.0f, 32.0f, 65.0f, 91.0f, 109.0f, 118.0f, 127.0f, 136.0f, 145.0f, 154.0f, 143.0f, 111.0f, 57.0f, 20.0f};
  TestConvTransposeOp(attrs, {X, W, B}, {X_shape, W_shape, B_shape}, expected_vals, Y_shape,
                      OpTester::ExpectResult::kExpectFailure,
                      // Just ensure that it starts with the expected string.
                      "Bias shape is not compatible with number of output channels. "
                      "It should be a 1-D tensor with size num_output_channels(M).",
                      // The EP exclusions are along the same lines as ConvTranspose_InvalidKernelShape which
                      // also tests for invalid shapes. It also includes XnnPack which seems to have its own
                      // way of dealing with incorrectly shaped bias.
                      {kTensorrtExecutionProvider, kQnnExecutionProvider,
                       kDmlExecutionProvider, kXnnpackExecutionProvider,
                       kWebGpuExecutionProvider});  // Remove when https://github.com/microsoft/onnxruntime/issues/27210 is fixed
}

TEST(ConvTransposeTest, ConvTranspose_onnx) {
  ConvTransposeOpAttributes attrs = {
      vector<int64_t>{3, 3},        // kernel_shape
      {},                           // output_padding
      {},                           // output_shape
      vector<int64_t>{0, 0, 0, 0},  // pads
      vector<int64_t>{1, 1},        // strides
      vector<int64_t>{1, 1},        // dilations
      1,                            // group
      "NOTSET"                      // auto_pad
  };
  vector<float> X = {0., 1., 2., 3., 4., 5., 6., 7., 8.};
  vector<int64_t> X_shape = {1, 1, 3, 3};
  vector<float> W = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17.};
  vector<int64_t> W_shape = {1, 2, 3, 3};
  vector<int64_t> Y_shape = {1, 2, 5, 5};
  vector<float> expected_vals = {
      0.f, 0.f, 1.f, 4.f, 4.f,
      0.f, 6.f, 20.f, 26.f, 20.f,
      9.f, 36.f, 84.f, 84.f, 57.f,