1 #include "caffe2/operators/lengths_reducer_rowwise_8bit_ops.h" 2 #include "caffe2/core/registry.h" 7 Rowwise8BitQuantizedToFloat,
8 Rowwise8BitQuantizedToFloatOp<CPUContext>);
10 FloatToRowwiseQuantized8Bits,
11 FloatToRowwiseQuantized8BitsOp<CPUContext>);
13 REGISTER_CPU_OPERATOR(
14 SparseLengthsSum8BitsRowwise,
15 SparseLengths8BitsRowwiseOp<CPUContext>);
17 REGISTER_CPU_OPERATOR(
18 SparseLengthsWeightedSum8BitsRowwise,
19 SparseLengths8BitsRowwiseOp<CPUContext, 1>);
21 REGISTER_CPU_OPERATOR(
22 SparseLengthsMean8BitsRowwise,
23 SparseLengths8BitsRowwiseOp<CPUContext, 0, 1>);
25 REGISTER_CPU_OPERATOR(
26 SparseLengthsWeightedMean8BitsRowwise,
27 SparseLengths8BitsRowwiseOp<CPUContext, 1, 1>);
29 OPERATOR_SCHEMA(SparseLengthsSum8BitsRowwise)
33 Variation of SparseLengthsSum operator, where DATA is 34 stored using 8bits. DATA was quantized with 8Bit row-wise 35 quantization (see doc to FloatToRowwiseQuantized8Bits operator). To 36 restore DATA from 8Bit, we use additional input that stores scales 42 "uint8 tensor obtained with " 43 "operator FloatToRowwiseQuantized8Bits")
47 "Integer vector containing indices of the first " 48 "dimension of DATA for the slices that are being aggregated")
52 "Vector with the same sum of elements as the first dimension of DATA")
56 "Matrix of floats, each row r_i of which stores a pair " 57 "s_i, b_i -- scale and bias for i-th row")
59 .Output(0,
"output",
"output");
61 OPERATOR_SCHEMA(SparseLengthsWeightedSum8BitsRowwise)
65 Variation of SparseLengthsWeightedSum operator, where 66 DATA is stored using 8bits. DATA was quantized with 8Bit row-wise 67 quantization (see doc to FloatToRowwiseQuantized8Bits operator). To 68 restore DATA from 8Bit, we use additional input that stores scales 74 "uint8 tensor obtained with " 75 "operator FloatToRowwiseQuantized8Bits")
79 "Scalar multipliers for the input slices. Must " 80 "be a vector with the length matching the length of INDICES")
84 "Integer vector containing indices of the first " 85 "dimension of DATA for the slices that are being aggregated")
89 "Vector with the same sum of elements as the first dimension of DATA")
93 "Matrix of floats, each row r_i of which stores a pair " 94 "s_i, b_i -- scale and bias for i-th row")
95 .Output(0,
"output",
"output");
97 OPERATOR_SCHEMA(SparseLengthsMean8BitsRowwise)
101 Variation of SparseLengthsMean operator, where DATA is 102 stored using 8bits. DATA was quantized with 8Bit row-wise 103 quantization (see doc to FloatToRowwiseQuantized8Bits operator). To 104 restore DATA from 8Bit, we use additional input that stores scales 110 "uint8 tensor obtained with " 111 "operator FloatToRowwiseQuantized8Bits")
115 "Integer vector containing indices of the first " 116 "dimension of DATA for the slices that are being aggregated")
120 "Vector with the same sum of elements as the first dimension of DATA")
124 "Matrix of floats, each row r_i of which stores a pair " 125 "s_i, b_i -- scale and bias for i-th row")
127 .Output(0,
"output",
"output");
129 OPERATOR_SCHEMA(SparseLengthsWeightedMean8BitsRowwise)
133 Variation of SparseLengthsWeightedMean operator, where 134 DATA is stored using 8bits. DATA was quantized with 8Bit row-wise 135 quantization (see doc to FloatToRowwiseQuantized8Bits operator). To 136 restore DATA from 8Bit, we use additional input that stores scales 142 "uint8 tensor obtained with " 143 "operator FloatToRowwiseQuantized8Bits")
147 "Scalar multipliers for the input slices. Must " 148 "be a vector with the length matching the length of INDICES")
152 "Integer vector containing indices of the first " 153 "dimension of DATA for the slices that are being aggregated")
157 "Vector with the same sum of elements as the first dimension of DATA")
161 "Matrix of floats, each row r_i of which stores a pair " 162 "s_i, b_i -- scale and bias for i-th row")
163 .Output(0,
"output",
"output");
165 OPERATOR_SCHEMA(FloatToRowwiseQuantized8Bits)
169 This operator applies 8Bit row-wise quantization to 170 input tensor and returns quantized tensor. Row wise quantization of 171 input tensor is the following process. We take tensor of size 172 (m_1, m_2,...,m_n), n >= 2, reshape it into matrix of size 173 (m_1, m_2 x... x m_n) and apply row-wise quantization. After this, 174 we compute scale_i= (min_i - max_i) / 255 and bias_i = min_i for 175 i-th row r_i of reshaped matrix, where min_i and max_i -- minimum 176 and maximum elements of i-th row, and quantize each element r_{ij} as 177 0 <= round(r_ij - bias_i) / scale_i) < 256. Instead of input tensor 178 we obtain uint8 tensor and auxiliary information as scale and bias to 179 restore input tensor (with losses). 181 .Input(0, "input",
"input")
182 .Output(0,
"quantized_input",
"quantized_input")
186 "Matrix of floats, each row r_i of which stores a pair " 189 OPERATOR_SCHEMA(Rowwise8BitQuantizedToFloat)
193 Given uint8 tensor, quantized using 8bit row-wise 194 quantization, and auxiliary scales and biases, this operator 195 restores float tensor in the following way. We take input 8bits tensor 196 of size (m_1, m_2, ..., m_n), n >= 2, reshape it into matrix of size 197 (m_1, m_2 x... x m_n). We compute element r_{ij} of output matrix as 198 r_{ij} * s_i + b_i and after this we reshape this output matrix into 199 output tensor of size (m_1, m_2, ..., m_n). 201 .Input(0, "quantized_input",
"quantized_input")
205 "Matrix of floats, each row r_i of which stores a pair " 206 "s_i, b_i -- scale and bias for i-th row")
207 .Output(1,
"output",
"output");
209 NO_GRADIENT(Rowwise8BitQuantizedToFloat);
210 NO_GRADIENT(FloatToRowwiseQuantized8Bits);
211 NO_GRADIENT(SparseLengthsSum8BitsRowwise);
212 NO_GRADIENT(SparseLengthsWeightedSum8BitsRowwise);
213 NO_GRADIENT(SparseLengthsMean8BitsRowwise);
214 NO_GRADIENT(SparseLengthsWeightedMean8BitsRowwise);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...