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

Function dequantize

csrc/quantization/pt_binding.cpp:51–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50template <typename T>
51at::Tensor dequantize(at::Tensor& quantized_data,
52 at::Tensor& params,
53 int groups,
54 int num_bits,
55 quantize::Type quant_type)
56{
57 auto dtype = (std::is_same<T, float>::value) ? torch::kFloat32 : torch::kFloat16;
58 auto output_options = at::TensorOptions()
59 .dtype(dtype)
60 .layout(at::kStrided)
61 .device(at::kCUDA)
62 .requires_grad(false);
63
64 auto output_sizes = quantized_data.sizes().vec();
65 output_sizes[output_sizes.size() - 1] *= num_bits == 8 ? 1 : 2;
66 auto output = torch::empty(output_sizes, output_options);
67
68 const int total_elems = at::numel(output);
69 const int elems_per_group = total_elems / groups;
70
71 launch_dequantize_kernel((T*)output.data_ptr(),
72 (const int8_t*)quantized_data.data_ptr(),
73 (const float*)params.data_ptr(),
74 quant_type,
75 num_bits,
76 elems_per_group,
77 total_elems,
78 at::cuda::getCurrentCUDAStream());
79
80 return output;
81}
82
83at::Tensor dequantize_int4_to_half_experimental(at::Tensor& data_in,
84 at::Tensor& scale_buffer,

Callers

nothing calls this directly

Calls 6

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