From c6617839dd36d3dc5a1c39c05e207f10054df458 Mon Sep 17 00:00:00 2001 From: Wilber Date: Mon, 5 Jul 2021 11:23:45 +0800 Subject: [PATCH] fix decoding error when clip grad op and python==2 (#33937) --- tools/remove_grad_op_and_kernel.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/remove_grad_op_and_kernel.py b/tools/remove_grad_op_and_kernel.py index 80314f2c3c5..e8ab321e961 100644 --- a/tools/remove_grad_op_and_kernel.py +++ b/tools/remove_grad_op_and_kernel.py @@ -20,6 +20,7 @@ import os import sys import re import glob +import io def find_type_files(cur_dir, file_type, file_list=[]): @@ -124,7 +125,7 @@ if __name__ == '__main__': custom_pattern2 = custom_pattern2[:-1] all_matches = [] - with open(op_file, 'r', encoding='utf-8') as f: + with io.open(op_file, 'r', encoding='utf-8') as f: content = ''.join(f.readlines()) op, op_count = remove_grad_op_and_kernel(content, op_pattern1, @@ -157,8 +158,8 @@ if __name__ == '__main__': for i in all_matches: content = content.replace(i, '') - with open(op_file, 'w') as f: - f.write(content) + with io.open(op_file, 'w', encoding='utf-8') as f: + f.write(u'{}'.format(content)) # 2. update operators/CMakeLists.txt cmake_file = os.path.join(tool_dir, -- GitLab