This function is to convert any instructions specified in the input from double or float to float16 by inserting a convert operator. For the conversion, there could be cases of overflowing or underflowing, but it is uncommon. Run optimize_module() before converting to fp16 to const eval and fold in FP32 to avoid loss of precision.
| 66 | // is uncommon. Run optimize_module() before converting to fp16 to const eval and fold in FP32 to |
| 67 | // avoid loss of precision. |
| 68 | void quantize_fp16(program& prog, const std::vector<std::string>& ins_names) |
| 69 | { |
| 70 | run_passes(prog, |
| 71 | {normalize_ops{}, |
| 72 | optimize_module{{"quantizelinear", "dequantizelinear"}}, |
| 73 | truncate_float_pass{ins_names, shape::half_type}, |
| 74 | optimize_module{{"quantizelinear", "dequantizelinear"}}}, |
| 75 | quant_tracer()); |
| 76 | } |
| 77 | |
| 78 | void quantize_bf16(program& prog, const std::vector<std::string>& ins_names) |
| 79 | { |