!26564 [MS][LITE][develop] fix deconv unstable accuracy

Merge pull request !26564 from sunsuodong/fix_deconv_winograd_fp16_bug
This commit is contained in:
i-robot 2021-11-22 07:17:33 +00:00 committed by Gitee
commit 9d023b6445
3 changed files with 11 additions and 4 deletions

View File

@ -192,6 +192,7 @@ int DeConvWinogradFp16CPUKernel::InitParameter() {
}
int DeConvWinogradFp16CPUKernel::DoDeconv(int task_id) {
// It is better than continuous cutting because it uses locks to merge after fully paralleling.
for (int tile_index = task_id; tile_index < deconv_param_->in_tile_count_; tile_index += deconv_param_->thread_num_) {
float16_t *tile_in = tile_input_ + task_id * DECONV_WINOGRAD_DEFAULT_UNIT * DECONV_WINOGRAD_DEFAULT_UNIT *
DECONV_WINOGRAD_DEFAULT_TILE * deconv_param_->ic_up_;
@ -206,8 +207,12 @@ int DeConvWinogradFp16CPUKernel::DoDeconv(int task_id) {
DeconvWgFp16(nhwc_input_, tile_in, tile_out, start_index, calculate_count, conv_param_, deconv_param_, task_id);
std::unique_lock<std::mutex> merge_lock(lock_);
std::unique_lock<std::mutex> merge_lock(nc4hw4_mutex_);
nc4hw4_cond_var_.wait(merge_lock, [&] { return tile_index == completed_index_ + 1; });
DeconvWgPostFp16(tile_out, nc4hw4_output_, conv_param_, deconv_param_, calculate_count, tile_index);
completed_index_++;
nc4hw4_cond_var_.notify_all();
}
return RET_OK;
}
@ -461,6 +466,7 @@ int DeConvWinogradFp16CPUKernel::Run() {
nhwc_output_ = output_ptr + batch_index * deconv_param_->output_plane_ * conv_param_->output_channel_;
::memset(nc4hw4_output_, 0, deconv_param_->output_plane_ * deconv_param_->oc_div_ * C4NUM * sizeof(float16_t));
completed_index_ = -1;
auto ret = ParallelLaunch(this->ms_context_, DeConvWgFp16Run, this, deconv_param_->thread_num_);
if (ret != RET_OK) {
MS_LOG(ERROR) << "DeConvWgFp16Run failed!";

View File

@ -49,7 +49,9 @@ class DeConvWinogradFp16CPUKernel : public ConvolutionBaseCPUKernel {
private:
DeConvParam *deconv_param_ = nullptr;
std::mutex lock_;
std::mutex nc4hw4_mutex_;
std::condition_variable nc4hw4_cond_var_;
int completed_index_ = -1;
float16_t *nhwc_input_ = nullptr;
float16_t *nhwc_output_ = nullptr;
float16_t *nc4hw4_output_ = nullptr;

View File

@ -61,8 +61,7 @@ ml_facedetector.onnx 6
ml_ei_facedetection.onnx 2
#ml_video_edit_art_generate.onnx #mul operator overflows, not suitable for fp16
#ml_voice_detect.onnx #conv operator overflows, not suitable for fp16
#ml_location_lane_counter.onnx has very small values during op computation (<1e-6), which causes the precision variation
ml_location_lane_counter.onnx 10
ml_location_lane_counter.onnx 6.8
ml_location_lane_counter0.onnx 1.0
#The encoder an decoder model are used in ml_asr scene, both have value overflow. Not suitable for fp16.
#But added for guarding process.