提交 5f3a2e84 编写于 作者: X xiaolil1

Revert "fix quantize bug and add debug log"

This reverts commit afe761d8.
上级 afe761d8
......@@ -350,29 +350,10 @@ std::cout<<"fuse_relu = "<<fuse_relu<<" fuse_residual_conn = "<<fuse_residual_c
std::vector<float> output_shift_scale;
float sum_scale = 1.0f;
for(int i=0; i<50; i++){
printf("%f ", (float)*(input_data+i));
}
printf("\n");fflush(stdout);
if(is_INT8){
std::cout<<"this is conv int8 op .............."<<std::endl;
//unsigned char* a = (unsigned char*)(input_data);
//for(int i=0; i<50; i++){
// printf("%d ", *(a+i));
//}
//printf("\n");
int count = is_multi_channel? (g>1? weights_tz[1]*weights_tz[0] : weights_tz[0]) : 1;
float scale_in_data = *(scale_in->data<float>());
for(int i=0; i<50; i++){
printf("%f ", *(input_data+i)/scale_in_data);
}
printf("\n");fflush(stdout);
std::vector<float> scale_weights_data(count);
for(int i=0; i<count; i++){
scale_weights_data[i] =*(scale_weights->data<float>() + i);
......@@ -498,6 +479,7 @@ std::cout<<key_conv_pd<<std::endl;
weights_memory_p = handler.AcquireWeightsMemoryFromPrimitive(
user_weights_memory_p, pipeline, is_test);
}
std::shared_ptr<mkldnn::memory> dst_memory_p;
if(is_INT8){
......@@ -528,7 +510,7 @@ std::cout<<key_conv_pd<<std::endl;
handler.AcquireDstMemoryFromPrimitive(to_void_cast<int8_t>(output_data));
}
}
std::cout<<"input fmt = "<<input->format()<<" input dt = "<<paddle::framework::ToMKLDNNDataType(input->type())<<" output fmt = "<<output->format()<<" output dt = "<<paddle::framework::ToMKLDNNDataType(output->type())<<" dst fmt = "<<dst_memory_p->get_primitive_desc().desc().data.format<<" dst dt = "<<dst_memory_p->get_primitive_desc().desc().data.data_type<<std::endl;
std::cout<<"input fmt = "<<input->format()<<" output fmt = "<<output->format()<<" dst fmt = "<<dst_memory_p->get_primitive_desc().desc().data.format<<std::endl;
} else{
T* output_data = nullptr;
if (fuse_residual_conn) {
......
......@@ -72,7 +72,7 @@ std::cout<<"this is dequant op ***********"<<std::endl;
auto dst_memory = mkldnn::memory(dst_pd, to_void_cast<float>(output_data));
auto reorder_pd = std::shared_ptr<reorder::primitive_desc>(
new reorder::primitive_desc(src_pd, dst_pd, attri));
new reorder::primitive_desc(dst_pd, src_pd, attri));
auto reorder_p= std::shared_ptr<reorder>(new reorder(*reorder_pd, *src_memory_p, dst_memory));
pipeline.push_back(*reorder_p);
......
......@@ -47,35 +47,9 @@ std::cout<<"this is quantize op!!!!!!!!!!!!!!"<<std::endl;
std::vector<int> dst_tz = paddle::framework::vectorize2int(output->dims());
const T* input_data = input->data<T>();
uint8_t* output_data = output->mutable_data<uint8_t>(ctx.GetPlace());
T* output_data = output->mutable_data<T>(ctx.GetPlace());
std::vector<T> scale_data = {*(scale->data<T>())};
FILE *fp = fopen("quant_input.txt","w");
printf("quantize check!!!!\n");
std::vector<int> tz = paddle::framework::vectorize2int(input->dims());
int count=1;
for(int i=0; i<tz.size(); i++){
count*=tz[i];
printf("%d ",tz[i]);
}
printf("\n");
int num=0;
for(int i=0; i<count; i++){
if(num==32){ fprintf(fp,"\n"); num=0;}
fprintf(fp,"%f ", *(input_data+i));
num ++;
}
fprintf(fp,"\n");
fclose(fp);
for(int i=0; i<scale_data.size(); i++){
printf("%f", scale_data[i]);
}
printf("\n");
for(int i=0; i<50; i++){
printf("%f ", (*(input_data+i))*scale_data[0]);
}
printf("\n");
fflush(stdout);
mkldnn::primitive_attr attri;
int mask = 0;
attri.set_output_scales(mask, scale_data);
......@@ -89,10 +63,10 @@ fflush(stdout);
auto dst_md = platform::MKLDNNMemDesc(
{dst_tz}, memory::data_type::u8, memory::format::nhwc);
auto dst_pd = mkldnn::memory::primitive_desc(dst_md, engine);
auto dst_memory = mkldnn::memory(dst_pd, to_void_cast<uint8_t>(output_data));
auto dst_memory = mkldnn::memory(dst_pd, to_void_cast<T>(output_data));
auto reorder_pd = std::shared_ptr<reorder::primitive_desc>(
new reorder::primitive_desc(src_pd, dst_pd, attri));
new reorder::primitive_desc(dst_pd, src_pd, attri));
auto reorder_p= std::shared_ptr<reorder>(new reorder(*reorder_pd, *src_memory_p, dst_memory));
pipeline.push_back(*reorder_p);
......
......@@ -212,18 +212,16 @@ class MKLDNNHandler {
std::shared_ptr<mkldnn::primitive> reorder_p;
if (mpd != user_mpd) {
target_memory_p = std::make_shared<mkldnn::memory>(mpd);
std::shared_ptr<mkldnn::reorder> reorder_p;// =
//std::make_shared<mkldnn::reorder>(*user_memory_p, *target_memory_p);
auto reorder_p =
std::make_shared<mkldnn::reorder>(*user_memory_p, *target_memory_p);
if(is_INT8){
mkldnn::primitive_attr attri;
attri.set_output_scales(mask, scale_data);
auto reorder_pd = std::shared_ptr<mkldnn::reorder::primitive_desc>(
new mkldnn::reorder::primitive_desc(user_mpd, mpd, attri));
reorder_p =
new mkldnn::reorder::primitive_desc(mpd, user_mpd, attri));
auto reorder_p =
std::shared_ptr<mkldnn::reorder>(new mkldnn::reorder(*reorder_pd, *user_memory_p, *target_memory_p));
} else{
reorder_p = std::make_shared<mkldnn::reorder>(*user_memory_p, *target_memory_p);
}
dev_ctx_.SetBlob(key_reorder_p, reorder_p);
pipeline.push_back(*reorder_p);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册