Skip to content

Commit

Permalink
[CodeStyle][task 1] enable Ruff UP032 rule with some comments (Paddle…
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyulingyue authored and hitywt committed Oct 24, 2023
1 parent 2f8c8f6 commit 299632e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
12 changes: 6 additions & 6 deletions python/paddle/distributed/fleet/elastic/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ def _update_elastic_scale_out(self):
if curr_host_port not in host_endpoints:
host_endpoints.append(curr_host_port)

os.environ[
'PADDLE_TRAINER_ID'
] = f'{host_endpoints.index(self.curr_host)}'
os.environ['PADDLE_TRAINER_ID'] = str(
host_endpoints.index(self.curr_host)
)
hosts = ','.join(
[host_port.split(":")[0] for host_port in host_endpoints]
)
Expand Down Expand Up @@ -547,9 +547,9 @@ def _update_elastic_scale_in(self):
)

self.args.ips = hosts
os.environ[
'PADDLE_TRAINER_ID'
] = f'{sorted_endpoints.index(self.curr_host)}'
os.environ['PADDLE_TRAINER_ID'] = str(
sorted_endpoints.index(self.curr_host)
)
os.environ['PADDLE_TRAINERS'] = hosts
self.np = len(sorted_endpoints)
os.environ['PADDLE_TRAINER_ENDPOINTS'] = ','.join(sorted_endpoints)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/distributed/passes/auto_parallel_amp.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def build_state(self):
fwd_op_id = self.grad_op_to_op_map[
op.desc.original_id()
]
assert fwd_op_id in self._op_fp16_dict, f"{str(op)}"
assert fwd_op_id in self._op_fp16_dict, str(op)
self._op_fp16_dict[
op.desc.original_id()
] = self._is_fp16_op(fwd_op_id)
Expand Down
8 changes: 2 additions & 6 deletions python/paddle/tensor/to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,11 @@ def _format_item(np_var, max_width=0, signed=False):
or np_var.dtype == np.float16
):
if DEFAULT_PRINT_OPTIONS.sci_mode:
item_str = f'{{:.{DEFAULT_PRINT_OPTIONS.precision}e}}'.format(
np_var
)
item_str = f'{np_var:.{DEFAULT_PRINT_OPTIONS.precision}e}'
elif np.ceil(np_var) == np_var:
item_str = f'{np_var:.0f}.'
else:
item_str = f'{{:.{DEFAULT_PRINT_OPTIONS.precision}f}}'.format(
np_var
)
item_str = f'{np_var:.{DEFAULT_PRINT_OPTIONS.precision}f}'
else:
item_str = f'{np_var}'

Expand Down
14 changes: 7 additions & 7 deletions test/legacy_test/test_inplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_backward_error(self):
loss = paddle.nn.functional.relu(var_c + var_d)
with self.assertRaisesRegex(
RuntimeError,
f"received tensor_version:{1} != wrapper_version_snapshot:{0}",
"received tensor_version:1 != wrapper_version_snapshot:0",
):
loss.backward()

Expand Down Expand Up @@ -171,7 +171,7 @@ def test_backward_error(self):
loss = paddle.nn.functional.relu(var_c)
with self.assertRaisesRegex(
RuntimeError,
f"received tensor_version:{1} != wrapper_version_snapshot:{0}",
"received tensor_version:1 != wrapper_version_snapshot:0",
):
loss.backward()

Expand Down Expand Up @@ -939,7 +939,7 @@ def test_backward_error(self):
loss = paddle.nn.functional.relu(var_c)
with self.assertRaisesRegex(
RuntimeError,
f"received tensor_version:{3} != wrapper_version_snapshot:{0}",
"received tensor_version:3 != wrapper_version_snapshot:0",
):
loss.backward()

Expand Down Expand Up @@ -1028,7 +1028,7 @@ def test_backward_error(self):
loss = paddle.nn.functional.relu(var_c)
with self.assertRaisesRegex(
RuntimeError,
f"received tensor_version:{2} != wrapper_version_snapshot:{0}",
"received tensor_version:2 != wrapper_version_snapshot:0",
):
loss.backward()

Expand Down Expand Up @@ -1104,7 +1104,7 @@ def test_backward_error(self):
loss = paddle.nn.functional.relu(var_c)
with self.assertRaisesRegex(
RuntimeError,
f"received tensor_version:{2} != wrapper_version_snapshot:{0}",
"received tensor_version:2 != wrapper_version_snapshot:0",
):
loss.backward()

Expand Down Expand Up @@ -1400,7 +1400,7 @@ def test_backward_error(self):
loss = paddle.nn.functional.relu(var_c)
with self.assertRaisesRegex(
RuntimeError,
f"received tensor_version:{2} != wrapper_version_snapshot:{0}",
"received tensor_version:2 != wrapper_version_snapshot:0",
):
loss.backward()

Expand Down Expand Up @@ -1442,7 +1442,7 @@ def test_backward_error(self):
loss = paddle.nn.functional.relu(var_c)
with self.assertRaisesRegex(
RuntimeError,
f"received tensor_version:{2} != wrapper_version_snapshot:{0}",
"received tensor_version:2 != wrapper_version_snapshot:0",
):
loss.backward()

Expand Down

0 comments on commit 299632e

Please sign in to comment.