MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / quantize_kernel

Function quantize_kernel

csrc/quantization/pt_binding.cpp:12–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "quantization.h"
11
12std::vector<at::Tensor> quantize_kernel(at::Tensor& input_vals,
13 int groups,
14 int numBits,
15 quantize::Type quantType)
16{
17 auto dtype = at::kFloat;
18 auto params_options = at::TensorOptions()
19 .dtype(dtype)
20 .layout(at::kStrided)
21 .device(at::kCUDA)
22 .requires_grad(false);
23 const int param_elems = (quantize::requires_offset(quantType)) ? 2 : 1;
24 auto params = torch::empty({groups, param_elems}, params_options);
25
26 auto output_options = at::TensorOptions()
27 .dtype(at::kChar)
28 .layout(at::kStrided)
29 .device(at::kCUDA)
30 .requires_grad(false);
31
32 auto output_sizes = input_vals.sizes().vec();
33 output_sizes[output_sizes.size() - 1] /= numBits == 8 ? 1 : 2;
34 auto output = torch::empty(output_sizes, output_options);
35
36 const int elems_per_group = at::numel(input_vals) / groups;
37
38 launch_quant((int8_t*)output.data_ptr(),
39 (float*)params.data_ptr(),
40 (__half*)input_vals.data_ptr(),
41 groups,
42 elems_per_group,
43 numBits,
44 quantType,
45 at::cuda::getCurrentCUDAStream());
46
47 return {output, params};
48}
49
50template <typename T>
51at::Tensor dequantize(at::Tensor& quantized_data,

Callers

nothing calls this directly

Calls 7

requires_offsetFunction · 0.85
getCurrentCUDAStreamFunction · 0.85
deviceMethod · 0.45
dtypeMethod · 0.45
sizesMethod · 0.45
sizeMethod · 0.45
data_ptrMethod · 0.45

Tested by

no test coverage detected