diff --git a/tools/remove_grad_op_and_kernel.py b/tools/remove_grad_op_and_kernel.py index 80314f2c3c583a2be75d25111f3101e3ceda5dd6..e8ab321e96105714eedcb9ea3753e81ee9966d08 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,