42int entry(
const int argc,
char **argv)
51 "Embedding min/max values of activations to the circle model for post-training quantization");
56 arser.add_argument(
"--input_model").required(
true).help(
"Input model filepath");
58 arser.add_argument(
"--input_data")
59 .help(
"Input data filepath. If not given, record-minmax will run with randomly generated data. "
60 "Note that the random dataset does not represent inference workload, leading to poor "
63 arser.add_argument(
"--output_model").required(
true).help(
"Output model filepath");
65 arser.add_argument(
"--min_percentile")
66 .type(arser::DataType::FLOAT)
67 .help(
"Record n'th percentile of min");
69 arser.add_argument(
"--num_threads")
70 .type(arser::DataType::INT32)
71 .help(
"Number of threads (default: 1)");
73 arser.add_argument(
"--max_percentile")
74 .type(arser::DataType::FLOAT)
75 .help(
"Record n'th percentile of max");
77 arser.add_argument(
"--moving_avg_batch")
78 .type(arser::DataType::INT32)
79 .help(
"Batch size of moving average algorithm (default: 16)");
81 arser.add_argument(
"--moving_avg_const")
82 .type(arser::DataType::FLOAT)
83 .help(
"Hyperparameter (C) to compute moving average (default: 0.1). Update equation: avg <- "
84 "avg + C * (curr_batch_avg - avg)");
86 arser.add_argument(
"--mode").help(
"Record mode. percentile (default) or moving_average");
88 arser.add_argument(
"--input_data_format")
89 .help(
"Input data format. h5/hdf5 (default) or list/filelist");
91 arser.add_argument(
"--generate_profile_data")
94 .help(
"This will turn on profiling data generation.");
98 arser.parse(argc, argv);
100 catch (
const std::runtime_error &err)
102 std::cout << err.what() << std::endl;
107 if (
arser.get<
bool>(
"--verbose"))
111 setenv(
"LUCI_LOG",
"100", 0);
116 auto input_model_path =
arser.get<std::string>(
"--input_model");
117 auto output_model_path =
arser.get<std::string>(
"--output_model");
119 float min_percentile = ::get_values_from<float>(
arser,
"--min_percentile", 1.0);
120 uint32_t num_threads = ::get_values_from<int>(
arser,
"--num_threads", 1);
122 throw std::runtime_error(
"The number of threads must be greater than zero");
123 float max_percentile = ::get_values_from<float>(
arser,
"--max_percentile", 99.0);
124 std::string mode = ::get_values_from<std::string>(
arser,
"--mode",
"percentile");
125 uint32_t moving_avg_batch = ::get_values_from<int>(
arser,
"--moving_avg_batch", 16);
126 float moving_avg_const = ::get_values_from<float>(
arser,
"--moving_avg_const", 0.1);
127 if (mode !=
"percentile" && mode !=
"moving_average")
128 throw std::runtime_error(
"Unsupported mode");
129 std::string input_data_format =
130 ::get_values_from<std::string>(
arser,
"--input_data_format",
"h5");
131 if (
arser[
"--generate_profile_data"])
134 std::unique_ptr<MinMaxComputer> computer;
136 if (mode ==
"percentile")
138 computer = make_percentile_computer(min_percentile, max_percentile);
140 else if (mode ==
"moving_average")
142 computer = make_moving_avg_computer(moving_avg_batch, moving_avg_const);
153 if (num_threads > 1 and not
arser[
"--input_data"])
155 throw std::runtime_error(
"Input data must be given for parallel recording");
161 if (
arser[
"--input_data"])
163 auto input_data_path =
arser.get<std::string>(
"--input_data");
168 if (num_threads > 1 and not(input_data_format ==
"h5") and not(input_data_format ==
"hdf5"))
170 throw std::runtime_error(
"Parallel recording is used only for h5 now");
173 if (input_data_format ==
"h5" || input_data_format ==
"hdf5")
176 if (num_threads == 1)
182 INFO(l) <<
"Using parallel recording" << std::endl;
199 else if (input_data_format ==
"list" || input_data_format ==
"filelist")
204 else if (input_data_format ==
"directory" || input_data_format ==
"dir")
212 throw std::runtime_error(
213 "Unsupported input data format (supported formats: h5/hdf5 (default), list/filelist)");