From 5f5f505a77386885f220039930384ac42ba51ed8 Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:15:29 +0800 Subject: [PATCH 01/11] Fixed D7 --- .../transpiler/distribute_transpiler.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python/paddle/distributed/transpiler/distribute_transpiler.py b/python/paddle/distributed/transpiler/distribute_transpiler.py index 60ec5bdb756f6..54f1c2379a378 100644 --- a/python/paddle/distributed/transpiler/distribute_transpiler.py +++ b/python/paddle/distributed/transpiler/distribute_transpiler.py @@ -2132,12 +2132,15 @@ def _create_table_optimize_block( table_opt_block = pserver_program._create_block(pre_block_idx) # create table param and grad var in pserver program # create table optimize block in pserver program - table_opt_op = [ - op - for op in self.optimize_ops - if 'Param' in op.input_names - and op.input("Param")[0] == self.table_name - ][0] + table_opt_op = next( + ( + op + for op in self.optimize_ops + if 'Param' in op.input_names + and op.input("Param")[0] == self.table_name + ), + None, + ) origin_param_var = self.origin_program.global_block().vars[ self.table_name From e91d5b4da95ab6f6edced91a8fd001a606b2f21e Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:17:58 +0800 Subject: [PATCH 02/11] Finished D9 --- python/paddle/pir/math_op_patch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/pir/math_op_patch.py b/python/paddle/pir/math_op_patch.py index b7900e332c0a8..ef50cbd6bcb5c 100644 --- a/python/paddle/pir/math_op_patch.py +++ b/python/paddle/pir/math_op_patch.py @@ -734,7 +734,7 @@ def to(self, *args, **kwargs): if len(invalid_keys) != 0: raise TypeError( "to() got an unexpected keyword argument " - + list(invalid_keys)[0] + + next(iter(invalid_keys), "unknown key") ) def dtype_first_sig(dtype, blocking=None): ... From d0e398d71e9ea0bf50920a6aface6ee2b758a226 Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:19:37 +0800 Subject: [PATCH 03/11] Fixed D8 --- .../distributed/transpiler/distribute_transpiler.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/python/paddle/distributed/transpiler/distribute_transpiler.py b/python/paddle/distributed/transpiler/distribute_transpiler.py index 54f1c2379a378..cd50aebca7324 100644 --- a/python/paddle/distributed/transpiler/distribute_transpiler.py +++ b/python/paddle/distributed/transpiler/distribute_transpiler.py @@ -1826,11 +1826,14 @@ def _update_dist_lookup_table_vars( for grad in grad_list if grad.name != grad_var_name(self.table_name) ] - self.table_param_grad = [ - param_grad - for param_grad in params_grads - if param_grad[0].name == self.table_name - ][0] + self.table_param_grad = next( + ( + param_grad + for param_grad in params_grads + if param_grad[0].name == self.table_name + ), + None, # Default value if no matching param_grad is found + ) table_grad_var = self.table_param_grad[1] if self.sync_mode: self.trainer_side_table_grad_list = [ From c7fed26a3e27979008b30943b60b39e3bcf35a21 Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:21:20 +0800 Subject: [PATCH 04/11] Fixed D10 --- python/paddle/static/amp/function_overload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/static/amp/function_overload.py b/python/paddle/static/amp/function_overload.py index 3ee9e7d388c79..bdc44079a6cab 100644 --- a/python/paddle/static/amp/function_overload.py +++ b/python/paddle/static/amp/function_overload.py @@ -123,7 +123,7 @@ def get(self, *args, **kwargs): satisfied_function_keys.remove(func_key) break if len(satisfied_function_keys) == 1: - key = list(satisfied_function_keys)[0] + key = next(iter(satisfied_function_keys), None) elif len(args) >= 3 and isinstance(args[2], float): key = FunctionType.FP16_ONLY else: From 3caaea3619d991819e13d70914fb1039b697e6db Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:23:30 +0800 Subject: [PATCH 05/11] Fixed D11 --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 2318d2c0852e3..9fc37458fa0d1 100644 --- a/setup.py +++ b/setup.py @@ -1023,9 +1023,9 @@ def get_paddle_extra_install_requirements(): output = subprocess.check_output(['nvcc', '--version']).decode( 'utf-8' ) - version_line = [ - line for line in output.split('\n') if 'release' in line - ][0] + version_line = next( + (line for line in output.split('\n') if 'release' in line), None + ) version = version_line.split(' ')[-1].split(',')[0] cuda_major_version = version.split('.')[0] except Exception as e: From c3e07a86201b3c2ddc513a1790039ffed5f344c6 Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:24:50 +0800 Subject: [PATCH 06/11] Fixed D12 --- test/sot/test_model_switch_training.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/sot/test_model_switch_training.py b/test/sot/test_model_switch_training.py index b887a3213a2a3..ab4b98501dda2 100644 --- a/test/sot/test_model_switch_training.py +++ b/test/sot/test_model_switch_training.py @@ -43,9 +43,9 @@ def setUp(self): def check_mode(self, is_train): self.assertEqual(len(self.compile_cache.cache), 1) - mode = list(self.compile_cache.cache.values())[ - 0 - ].partial_program.training + mode = next( + iter(self.compile_cache.cache.values()) + ).partial_program.training self.assertEqual(mode, is_train) def get_dygraph_out(self, input): From d14c54f2e2c20636861ec964b1745e6ff661ee90 Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:26:24 +0800 Subject: [PATCH 07/11] Fixed D13 --- test/xpu/test_tril_triu_op_xpu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/xpu/test_tril_triu_op_xpu.py b/test/xpu/test_tril_triu_op_xpu.py index 8f75f1df38ea1..aa8dfbe7b76ee 100644 --- a/test/xpu/test_tril_triu_op_xpu.py +++ b/test/xpu/test_tril_triu_op_xpu.py @@ -140,7 +140,7 @@ def test_errors1(self): errmsg = { "diagonal: TypeError": f"diagonal in {op_type} must be a python Int", } - expected = list(errmsg.keys())[0] + expected = next(iter(errmsg.keys())) with self.assertRaisesRegex( eval(expected.split(':')[-1]), errmsg[expected] ): @@ -155,7 +155,7 @@ def test_errors2(self): errmsg = { "input: ValueError": f"x shape in {op_type} must be at least 2-D", } - expected = list(errmsg.keys())[0] + expected = next(iter(errmsg.keys())) with self.assertRaisesRegex( eval(expected.split(':')[-1]), errmsg[expected] ): From 0d018d95bee85b9b57da007f8b6ca038e591452a Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:16:39 +0800 Subject: [PATCH 08/11] Removed None --- .../transpiler/distribute_transpiler.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/python/paddle/distributed/transpiler/distribute_transpiler.py b/python/paddle/distributed/transpiler/distribute_transpiler.py index cd50aebca7324..bd61e5b773098 100644 --- a/python/paddle/distributed/transpiler/distribute_transpiler.py +++ b/python/paddle/distributed/transpiler/distribute_transpiler.py @@ -1827,12 +1827,9 @@ def _update_dist_lookup_table_vars( if grad.name != grad_var_name(self.table_name) ] self.table_param_grad = next( - ( - param_grad - for param_grad in params_grads - if param_grad[0].name == self.table_name - ), - None, # Default value if no matching param_grad is found + param_grad + for param_grad in params_grads + if param_grad[0].name == self.table_name ) table_grad_var = self.table_param_grad[1] if self.sync_mode: @@ -2136,13 +2133,10 @@ def _create_table_optimize_block( # create table param and grad var in pserver program # create table optimize block in pserver program table_opt_op = next( - ( - op - for op in self.optimize_ops - if 'Param' in op.input_names - and op.input("Param")[0] == self.table_name - ), - None, + op + for op in self.optimize_ops + if 'Param' in op.input_names + and op.input("Param")[0] == self.table_name ) origin_param_var = self.origin_program.global_block().vars[ From c4c9a819632214d551cbce696444cede062ddd38 Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:18:25 +0800 Subject: [PATCH 09/11] Removed None --- python/paddle/static/amp/function_overload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/static/amp/function_overload.py b/python/paddle/static/amp/function_overload.py index bdc44079a6cab..ea01cfdd2fbf5 100644 --- a/python/paddle/static/amp/function_overload.py +++ b/python/paddle/static/amp/function_overload.py @@ -123,7 +123,7 @@ def get(self, *args, **kwargs): satisfied_function_keys.remove(func_key) break if len(satisfied_function_keys) == 1: - key = next(iter(satisfied_function_keys), None) + key = next(iter(satisfied_function_keys)) elif len(args) >= 3 and isinstance(args[2], float): key = FunctionType.FP16_ONLY else: From 537ef826ccc3ff773249bf368ddc8bf14cb87619 Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:20:16 +0800 Subject: [PATCH 10/11] Removed None --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9fc37458fa0d1..49b9f8e7aff8b 100644 --- a/setup.py +++ b/setup.py @@ -1024,7 +1024,7 @@ def get_paddle_extra_install_requirements(): 'utf-8' ) version_line = next( - (line for line in output.split('\n') if 'release' in line), None + line for line in output.split('\n') if 'release' in line ) version = version_line.split(' ')[-1].split(',')[0] cuda_major_version = version.split('.')[0] From 73aa52b66d91bfac60a9bc1bc3fde634088a0b5a Mon Sep 17 00:00:00 2001 From: MufanColin <76479709+MufanColin@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:22:14 +0800 Subject: [PATCH 11/11] Removed unnecessary parts --- python/paddle/pir/math_op_patch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/pir/math_op_patch.py b/python/paddle/pir/math_op_patch.py index ef50cbd6bcb5c..ef5aa6beb5604 100644 --- a/python/paddle/pir/math_op_patch.py +++ b/python/paddle/pir/math_op_patch.py @@ -734,7 +734,7 @@ def to(self, *args, **kwargs): if len(invalid_keys) != 0: raise TypeError( "to() got an unexpected keyword argument " - + next(iter(invalid_keys), "unknown key") + + next(iter(invalid_keys)) ) def dtype_first_sig(dtype, blocking=None): ...