tensorflow/core/kernels/quantized_matmul_op_test.cc
// This test multiplies two 1x1 8bit matrices, and compares the
// results with hand-calculated expectations.
This test multiplies two 1x1 8bit matrices, and compares the
results with hand-calculated expectations.
This test multiplies two 1x1 8bit matrices and compares the results with hand - calculated expectations .
TEST_F(QuantizedMatMulTest, VerySmall_WithParams) {
  const bool transpose_a = true;
  const int a_rows = 1;
  const int a_cols = 1;
  const int b_rows = 1;
  const int b_cols = 1;
  const bool transpose_b = false;
  TF_ASSERT_OK(NodeDefBuilder("quantized_mat_mul_op", "QuantizedMatMul")
                   .Input(FakeInput(DT_QUINT8))
                   .Input(FakeInput(DT_QUINT8))
                   .Input(FakeInput(DT_FLOAT))
                   .Input(FakeInput(DT_FLOAT))
                   .Input(FakeInput(DT_FLOAT))
                   .Input(FakeInput(DT_FLOAT))
                   .Attr("Toutput", DataTypeToEnum<qint32>::v())
                   .Attr("transpose_a", transpose_a)
                   .Attr("transpose_b", transpose_b)
                   .Finalize(node_def()));
  TF_ASSERT_OK(InitOp());
  AddInputFromArray<quint8>(TensorShape({a_rows, a_cols}), {11});
  AddInputFromArray<quint8>(TensorShape({b_rows, b_cols}), {0});
  AddInputFromArray<float>(TensorShape({1}), {-12.0f});
  AddInputFromArray<float>(TensorShape({1}), {243.0f});
  AddInputFromArray<float>(TensorShape({1}), {1.0f});
  AddInputFromArray<float>(TensorShape({1}), {256.0f});
  TF_ASSERT_OK(RunOpKernel());
  Tensor expected(allocator(), DT_QINT32, TensorShape({a_cols, b_cols}));
  test::FillValues<qint32>(&expected, {-1});
  test::ExpectTensorEqual<qint32>(expected, *GetOutput(0));
}
TEST_F ( QuantizedMatMulTest , VerySmall_WithParams ) { const bool transpose_a = true ; const int a_rows = 1 ; const int a_cols = 1 ; const int b_rows = 1 ; const int b_cols = 1 ; const bool transpose_b = false ; TF_ASSERT_OK ( NodeDefBuilder ( " " , " " ) . Input ( FakeInput ( DT_QUINT8 ) ) . Input ( FakeInput ( DT_QUINT8 ) ) . Input ( FakeInput ( DT_FLOAT ) ) . Input ( FakeInput ( DT_FLOAT ) ) . Input ( FakeInput ( DT_FLOAT ) ) . Input ( FakeInput ( DT_FLOAT ) ) . Attr ( " " , DataTypeToEnum < qint32 > :: v ( ) ) . Attr ( " " , transpose_a ) . Attr ( " " , transpose_b ) . Finalize ( node_def ( ) ) ) ; TF_ASSERT_OK ( InitOp ( ) ) ; AddInputFromArray < quint8 > ( TensorShape ( { a_rows , a_cols } ) , { 11 } ) ; AddInputFromArray < quint8 > ( TensorShape ( { b_rows , b_cols } ) , { 0 } ) ; AddInputFromArray < float > ( TensorShape ( { 1 } ) , { -12.0f } ) ; AddInputFromArray < float > ( TensorShape ( { 1 } ) , { 243.0f } ) ; AddInputFromArray < float > ( TensorShape ( { 1 } ) , { 1.0f } ) ; AddInputFromArray < float > ( TensorShape ( { 1 } ) , { 256.0f } ) ; TF_ASSERT_OK ( RunOpKernel ( ) ) ; Tensor expected ( allocator ( ) , DT_QINT32 , TensorShape ( { a_cols , b_cols } ) ) ; test :: FillValues < qint32 > ( & expected , { -1 } ) ; test :: ExpectTensorEqual < qint32 > ( expected , * GetOutput ( 0 ) ) ; }
This test multiplies two 1x1 8bit matrices, and compares the
results with hand-calculated expectations.
This test multiplies two 1x1 8bit matrices and compares the results with hand - calculated expectations .
// These parameters reflect a typical production usage of eight-bit matmuls // in an Inception-style network. // The A matrix is: // |  -1 | // The input array only contains unsigned bytes, so we specify the actual // values as n+a_offset, where a_offset is 12 above. For example that means -1 // is represented as -1 + 12, or 11. // We have set the transpose_a flag to true, so the matrix is transposed, and // for filling the values the in-memory storage order is effectively // column major, rather than the default row-major. // The B matrix is: // |   1 | // We're requesting C = A.transposed() * B, // so we expect to get these results: // 1*-1 = -1 // | -1 |