Commit 32c48cfe authored by Shucai Xiao's avatar Shucai Xiao
Browse files

change the int8 quantization parameter

parent 0bd9c447
...@@ -126,7 +126,7 @@ struct program ...@@ -126,7 +126,7 @@ struct program
friend bool operator==(const program& x, const program& y); friend bool operator==(const program& x, const program& y);
friend bool operator!=(const program& x, const program& y) { return !(x == y); } friend bool operator!=(const program& x, const program& y) { return !(x == y); }
std::vector<std::pair<float, float>> int8_quant_params; std::shared_ptr<std::vector<std::pair<float, float>>> int8_quant_params = std::make_shared<std::vector<std::pair<float, float>>>();
private: private:
void assign(const program& p); void assign(const program& p);
......
...@@ -113,6 +113,7 @@ void program::assign(const program& p) ...@@ -113,6 +113,7 @@ void program::assign(const program& p)
impl->instructions.clear(); impl->instructions.clear();
} }
impl->ctx = p.impl->ctx; impl->ctx = p.impl->ctx;
int8_quant_params = p.int8_quant_params;
std::unordered_map<instruction_ref, instruction_ref> ins_map; std::unordered_map<instruction_ref, instruction_ref> ins_map;
for(auto ins : iterator_for(p)) for(auto ins : iterator_for(p))
......
...@@ -324,13 +324,13 @@ void quantize_int8(program& prog, ...@@ -324,13 +324,13 @@ void quantize_int8(program& prog,
void quantize_int8(program& prog, const std::vector<std::string>& ins_names) void quantize_int8(program& prog, const std::vector<std::string>& ins_names)
{ {
quantize_int8(prog, ins_names, prog.int8_quant_params); quantize_int8(prog, ins_names, *prog.int8_quant_params);
} }
void quantize_int8(program& prog) void quantize_int8(program& prog)
{ {
std::vector<std::string> ins_names = {"dot", "convolution"}; std::vector<std::string> ins_names = {"dot", "convolution"};
quantize_int8(prog, ins_names, prog.int8_quant_params); quantize_int8(prog, ins_names);
} }
// For the input of each input argument, we need to insert a // For the input of each input argument, we need to insert a
...@@ -379,7 +379,7 @@ void capture_arguments(program& prog, ...@@ -379,7 +379,7 @@ void capture_arguments(program& prog,
} }
// set one pair of parameter for each argument // set one pair of parameter for each argument
prog.int8_quant_params.resize(num_quant_params, std::make_pair(-1.0f, -1.0f)); prog.int8_quant_params->resize(num_quant_params, std::make_pair(-1.0f, -1.0f));
} }
void capture_arguments(program& prog, const std::vector<std::string>& ins_names) void capture_arguments(program& prog, const std::vector<std::string>& ins_names)
...@@ -394,9 +394,9 @@ void capture_arguments(program& prog, const std::vector<std::string>& ins_names) ...@@ -394,9 +394,9 @@ void capture_arguments(program& prog, const std::vector<std::string>& ins_names)
auto max_val = *std::max_element(vec_val.begin(), vec_val.end()); auto max_val = *std::max_element(vec_val.begin(), vec_val.end());
auto min_val = *std::min_element(vec_val.begin(), vec_val.end()); auto min_val = *std::min_element(vec_val.begin(), vec_val.end());
auto max_abs = std::max(std::fabs(max_val), std::fabs(min_val)); auto max_abs = std::max(std::fabs(max_val), std::fabs(min_val));
param_pair.first = 127.0f / max_abs;
prog.int8_quant_params[ins_index] = param_pair; param_pair.first = 127.0f / max_abs;
(*prog.int8_quant_params)[ins_index] = param_pair;
}; };
capture_arguments(prog, ins_names, calc_quant_params); capture_arguments(prog, ins_names, calc_quant_params);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment