Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeStyle][Ruff][BUAA][G-[59-67]] Fix ruff RUF005 diagnostic for 9 files in python/paddle #67282

Merged
merged 26 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
465e2c6
check ruff
Fripping Aug 9, 2024
79db6c4
check ruff
Fripping Aug 9, 2024
556fedd
Delete test/legacy_test/.ipynb_checkpoints directory
Fripping Aug 9, 2024
f65ac24
Delete python/paddle/static/.ipynb_checkpoints directory
Fripping Aug 9, 2024
d8cbc40
Delete python/paddle/nn/layer/.ipynb_checkpoints directory
Fripping Aug 9, 2024
9451a19
Delete python/paddle/optimizer/.ipynb_checkpoints directory
Fripping Aug 9, 2024
bce3752
Delete python/paddle/jit/dy2static/.ipynb_checkpoints directory
Fripping Aug 9, 2024
61c94cd
Delete python/paddle/nn/functional/.ipynb_checkpoints directory
Fripping Aug 9, 2024
6929d53
Delete python/paddle/sparse/nn/layer/.ipynb_checkpoints directory
Fripping Aug 9, 2024
96668f2
Delete python/paddle/incubate/nn/layer/.ipynb_checkpoints directory
Fripping Aug 9, 2024
67df348
Delete python/paddle/quantization/imperative/.ipynb_checkpoints direc…
Fripping Aug 9, 2024
7b45c92
Delete python/paddle/incubate/multiprocessing/.ipynb_checkpoints dire…
Fripping Aug 9, 2024
b497d15
Delete python/paddle/incubate/distributed/fleet/.ipynb_checkpoints di…
Fripping Aug 9, 2024
9b5d1d9
Delete python/paddle/jit/dy2static/transformers/.ipynb_checkpoints di…
Fripping Aug 9, 2024
04d05b5
Delete python/paddle/jit/sot/opcode_translator/executor/.ipynb_checkp…
Fripping Aug 9, 2024
24dace7
Update utils.py
Fripping Aug 12, 2024
4e795f5
Update reductions.py
Fripping Aug 12, 2024
3a904f8
Update fused_transformer.py
Fripping Aug 12, 2024
71eadb3
Update program_translator.py
Fripping Aug 12, 2024
e45df47
Update decorator_transformer.py
Fripping Aug 12, 2024
8a98acd
Update ifelse_transformer.py
Fripping Aug 12, 2024
9dafc69
Update logical_transformer.py
Fripping Aug 12, 2024
2085096
Update loop_transformer.py
Fripping Aug 12, 2024
5fa873d
Update opcode_executor.py
Fripping Aug 12, 2024
b9efc26
Update opcode_executor.py
Fripping Aug 12, 2024
61bfcbe
Update conv.py
Fripping Aug 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/paddle/nn/functional/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4545,7 +4545,7 @@ def adaptive_log_softmax_with_loss(
output = paddle.zeros([batch_size], dtype=input.dtype)
gather_inds = paddle.empty([batch_size], dtype=label.dtype)

cutoff_values = [0] + cutoffs
cutoff_values = [0, *cutoffs]
for i in range(len(cutoff_values) - 1):
low_idx = cutoff_values[i]
high_idx = cutoff_values[i + 1]
Expand Down
24 changes: 12 additions & 12 deletions python/paddle/nn/functional/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def _update_padding_nd(padding, num_dims, channel_last=False, ceil_mode=False):
def _expand_low_nd_padding(padding):
# 1d to 2d fake input
if len(padding) == 2:
padding = [0] * 2 + padding
padding = [0, 0, *padding]
elif len(padding) == 1:
padding = [0] + padding
padding = [0, *padding]
else:
raise ValueError(
f"The size of padding's dimension should be 1 or 2. But got padding={padding}"
Expand Down Expand Up @@ -250,12 +250,12 @@ def avg_pool1d(
_check_input(x, 3)
x = unsqueeze(x, [2])
kernel_size = convert_to_list(kernel_size, 1, 'kernel_size')
kernel_size = [1] + kernel_size
kernel_size = [1, *kernel_size]
if stride is None:
stride = kernel_size
else:
stride = convert_to_list(stride, 1, 'pool_stride')
stride = [1] + stride
stride = [1, *stride]

_check_value_limitation(kernel_size, "kernel_size", min_limit=1e-3)
_check_value_limitation(stride, "stride", min_limit=1e-3)
Expand Down Expand Up @@ -628,11 +628,11 @@ def max_pool1d(
data_format = "NCHW"
_check_input(x, 3)
x = unsqueeze(x, [2])
kernel_size = [1] + convert_to_list(kernel_size, 1, 'pool_size')
kernel_size = [1, *convert_to_list(kernel_size, 1, "pool_size")]
if stride is None:
stride = kernel_size
else:
stride = [1] + convert_to_list(stride, 1, 'pool_stride')
stride = [1, *convert_to_list(stride, 1, "pool_stride")]

padding, padding_algorithm = _update_padding_nd(
padding, 1, ceil_mode=ceil_mode
Expand Down Expand Up @@ -823,11 +823,11 @@ def max_unpool1d(
data_format = "NCHW"
x = unsqueeze(x, [2])
indices = unsqueeze(indices, [2])
kernel_size = [1] + convert_to_list(kernel_size, 1, 'pool_size')
kernel_size = [1, *convert_to_list(kernel_size, 1, "pool_size")]
if stride is None:
stride = kernel_size
else:
stride = [1] + convert_to_list(stride, 1, 'pool_stride')
stride = [1, *convert_to_list(stride, 1, 'pool_stride')]
padding, padding_algorithm = _update_padding_nd(padding, 1)
# use 2d to implenment 1d should expand padding in advance.
padding = _expand_low_nd_padding(padding)
Expand Down Expand Up @@ -1475,7 +1475,7 @@ def adaptive_avg_pool1d(
"""
pool_type = 'avg'
_check_input(x, 3)
pool_size = [1] + convert_to_list(output_size, 1, 'pool_size')
pool_size = [1, *convert_to_list(output_size, 1, "pool_size")]

x = unsqueeze(x, [2])
if in_dynamic_or_pir_mode():
Expand Down Expand Up @@ -1845,7 +1845,7 @@ def adaptive_max_pool1d(
"""
_check_input(x, 3)

pool_size = [1] + convert_to_list(output_size, 1, 'pool_size')
pool_size = [1, *convert_to_list(output_size, 1, "pool_size")]

x = unsqueeze(x, [2])
if in_dynamic_or_pir_mode():
Expand Down Expand Up @@ -2468,12 +2468,12 @@ def lp_pool1d(
_check_input(x, 3)
x = unsqueeze(x, [axis])
kernel_size = convert_to_list(kernel_size, 1, 'kernel_size')
kernel_size = [1] + kernel_size
kernel_size = [1, *kernel_size]
if stride is None:
stride = kernel_size
else:
stride = convert_to_list(stride, 1, 'pool_stride')
stride = [1] + stride
stride = [1, *stride]

_check_value_limitation(kernel_size, "kernel_size", min_limit=1e-3)
_check_value_limitation(stride, "stride", min_limit=1e-3)
Expand Down
6 changes: 4 additions & 2 deletions python/paddle/nn/layer/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def __init__(
filter_shape = [
self._in_channels,
out_channels // groups,
] + self._kernel_size
*self._kernel_size,
]
else:
if in_channels % groups != 0:
raise ValueError("in_channels must be divisible by groups.")
Expand All @@ -165,7 +166,8 @@ def __init__(
filter_shape = [
out_channels,
in_channels // groups,
] + self._kernel_size
*self._kernel_size,
]

def _get_default_param_initializer():
if transposed:
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/nn/layer/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,7 @@ def __init__(

self.in_features = in_features
self.n_classes = n_classes
self.cutoffs = cutoffs + [n_classes]
self.cutoffs = [*cutoffs, n_classes]
self.div_value = div_value
self._weight_attr = weight_attr
self._bias_attr = bias_attr
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/nn/layer/rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _maybe_copy(state: Tensor, new_state: Tensor, step_mask: Tensor) -> Tensor:


def _transpose_batch_time(x: Tensor) -> Tensor:
perm = [1, 0] + list(range(2, len(x.shape)))
perm = [1, 0, *list(range(2, len(x.shape)))]
return paddle.transpose(x, perm)


Expand Down Expand Up @@ -650,7 +650,7 @@ def _is_shape_sequence(seq):
class Shape:
def __init__(self, shape):
self.shape = (
list(shape) if shape[0] == -1 else ([-1] + list(shape))
list(shape) if shape[0] == -1 else ([-1, *list(shape)])
)

# nested structure of shapes
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/optimizer/asgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _create_accumulators(self, block, parameters):
p_new,
p.dtype,
0,
[self._n] + list(p.shape),
[self._n, *list(p.shape)],
)

self._add_accumulator(
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/quantization/imperative/qat.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,9 @@ def _gather_scales(self, program, scope, fetch_targets):

def _gather_input_scale():
target_ops = []
skip_ops = utils.fake_quantize_dequantize_op_types + [
"moving_average_abs_max_scale"
skip_ops = [
*utils.fake_quantize_dequantize_op_types,
"moving_average_abs_max_scale",
]
for block in program.blocks:
for op in block.ops:
Expand Down
6 changes: 4 additions & 2 deletions python/paddle/sparse/nn/layer/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def __init__(
)

# the sparse conv restricts the shape is [D, H, W, in_channels, out_channels]
filter_shape = self._kernel_size + [
filter_shape = [
*self._kernel_size,
self._in_channels,
self._out_channels,
]
Expand Down Expand Up @@ -233,7 +234,8 @@ def __init__(
)

# the sparse conv restricts the shape is [H, W, in_channels, out_channels]
filter_shape = self._kernel_size + [
filter_shape = [
*self._kernel_size,
self._in_channels,
self._out_channels,
]
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/static/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def batch(self, batch_size: int | Size1) -> Self:
f"type(batch_size) shall be `int`, but received {type(batch_size).__name__}."
)

new_shape = [batch_size] + list(self.shape)
new_shape = [batch_size, *list(self.shape)]
self.shape = tuple(new_shape)

return self
Expand Down