Skip to content

Commit d91457d

Browse files
authored
[CodeStyle] black -> ruff format migration - part 37 (#74789)
1 parent ab03fa2 commit d91457d

File tree

43 files changed

+149
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+149
-145
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ repos:
101101
102102
# | test/[b-h].+
103103
104-
# | test/[i-k].+
104+
| test/[i-k].+
105105
106106
# | test/l.+
107107
@@ -157,7 +157,7 @@ repos:
157157
158158
| test/[b-h].+
159159
160-
| test/[i-k].+
160+
# | test/[i-k].+
161161
162162
| test/l.+
163163

test/ipu/test_ipu_strategy_ipu.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def test_set_options(self):
4848
try:
4949
ipu_strategy.set_options({option_name: set_value})
5050
new_value = ipu_strategy.get_option(option_name)
51-
assert (
52-
new_value == set_value
53-
), f"set {option_name} to {set_value} failed"
51+
assert new_value == set_value, (
52+
f"set {option_name} to {set_value} failed"
53+
)
5454
except:
5555
raise Exception(f"set {option_name} to {set_value} failed")
5656

@@ -78,13 +78,13 @@ def test_set_other_options(self):
7878
for k, v in options.items():
7979
ipu_strategy.set_options({k: v})
8080
if isinstance(v, list):
81-
assert (
82-
v.sort() == ipu_strategy.get_option(k).sort()
83-
), f"set {k} to {v} failed "
81+
assert v.sort() == ipu_strategy.get_option(k).sort(), (
82+
f"set {k} to {v} failed "
83+
)
8484
else:
85-
assert v == ipu_strategy.get_option(
86-
k
87-
), f"set {k} to {v} failed "
85+
assert v == ipu_strategy.get_option(k), (
86+
f"set {k} to {v} failed "
87+
)
8888

8989
# The custom logger need 2 int as inputs
9090
logger = lambda progress, total: print(

test/ir/inference/auto_scan_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ def run_and_statis(
465465
report_multiple_bugs=False,
466466
)
467467
settings.load_profile("ci")
468-
assert (
469-
passes is not None
470-
), "Parameter of passes must be defined in function run_and_statis."
468+
assert passes is not None, (
469+
"Parameter of passes must be defined in function run_and_statis."
470+
)
471471
self.passes = passes
472472

473473
self.add_ignore_pass_case()
@@ -979,7 +979,9 @@ def random_to_skip():
979979
assert any(
980980
op.name() == "pd_op.tensorrt_engine"
981981
for op in trt_program.global_block().ops
982-
), "trt_program does not contain any tensorrt_engine ops."
982+
), (
983+
"trt_program does not contain any tensorrt_engine ops."
984+
)
983985

984986
feed_data = prog_config.get_feed_data()
985987
for key, value in feed_data.items():

test/ir/inference/dist_llama_inference_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ def __init__(self, config: FusedMultiTransformerConfig):
191191

192192
self.embed_dim = config.embed_dim
193193
self.head_dim = config.embed_dim // config.num_heads
194-
assert (
195-
self.head_dim * config.num_heads == config.embed_dim
196-
), "embed_dim must be divisible by num_heads"
194+
assert self.head_dim * config.num_heads == config.embed_dim, (
195+
"embed_dim must be divisible by num_heads"
196+
)
197197

198198
# tensor model parallel
199199
if config.nranks > 1:
@@ -406,9 +406,9 @@ def init_weight(self):
406406

407407
def get_attr(self, attrs, idx):
408408
if isinstance(attrs, (list, tuple)):
409-
assert (
410-
len(attrs) == self.num_layers
411-
), f"length of attrs is {len(attrs)} is not equal to self.num_layers {self.num_layers}"
409+
assert len(attrs) == self.num_layers, (
410+
f"length of attrs is {len(attrs)} is not equal to self.num_layers {self.num_layers}"
411+
)
412412
return attrs[idx]
413413
return attrs
414414

test/ir/inference/program_config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def __init__(
6666
self.dtype = self.data.dtype
6767
self.shape = self.data.shape
6868
else:
69-
assert (
70-
shape is not None
71-
), "While data_gen is not defined, shape must not be None"
69+
assert shape is not None, (
70+
"While data_gen is not defined, shape must not be None"
71+
)
7272
self.data = np.random.normal(0.0, 1.0, shape).astype(np.float32)
7373
self.shape = shape
7474
self.dtype = self.data.dtype
@@ -291,9 +291,9 @@ def __repr__(self):
291291
return log_str
292292

293293
def set_input_type(self, _type: np.dtype) -> None:
294-
assert (
295-
_type in self.supported_cast_type or _type is None
296-
), "PaddleTRT only supports FP32 / FP16 IO"
294+
assert _type in self.supported_cast_type or _type is None, (
295+
"PaddleTRT only supports FP32 / FP16 IO"
296+
)
297297

298298
ver = paddle.inference.get_trt_compile_version()
299299
trt_version = ver[0] * 1000 + ver[1] * 100 + ver[2] * 10
@@ -629,9 +629,9 @@ def create_quant_model(
629629

630630
def _get_op_output_var_names(op):
631631
""" """
632-
assert isinstance(
633-
op, (IrNode, Operator)
634-
), "The input op should be IrNode or Operator."
632+
assert isinstance(op, (IrNode, Operator)), (
633+
"The input op should be IrNode or Operator."
634+
)
635635
var_names = []
636636
op_name = op.name() if isinstance(op, IrNode) else op.type
637637
if op_name not in op_real_in_out_name:

test/ir/inference/test_trt_convert_isnan_v2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def generate_input1(dims):
9191

9292
yield program_config
9393

94-
def sample_predictor_configs(self, program_config) -> Generator[
94+
def sample_predictor_configs(
95+
self, program_config
96+
) -> Generator[
9597
tuple[
9698
paddle_infer.Config, tuple[int, int], tuple[float, float] | float
9799
],

test/ir/inference/test_trt_explicit_quantization_resnet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def net(self, input, class_dim=1000, conv1_name='conv1', fc_name=None):
3333
else self.prefix_name + '_'
3434
)
3535
supported_layers = [34, 50, 101, 152]
36-
assert (
37-
layers in supported_layers
38-
), f"supported layers are {supported_layers} but input layer is {layers}"
36+
assert layers in supported_layers, (
37+
f"supported layers are {supported_layers} but input layer is {layers}"
38+
)
3939

4040
if layers == 34 or layers == 50:
4141
depth = [3, 4, 6, 3]

test/ir/pir/cinn/performance/test_cinn_large_shape_reduce.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
4141
if to_static:
4242
paddle.base.core._set_prim_all_enabled(with_prim)
4343
if with_cinn:
44-
assert (
45-
with_prim
46-
), "with_cinn=True but with_prim=False is unsupported"
44+
assert with_prim, (
45+
"with_cinn=True but with_prim=False is unsupported"
46+
)
4747
net = paddle.jit.to_static(net, backend="CINN", full_graph=True)
4848
else:
4949
net = paddle.jit.to_static(net, backend=None, full_graph=True)

test/ir/pir/cinn/symbolic/test_sub_graph_batch_norm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def train(self, to_static, with_prim=False, with_cinn=False):
7878
if to_static:
7979
paddle.base.core._set_prim_all_enabled(with_prim)
8080
if with_cinn:
81-
assert (
82-
with_prim
83-
), "with_cinn=True but with_prim=False is unsupported"
81+
assert with_prim, (
82+
"with_cinn=True but with_prim=False is unsupported"
83+
)
8484
net = paddle.jit.to_static(net, backend="CINN", full_graph=True)
8585
else:
8686
net = paddle.jit.to_static(net, backend=None, full_graph=True)

test/ir/pir/cinn/symbolic/test_sub_graph_chatglm2_0_st.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
223223
if to_static:
224224
paddle.base.core._set_prim_all_enabled(with_prim)
225225
if with_cinn:
226-
assert (
227-
with_prim
228-
), "with_cinn=True but with_prim=False is unsupported"
226+
assert with_prim, (
227+
"with_cinn=True but with_prim=False is unsupported"
228+
)
229229
net = paddle.jit.to_static(net, backend="CINN", full_graph=True)
230230
else:
231231
net = paddle.jit.to_static(net, backend=None, full_graph=True)

0 commit comments

Comments
 (0)