| 164 | } |
| 165 | |
| 166 | std::vector<at::Tensor> quantized_reduction(at::Tensor& input_vals, |
| 167 | at::Tensor& input_scales, |
| 168 | int in_groups, |
| 169 | int out_groups, |
| 170 | int num_bits, |
| 171 | quantize::Type quant_type, |
| 172 | int devices_per_node) |
| 173 | { |
| 174 | auto scales_options = at::TensorOptions() |
| 175 | .dtype(at::kFloat) |
| 176 | .layout(at::kStrided) |
| 177 | .device(at::kCUDA) |
| 178 | .requires_grad(false); |
| 179 | const int scales_elems = (quantize::requires_offset(quant_type)) ? 2 : 1; |
| 180 | auto scales = torch::empty({out_groups, scales_elems}, scales_options); |
| 181 | |
| 182 | auto output_options = at::TensorOptions() |
| 183 | .dtype(at::kChar) |
| 184 | .layout(at::kStrided) |
| 185 | .device(at::kCUDA) |
| 186 | .requires_grad(false); |
| 187 | |
| 188 | std::vector<int64_t> sz(input_vals.sizes().begin(), input_vals.sizes().end()); |
| 189 | sz[sz.size() - 1] = sz.back() / devices_per_node; // num of GPU per nodes |
| 190 | const int elems_per_in_tensor = at::numel(input_vals) / devices_per_node; |
| 191 | auto output = torch::empty(sz, output_options); |
| 192 | |
| 193 | const int elems_per_in_group = elems_per_in_tensor / (in_groups / devices_per_node); |
| 194 | const int elems_per_out_group = elems_per_in_tensor / out_groups; |
| 195 | |
| 196 | launch_dequant_reduce((int8_t*)output.data_ptr(), |
| 197 | (float*)scales.data_ptr(), |
| 198 | (const int8_t*)input_vals.data_ptr(), |
| 199 | (const float*)input_scales.data_ptr(), |
| 200 | devices_per_node, |
| 201 | num_bits, |
| 202 | quant_type, |
| 203 | out_groups, |
| 204 | elems_per_out_group, |
| 205 | elems_per_in_tensor, |
| 206 | in_groups / devices_per_node, |
| 207 | elems_per_in_group, |
| 208 | at::cuda::getCurrentCUDAStream()); |
| 209 | return {output, scales}; |
| 210 | } |
| 211 | |
| 212 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) |
| 213 | { |
nothing calls this directly
no test coverage detected