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-[181-190]] Fix Ruff RUF005 diagnostic for 10 files in test/ir/pir/fused_pass/onednn/ and test/legacy_test/ #67141

Merged
merged 8 commits into from
Aug 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def build_ir_program(self):
name='x', shape=[5, 5, 5, 5], dtype='float32'
)
transpose = paddle.transpose(
x, [len(x.shape) - 1] + list(range(0, len(x.shape) - 1))
x, [len(x.shape) - 1, *range(0, len(x.shape) - 1)]
)
out = paddle.unsqueeze(transpose, [1])
out = paddle.assign(out)
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/ctr_dataset_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def reader():
dnn_input = load_dnn_input_record(fs[0])
lr_input = load_lr_input_record(fs[1])
click = [int(fs[2])]
yield [dnn_input] + [lr_input] + [click]
yield (*dnn_input, *lr_input, *click)

return reader

Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/dist_allreduce_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def cnn_model(data):

SIZE = 10
input_shape = conv_pool_2.shape
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
param_shape = [*reduce(lambda a, b: a * b, input_shape[1:], 1), SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5

predict = paddle.static.nn.fc(
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/dist_fleet_raw_program_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def cnn_model(data):

SIZE = 10
input_shape = conv_pool_2.shape
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
param_shape = [*reduce(lambda a, b: a * b, input_shape[1:], 1), SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5

predict = paddle.static.nn.fc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def cnn_model(data):

SIZE = 10
input_shape = conv_pool_2.shape
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
param_shape = [*reduce(lambda a, b: a * b, input_shape[1:], 1), SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5

predict = paddle.static.nn.fc(
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/dist_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def cnn_model(data):

SIZE = 10
input_shape = conv_pool_2.shape
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
param_shape = [*reduce(lambda a, b: a * b, input_shape[1:], 1), SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5

predict = paddle.static.nn.fc(
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/dist_mnist_dgc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def cnn_model(data):

SIZE = 10
input_shape = conv_pool_2.shape
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
param_shape = [*reduce(lambda a, b: a * b, input_shape[1:], 1), SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5

predict = paddle.static.nn.fc(
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def __split_heads(x, num_heads):
# [batch_size, max_sequence_length, num_heads, hidden_size_per_head].
reshaped = paddle.reshape(
x=x,
shape=list(x.shape[:-1]) + [num_heads, hidden_size // num_heads],
shape=[*x.shape[:-1], num_heads, hidden_size // num_heads],
)

# permute the dimensions into:
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/seresnext_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def bottleneck_block(input, num_filters, stride, cardinality, reduction_ratio):

def SE_ResNeXt50Small(use_feed):
img = paddle.static.data(
name='image', shape=[-1] + img_shape, dtype='float32'
name='image', shape=[-1, *img_shape], dtype='float32'
)
label = paddle.static.data(name='label', shape=[-1, 1], dtype='int64')

Expand Down
7 changes: 4 additions & 3 deletions test/legacy_test/simple_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def pir_fc(hidden, size, activation, param_attr, bias_attr):
input_shape = input.shape
num_flatten_dims = len(input_shape) - 1
param_shape = [
reduce(lambda a, b: a * b, input_shape[num_flatten_dims:], 1)
] + [size]
reduce(lambda a, b: a * b, input_shape[num_flatten_dims:], 1),
size,
]

w = helper.create_parameter(
attr=param_attr, shape=param_shape, dtype=input.dtype, is_bias=False
Expand Down Expand Up @@ -216,7 +217,7 @@ def bow_net(
def init_data(batch_size=32, img_shape=[784], label_range=9):
np.random.seed(5)
assert isinstance(img_shape, list)
input_shape = [batch_size] + img_shape
input_shape = [batch_size, *img_shape]
img = np.random.random(size=input_shape).astype(np.float32)
label = (
np.array([np.random.randint(0, label_range) for _ in range(batch_size)])
Expand Down