1 #include "caffe2/operators/lengths_reducer_rowwise_8bit_ops.h" 2 #include "c10/util/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)
32 .ValueLengthInputFillers(
33 SparseLengths8BitsRowwiseOp<CPUContext>::DATA,
34 SparseLengths8BitsRowwiseOp<CPUContext>::LENGTHS)
36 Variation of SparseLengthsSum operator, where DATA is 37 stored using 8bits. DATA was quantized with 8Bit row-wise 38 quantization (see doc to FloatToRowwiseQuantized8Bits operator). To 39 restore DATA from 8Bit, we use additional input that stores scales 45 "uint8 tensor obtained with " 46 "operator FloatToRowwiseQuantized8Bits")
50 "Integer vector containing indices of the first " 51 "dimension of DATA for the slices that are being aggregated")
55 "Vector with the same sum of elements as the first dimension of DATA")
59 "Matrix of floats, each row r_i of which stores a pair " 60 "s_i, b_i -- scale and bias for i-th row")
62 .Output(0,
"output",
"output");
64 OPERATOR_SCHEMA(SparseLengthsWeightedSum8BitsRowwise)
67 .ValueLengthInputFillers(
68 SparseLengths8BitsRowwiseOp<CPUContext, 1>::DATA,
69 SparseLengths8BitsRowwiseOp<CPUContext, 1>::LENGTHS)
71 Variation of SparseLengthsWeightedSum operator, where 72 DATA is stored using 8bits. DATA was quantized with 8Bit row-wise 73 quantization (see doc to FloatToRowwiseQuantized8Bits operator). To 74 restore DATA from 8Bit, we use additional input that stores scales 80 "uint8 tensor obtained with " 81 "operator FloatToRowwiseQuantized8Bits")
85 "Scalar multipliers for the input slices. Must " 86 "be a vector with the length matching the length of INDICES")
90 "Integer vector containing indices of the first " 91 "dimension of DATA for the slices that are being aggregated")
95 "Vector with the same sum of elements as the first dimension of DATA")
99 "Matrix of floats, each row r_i of which stores a pair " 100 "s_i, b_i -- scale and bias for i-th row")
101 .Output(0,
"output",
"output");
103 OPERATOR_SCHEMA(SparseLengthsMean8BitsRowwise)
106 .ValueLengthInputFillers(
107 SparseLengths8BitsRowwiseOp<CPUContext, 0, 1>::DATA,
108 SparseLengths8BitsRowwiseOp<CPUContext, 0, 1>::LENGTHS)
110 Variation of SparseLengthsMean operator, where DATA is 111 stored using 8bits. DATA was quantized with 8Bit row-wise 112 quantization (see doc to FloatToRowwiseQuantized8Bits operator). To 113 restore DATA from 8Bit, we use additional input that stores scales 119 "uint8 tensor obtained with " 120 "operator FloatToRowwiseQuantized8Bits")
124 "Integer vector containing indices of the first " 125 "dimension of DATA for the slices that are being aggregated")
129 "Vector with the same sum of elements as the first dimension of DATA")
133 "Matrix of floats, each row r_i of which stores a pair " 134 "s_i, b_i -- scale and bias for i-th row")
136 .Output(0,
"output",
"output");
138 OPERATOR_SCHEMA(SparseLengthsWeightedMean8BitsRowwise)
141 .ValueLengthInputFillers(
142 SparseLengths8BitsRowwiseOp<CPUContext, 1, 1>::DATA,
143 SparseLengths8BitsRowwiseOp<CPUContext, 1, 1>::LENGTHS)
145 Variation of SparseLengthsWeightedMean operator, where 146 DATA is stored using 8bits. DATA was quantized with 8Bit row-wise 147 quantization (see doc to FloatToRowwiseQuantized8Bits operator). To 148 restore DATA from 8Bit, we use additional input that stores scales 154 "uint8 tensor obtained with " 155 "operator FloatToRowwiseQuantized8Bits")
159 "Scalar multipliers for the input slices. Must " 160 "be a vector with the length matching the length of INDICES")
164 "Integer vector containing indices of the first " 165 "dimension of DATA for the slices that are being aggregated")
169 "Vector with the same sum of elements as the first dimension of DATA")
173 "Matrix of floats, each row r_i of which stores a pair " 174 "s_i, b_i -- scale and bias for i-th row")
175 .Output(0,
"output",
"output");
177 OPERATOR_SCHEMA(FloatToRowwiseQuantized8Bits)
180 .ValueLengthInputFillers(
181 SparseLengths8BitsRowwiseOp<CPUContext>::DATA,
182 SparseLengths8BitsRowwiseOp<CPUContext>::LENGTHS)
184 This operator applies 8Bit row-wise quantization to 185 input tensor and returns quantized tensor. Row wise quantization of 186 input tensor is the following process. We take tensor of size 187 (m_1, m_2,...,m_n), n >= 2, reshape it into matrix of size 188 (m_1, m_2 x... x m_n) and apply row-wise quantization. After this, 189 we compute scale_i= (min_i - max_i) / 255 and bias_i = min_i for 190 i-th row r_i of reshaped matrix, where min_i and max_i -- minimum 191 and maximum elements of i-th row, and quantize each element r_{ij} as 192 0 <= round(r_ij - bias_i) / scale_i) < 256. Instead of input tensor 193 we obtain uint8 tensor and auxiliary information as scale and bias to 194 restore input tensor (with losses). 196 .Input(0, "input",
"input")
197 .Output(0,
"quantized_input",
"quantized_input")
201 "Matrix of floats, each row r_i of which stores a pair " 204 OPERATOR_SCHEMA(Rowwise8BitQuantizedToFloat)
207 .ValueLengthInputFillers(
208 SparseLengths8BitsRowwiseOp<CPUContext>::DATA,
209 SparseLengths8BitsRowwiseOp<CPUContext>::LENGTHS)
211 Given uint8 tensor, quantized using 8bit row-wise 212 quantization, and auxiliary scales and biases, this operator 213 restores float tensor in the following way. We take input 8bits tensor 214 of size (m_1, m_2, ..., m_n), n >= 2, reshape it into matrix of size 215 (m_1, m_2 x... x m_n). We compute element r_{ij} of output matrix as 216 r_{ij} * s_i + b_i and after this we reshape this output matrix into 217 output tensor of size (m_1, m_2, ..., m_n). 219 .Input(0, "quantized_input",
"quantized_input")
223 "Matrix of floats, each row r_i of which stores a pair " 224 "s_i, b_i -- scale and bias for i-th row")
225 .Output(1,
"output",
"output");
227 NO_GRADIENT(Rowwise8BitQuantizedToFloat);
228 NO_GRADIENT(FloatToRowwiseQuantized8Bits);
229 NO_GRADIENT(SparseLengthsSum8BitsRowwise);
230 NO_GRADIENT(SparseLengthsWeightedSum8BitsRowwise);
231 NO_GRADIENT(SparseLengthsMean8BitsRowwise);
232 NO_GRADIENT(SparseLengthsWeightedMean8BitsRowwise);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...