@@ -81,8 +81,8 @@ std::vector<Tensor> quantize_per_tensor_list_cpu(
8181 for (const auto i : c10::irange (tensors.size ())) {
8282 quantized_tensors.push_back (at::quantize_per_tensor (
8383 tensors[i],
84- scales[i ].item <double >(),
85- zero_points[i ].item <int64_t >(),
84+ scales[static_cast < int64_t >(i) ].item <double >(),
85+ zero_points[static_cast < int64_t >(i) ].item <int64_t >(),
8686 dtype));
8787 }
8888 return quantized_tensors;
@@ -293,18 +293,16 @@ std::tuple<double, int64_t> _choose_qparams_per_tensor(
293293
294294static float calculate_quant_loss (
295295 const float * input,
296- int numel,
296+ int64_t numel,
297297 float xmin,
298298 float xmax,
299299 float * q_input,
300- int bit_width) {
300+ int64_t bit_width) {
301301 xmin = static_cast <at::Half>(xmin);
302302 float data_range = xmax - xmin;
303- // NOLINTNEXTLINE(cppcoreguidelines-narrowing-conversions,bugprone-narrowing-conversions)
304- float qmax = (1 << bit_width) - 1 ;
303+ float qmax = static_cast <float >((1 << bit_width) - 1 );
305304 float scale = data_range == 0
306- ? 1.0
307- // NOLINTNEXTLINE(cppcoreguidelines-narrowing-conversions,bugprone-narrowing-conversions)
305+ ? 1 .0f
308306 : static_cast <float >(static_cast <at::Half>(data_range / qmax));
309307 float inverse_scale = scale == 0 ? 1 .0f : 1 .0f / scale;
310308
@@ -347,10 +345,10 @@ std::tuple<Tensor, Tensor> choose_qparams_optimized(
347345 const float * input_row = input_tensor.const_data_ptr <float >();
348346 float xmin = *std::min_element (input_row, input_row + numel);
349347 float xmax = *std::max_element (input_row, input_row + numel);
348+ float n_bins_float = static_cast <float >(n_bins);
350349
351- float stepsize = (xmax - xmin) / n_bins;
352- // NOLINTNEXTLINE(cppcoreguidelines-narrowing-conversions,bugprone-narrowing-conversions)
353- int min_bins = n_bins * (1.0 - (float ) ratio);
350+ float stepsize = (xmax - xmin) / n_bins_float;
351+ float min_bins = static_cast <float >(n_bins_float* (1.0 - ratio));
354352 Tensor input_tensor_contig = input_tensor.contiguous ();
355353 const float * input = input_tensor_contig.const_data_ptr <float >();
356354 std::vector<float > q_input (numel);
@@ -363,7 +361,6 @@ std::tuple<Tensor, Tensor> choose_qparams_optimized(
363361 float cur_max = xmax;
364362 float cur_loss = loss;
365363
366- // NOLINTNEXTLINE(cppcoreguidelines-narrowing-conversions,bugprone-narrowing-conversions)
367364 float thr = min_bins * stepsize;
368365 while (cur_min + thr < cur_max) {
369366 // move left
0 commit comments