| 1129 | } |
| 1130 | |
| 1131 | void dispatch_quantize_dequantize( |
| 1132 | const array& w, |
| 1133 | array& out, |
| 1134 | int bits, |
| 1135 | int group_size) { |
| 1136 | if (w.dtype() == float16) { |
| 1137 | fp_quantize_dequantize<float16_t>(w, out, bits, group_size, w.size()); |
| 1138 | } else if (w.dtype() == bfloat16) { |
| 1139 | fp_quantize_dequantize<bfloat16_t>(w, out, bits, group_size, w.size()); |
| 1140 | } else if (w.dtype() == float32) { |
| 1141 | fp_quantize_dequantize<float>(w, out, bits, group_size, w.size()); |
| 1142 | } else { |
| 1143 | throw std::runtime_error( |
| 1144 | "[quantize_dequantize] Only supports floating point inputs"); |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | template <typename T, typename U> |
| 1149 | void quantize( |