Skip to content

Commit

Permalink
[CodeStyle][Ruff][BUAA][G-[181-190]] Fix Ruff RUF005 diagnostic for…
Browse files Browse the repository at this point in the history
… 10 files in `test/ir/pir/fused_pass/onednn/` and `test/legacy_test/` (#67141)

---------

Co-authored-by: Nyakku Shigure <[email protected]>
  • Loading branch information
Jeff114514 and SigureMo authored Aug 10, 2024
1 parent 25da882 commit 72554dc
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 16 deletions.
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
6 changes: 3 additions & 3 deletions test/legacy_test/test_flash_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,10 @@ def gen_unpadded_data(self, dtype):
low=1, high=self.seq_len, size=[self.batch_size]
)
cu_seqlen_q = paddle.to_tensor(
[0, *np.cumsum(seq_len_q)], dtype=paddle.int32
[0, *np.cumsum(seq_len_q).tolist()], dtype=paddle.int32
)
cu_seqlen_k = paddle.to_tensor(
[0, *np.cumsum(seq_len_k)], dtype=paddle.int32
[0, *np.cumsum(seq_len_k).tolist()], dtype=paddle.int32
)

qs, ks, vs = [], [], []
Expand Down Expand Up @@ -966,7 +966,7 @@ def gen_unpadded_data(self, dtype):
)
seq_len_k = seq_len_q
cu_seqlen_q = paddle.to_tensor(
[0, *np.cumsum(seq_len_q)], dtype=paddle.int32
[0, *np.cumsum(seq_len_q).tolist()], dtype=paddle.int32
)
cu_seqlen_k = cu_seqlen_q

Expand Down
4 changes: 3 additions & 1 deletion test/sequence/test_sequence_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ def init_test_case(self):
self.input_size = [self.input_row, 25]
idx = list(range(self.input_size[0]))
del idx[0]
offset_lod = [[0, *np.sort(random.sample(idx, 8)), self.input_size[0]]]
offset_lod = [
[0, *np.sort(random.sample(idx, 8)).tolist(), self.input_size[0]]
]
self.lod = [[]]
# convert from offset-based lod to length-based lod
for i in range(len(offset_lod[0]) - 1):
Expand Down

0 comments on commit 72554dc

Please sign in to comment.