From 1f8e6ad661da03c6059fe42e10e09cde7ebac3b0 Mon Sep 17 00:00:00 2001 From: Infinity_lee Date: Thu, 23 Mar 2023 09:35:28 +0800 Subject: [PATCH] [CodeStyle][C404] Unnecessary list comprehension (rewrite as a dict comprehension) (#51969) --- python/paddle/distributed/passes/auto_parallel_sharding.py | 2 +- .../fluid/tests/unittests/distributed_fused_lamb_test_base.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/python/paddle/distributed/passes/auto_parallel_sharding.py b/python/paddle/distributed/passes/auto_parallel_sharding.py index eba71a86f57..d210bc12f52 100644 --- a/python/paddle/distributed/passes/auto_parallel_sharding.py +++ b/python/paddle/distributed/passes/auto_parallel_sharding.py @@ -1790,7 +1790,7 @@ def group_param(sharding_info, fuse_size): class ShardingInfo: def __init__(self, group, rank, params_grads, partition_algor): self.group = group - self.params_grads = dict([(p.name, (p, g)) for p, g in params_grads]) + self.params_grads = {p.name: (p, g) for p, g in params_grads} assert len(self.params_grads) == len( set(self.params_grads) ), "found duplicated param in params_grads" diff --git a/python/paddle/fluid/tests/unittests/distributed_fused_lamb_test_base.py b/python/paddle/fluid/tests/unittests/distributed_fused_lamb_test_base.py index 3fa9c125292..bcf2b7c49b6 100644 --- a/python/paddle/fluid/tests/unittests/distributed_fused_lamb_test_base.py +++ b/python/paddle/fluid/tests/unittests/distributed_fused_lamb_test_base.py @@ -231,9 +231,7 @@ def run_model(use_distributed_lamb, use_fp16, use_master_param_norm, **kwargs): def reader(): for _ in range(6): - yield dict( - [(grad.name, gen_random_grad_tensor(grad)) for grad in grads] - ) + yield {grad.name: gen_random_grad_tensor(grad) for grad in grads} scope = paddle.static.Scope() fetch_list = params -- GitLab