| 707 | }; |
| 708 | |
| 709 | struct verify : command<verify> |
| 710 | { |
| 711 | compiler c; |
| 712 | std::optional<double> rms_tol; |
| 713 | std::optional<double> atol; |
| 714 | std::optional<double> rtol; |
| 715 | bool per_instruction = false; |
| 716 | bool reduce = false; |
| 717 | bool bisect = false; |
| 718 | verify_options vo; |
| 719 | void parse(argument_parser& ap) |
| 720 | { |
| 721 | c.parse(ap); |
| 722 | ap(rms_tol, {"--rms-tol"}, ap.help("Tolerance for the RMS error")); |
| 723 | ap(atol, {"--atol"}, ap.help("Tolerance for the elementwise absolute difference")); |
| 724 | ap(rtol, {"--rtol"}, ap.help("Tolerance for the elementwise relative difference")); |
| 725 | ap(per_instruction, |
| 726 | {"-i", "--per-instruction"}, |
| 727 | ap.help("Verify each instruction"), |
| 728 | ap.set_value(true)); |
| 729 | ap(reduce, {"-r", "--reduce"}, ap.help("Reduce program and verify"), ap.set_value(true)); |
| 730 | ap(bisect, {"-b", "--bisect"}, ap.help("Bisect program and verify"), ap.set_value(true)); |
| 731 | ap(vo.ref_use_double, |
| 732 | {"--ref-use-double"}, |
| 733 | ap.help( |
| 734 | "Convert floating point values to double on ref. Also removes Q/DQ pairs on ref."), |
| 735 | ap.set_value(true)); |
| 736 | ap(vo.compiled_model, {"--compiled-model", "-c"}, ap.help("Compiled model to use")); |
| 737 | } |
| 738 | |
| 739 | void run() |
| 740 | { |
| 741 | auto p = c.l.load(); |
| 742 | c.l.save(p); |
| 743 | std::cout << p << std::endl; |
| 744 | |
| 745 | auto t = c.ct.get_target(); |
| 746 | auto m = |
| 747 | c.parameters.generate(p, t, true, c.l.batch, loader::parse_param_dims(c.l.param_dims)); |
| 748 | |
| 749 | if(c.to_fp16) |
| 750 | { |
| 751 | vo.quantize = precision::fp16; |
| 752 | } |
| 753 | if(c.to_bf16) |
| 754 | { |
| 755 | vo.quantize = precision::bf16; |
| 756 | } |
| 757 | if(c.to_int8) |
| 758 | { |
| 759 | vo.quantize = precision::int8; |
| 760 | } |
| 761 | |
| 762 | auto tols = get_tolerances(p, vo, rms_tol, atol, rtol); |
| 763 | std::cout << "rms_tol: " << tols.rms_tol << std::endl; |
| 764 | std::cout << "atol: " << tols.atol << std::endl; |
| 765 | std::cout << "rtol: " << tols.rtol << std::endl; |
| 766 | |