Skip to content

Commit

Permalink
[CodeStyle][UP031] fix some /test/{rnn, tokenizer, xpu}* and `tools…
Browse files Browse the repository at this point in the history
…/*` - part 17 (PaddlePaddle#65578)
  • Loading branch information
gouzil authored Jun 30, 2024
1 parent 78632fa commit d7bb2a6
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion test/rnn/test_rnn_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def forward(self, input):
full_graph=True,
)
temp_dir = tempfile.TemporaryDirectory()
save_dirname = os.path.join(temp_dir.name, "./inference/%s_infer" % mode)
save_dirname = os.path.join(temp_dir.name, f"./inference/{mode}_infer")

paddle.jit.save(rnn, save_dirname)

Expand Down
4 changes: 2 additions & 2 deletions test/tokenizer/tokenizer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def convert_to_unicode(text):
elif isinstance(text, bytes):
return text.decode("utf-8", "ignore")
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
raise ValueError(f"Unsupported string type: {type(text)}")


def whitespace_tokenize(text):
Expand Down Expand Up @@ -484,7 +484,7 @@ def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
continue
path = os.path.join(default_root, file_path.split('/')[-1])
if os.path.exists(path):
print("Already cached %s" % path)
print(f"Already cached {path}")
resolved_vocab_files[file_id] = path
else:
print(f"Downloading {file_path} and saved to {default_root}")
Expand Down
4 changes: 2 additions & 2 deletions test/xpu/get_test_cover_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def create_test_class(
if test_class[0] == '__class__':
continue
class_obj = test_class[1]
cls_name = f"{test_class[0]}_{str(test_type)}"
cls_name = f"{test_class[0]}_{test_type}"
func_globals[cls_name] = type(
cls_name,
(class_obj,),
Expand All @@ -313,7 +313,7 @@ def create_test_class(
):
base_class, dynamic_classes = test_class_obj.dynamic_create_class()
for dy_class in dynamic_classes:
cls_name = f"{dy_class[0]}_{str(test_type)}"
cls_name = f"{dy_class[0]}_{test_type}"
attr_dict = dy_class[1]
attr_dict['in_type'] = type_dict_str_to_numpy[test_type]
attr_dict['in_type_str'] = test_type
Expand Down
4 changes: 2 additions & 2 deletions test/xpu/test_conv2d_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def conv2d_forward_naive(
):
if padding_algorithm not in ["SAME", "VALID", "EXPLICIT"]:
raise ValueError(
f"Unknown Attr(padding_algorithm): '{str(padding_algorithm)}'. "
f"Unknown Attr(padding_algorithm): '{padding_algorithm}'. "
"It can only be 'SAME' or 'VALID'."
)

if data_format not in ["NCHW", "NHWC"]:
raise ValueError(
f"Unknown Attr(data_format): '{str(data_format)}' ."
f"Unknown Attr(data_format): '{data_format}' ."
"It can only be 'NCHW' or 'NHWC'."
)

Expand Down
2 changes: 1 addition & 1 deletion test/xpu/test_conv2d_transpose_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def conv2dtranspose_forward_naive(input_, filter_, attrs):
padding_algorithm = attrs['padding_algorithm']
if padding_algorithm not in ["SAME", "VALID", "EXPLICIT"]:
raise ValueError(
f"Unknown Attr(padding_algorithm): '{str(padding_algorithm)}'. "
f"Unknown Attr(padding_algorithm): '{padding_algorithm}'. "
"It can only be 'SAME' or 'VALID'."
)

Expand Down
4 changes: 2 additions & 2 deletions test/xpu/test_conv3d_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def conv3d_forward_naive(
):
if padding_algorithm not in ["SAME", "VALID", "EXPLICIT"]:
raise ValueError(
f"Unknown Attr(padding_algorithm): '{str(padding_algorithm)}'. "
f"Unknown Attr(padding_algorithm): '{padding_algorithm}'. "
"It can only be 'SAME' or 'VALID'."
)

if data_format not in ["NCDHW", "NDHWC"]:
raise ValueError(
f"Unknown Attr(data_format): '{str(data_format)}' ."
f"Unknown Attr(data_format): '{data_format}' ."
"It can only be 'NCDHW' or 'NDHWC'."
)

Expand Down
2 changes: 1 addition & 1 deletion test/xpu/test_depthwise_conv2d_transpose_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def depthwiseconv2dtranspose_forward_naive(input_, filter_, attrs):
padding_algorithm = attrs['padding_algorithm']
if padding_algorithm not in ["SAME", "VALID", "EXPLICIT"]:
raise ValueError(
f"Unknown Attr(padding_algorithm): '{str(padding_algorithm)}'. "
f"Unknown Attr(padding_algorithm): '{padding_algorithm}'. "
"It can only be 'SAME' or 'VALID'."
)

Expand Down
2 changes: 1 addition & 1 deletion test/xpu/test_pool2d_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _get_padding_with_SAME(input_shape, pool_size, pool_stride):
padding_algorithm = padding_algorithm.upper()
if padding_algorithm not in ["SAME", "VALID", "EXPLICIT"]:
raise ValueError(
f"Unknown Attr(padding_algorithm): '{str(padding_algorithm)}'. "
f"Unknown Attr(padding_algorithm): '{padding_algorithm}'. "
"It can only be 'SAME' or 'VALID'."
)

Expand Down
2 changes: 1 addition & 1 deletion test/xpu/test_pool3d_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _get_padding_with_SAME(input_shape, pool_size, pool_stride):
padding_algorithm = padding_algorithm.upper()
if padding_algorithm not in ["SAME", "VALID", "EXPLICIT"]:
raise ValueError(
f"Unknown Attr(padding_algorithm): '{str(padding_algorithm)}'. "
f"Unknown Attr(padding_algorithm): '{padding_algorithm}'. "
"It can only be 'SAME' or 'VALID'."
)

Expand Down
2 changes: 1 addition & 1 deletion tools/cinn/tvm_benchmark/test_topi_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_op(
c = tvm.nd.array(numpy.zeros(out_shape, dtype=dtype[len(dtype) - 1]), ctx)

evaluator = func.time_evaluator(func.entry_name, ctx, number=repeat)
print("repeat: %f" % repeat)
print(f"repeat: {repeat:f}")
if len(input_shapes) == 1:
print("Baseline: %f" % (evaluator(a, c).mean * 1000))
print(tvm.lower(s, [A, C], simple_mode=True))
Expand Down
4 changes: 2 additions & 2 deletions tools/count_api_without_core_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def md5(doc):
except UnicodeDecodeError as e:
md5sum = None
print(
f"Error({str(e)}) occurred when `md5({doc})`, discard it.",
f"Error({e}) occurred when `md5({doc})`, discard it.",
file=sys.stderr,
)
return md5sum
Expand Down Expand Up @@ -110,7 +110,7 @@ def visit_member(parent_name, member, func):
return
else:
raise RuntimeError(
f"Unsupported generate signature of member, type {str(type(member))}"
f"Unsupported generate signature of member, type {type(member)}"
)


Expand Down
4 changes: 3 additions & 1 deletion tools/get_single_test_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def getFNDAFile(rootPath, test):
symbol = tmp_data[1]
if symbol in fnda_base_dict:
if (hit - fnda_base_dict[symbol]) > 0:
fnda_str = f'FNDA:{str(hit - fnda_base_dict[symbol])},{symbol}'
fnda_str = (
f'FNDA:{hit - fnda_base_dict[symbol]},{symbol}'
)
os.system(f'echo {fnda_str} >> {fn_filename}')
else:
os.system(f'echo {message} >> {fn_filename}')
Expand Down
2 changes: 1 addition & 1 deletion tools/print_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def md5(doc):
except UnicodeDecodeError as e:
md5sum = None
print(
f"Error({str(e)}) occurred when `md5({doc})`, discard it.",
f"Error({e}) occurred when `md5({doc})`, discard it.",
file=sys.stderr,
)

Expand Down

0 comments on commit d7bb2a6

Please sign in to comment.