MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / dequantize

Function dequantize

deepspeed/ops/csrc/quantization/pt_binding.cpp:107–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105
106template <typename T>
107at::Tensor dequantize(at::Tensor& quantized_data,
108 at::Tensor& params,
109 int groups,
110 int num_bits,
111 quantize::Type quant_type)
112{
113 auto dtype = (std::is_same<T, float>::value) ? torch::kFloat32 : torch::kFloat16;
114 auto output_options = at::TensorOptions()
115 .dtype(dtype)
116 .layout(at::kStrided)
117 .device(at::kCUDA)
118 .requires_grad(false);
119
120 auto output_sizes = quantized_data.sizes().vec();
121 output_sizes[output_sizes.size() - 1] *= num_bits == 8 ? 1 : 2;
122 auto output = torch::empty(output_sizes, output_options);
123
124 const int total_elems = at::numel(output);
125 const int elems_per_group = total_elems / groups;
126
127 launch_dequantize_kernel((T*)output.data_ptr(),
128 (const int8_t*)quantized_data.data_ptr(),
129 (const float*)params.data_ptr(),
130 quant_type,
131 num_bits,
132 elems_per_group,
133 total_elems,
134 at::cuda::getCurrentCUDAStream());
135
136 return output;
137}
138
139PYBIND11_MODULE(TORCH_EXTENSION_NAME, m)
140{

Callers

nothing calls this directly

Calls 5

data_ptrMethod · 0.80
deviceMethod · 0.45
dtypeMethod · 0.45
sizesMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected