1 #include <pybind11/pybind11.h> 2 #include "activation_distribution_observer.h" 3 #include "caffe2_dnnlowp_utils.h" 5 PYBIND11_MODULE(dnnlowp_pybind11, m) {
9 m.def(
"ClearNetObservers", []() { ClearGlobalNetObservers(); });
12 "ObserveMinMaxOfOutput",
13 [](
const string& min_max_file_name,
int dump_freq) {
14 AddGlobalNetObserverCreator(
15 [dump_freq, min_max_file_name](
NetBase* net) {
16 return make_unique<OutputMinMaxNetObserver>(
17 net, min_max_file_name, dump_freq);
20 pybind11::arg(
"min_max_file_name"),
21 pybind11::arg(
"dump_freq") = -1);
24 "ObserveHistogramOfOutput",
25 [](
const string& out_file_name,
int dump_freq,
bool mul_nets) {
26 AddGlobalNetObserverCreator(
27 [out_file_name, dump_freq, mul_nets](
NetBase* net) {
28 return make_unique<HistogramNetObserver>(
29 net, out_file_name, 2048, dump_freq, mul_nets);
32 pybind11::arg(
"out_file_name"),
33 pybind11::arg(
"dump_freq") = -1,
34 pybind11::arg(
"mul_nets") =
false);
37 "RegisterQuantizationParams",
38 [](
const string& min_max_file_name,
40 const string& qparams_output_file_name) {
41 AddGlobalNetObserverCreator([min_max_file_name,
43 qparams_output_file_name](
NetBase* net) {
44 return make_unique<RegisterQuantizationParamsNetObserver>(
45 net, min_max_file_name, is_weight, qparams_output_file_name);
48 pybind11::arg(
"min_max_file_name"),
49 pybind11::arg(
"is_weight") =
false,
50 pybind11::arg(
"qparams_output_file_name") =
"");
53 "RegisterQuantizationParamsWithHistogram",
54 [](
const string& histogram_file_name,
56 const string& qparams_output_file_name) {
57 AddGlobalNetObserverCreator([histogram_file_name,
59 qparams_output_file_name](
NetBase* net) {
62 net, histogram_file_name, is_weight, qparams_output_file_name);
65 pybind11::arg(
"histogram_file_name"),
66 pybind11::arg(
"is_weight") =
false,
67 pybind11::arg(
"qparams_output_file_name") =
"");
70 "AddScaleZeroOffsetArgumentsWithHistogram",
71 [](
const pybind11::bytes& net_def_bytes,
72 const string& histogram_file_name) {
75 ParseProtoFromLargeString(net_def_bytes.cast<
string>(), &def));
76 pybind11::gil_scoped_release g;
79 auto transformed_net =
80 dnnlowp::AddScaleZeroOffsetArgumentsWithHistogram(
81 def, histogram_file_name);
83 CAFFE_ENFORCE(transformed_net.SerializeToString(&protob));
84 return pybind11::bytes(protob);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Set quantization parameters of operators based on min/max collected from OutputMinMaxObserver.