Skip to content

Commit 190d939

Browse files
align the lint check
1 parent dbf0a9c commit 190d939

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

test/microbench/adaptive_avg_pool2d.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import time
22
import argparse
3+
34
import torch
45
from torch.profiler import profile, ProfilerActivity
56

@@ -48,21 +49,22 @@ def Adaptive_AVGPool2d(shape, dtype, channels_last, backward, device):
4849
def run_profile(shape, dtype, channels_last, backward, device, num_iter):
4950
with profile(
5051
activities=[ProfilerActivity.CPU,
51-
ProfilerActivity.XPU if device == 'xpu' else ProfilerActivity.CUDA],
52+
ProfilerActivity.XPU if device == "xpu" else ProfilerActivity.CUDA,
53+
],
5254
record_shapes=True,
5355
) as prof:
5456
for i in range(num_iter):
5557
Adaptive_AVGPool2d(shape, dtype, channels_last, backward, device)
56-
print(prof.key_averages().table(sort_by="{}_time_total".format(device)))
58+
print(prof.key_averages().table(sort_by=f"{device}_time_total"))
5759

5860
def run_e2e(shape, dtype, channels_last, backward, device, num_iter):
59-
if device in ['xpu', 'cuda']:
60-
torch.xpu.synchronize() if device == 'xpu' else torch.cuda.synchronize()
61+
if device in ["xpu", "cuda"]:
62+
torch.xpu.synchronize() if device == "xpu" else torch.cuda.synchronize()
6163
t1 = time.time()
6264
for i in range(num_iter):
6365
Adaptive_AVGPool2d(shape, dtype, channels_last, backward, device)
64-
if device in ['xpu', 'cuda']:
65-
torch.xpu.synchronize() if device == 'xpu' else torch.cuda.synchronize()
66+
if device in ["xpu", "cuda"]:
67+
torch.xpu.synchronize() if device == "xpu" else torch.cuda.synchronize()
6668
t2 = time.time()
6769
e2e_time = (t2 - t1) / num_iter
6870
print("E2E total time:", f"{float(e2e_time):.20f}")
@@ -88,22 +90,39 @@ def benchmark(args):
8890
backward,
8991
)
9092
if not args.e2e_only:
91-
run_profile(shape, dtype, channels_last, backward, args.device, args.num_iter)
93+
run_profile(
94+
shape,
95+
dtype,
96+
channels_last,
97+
backward,
98+
args.device,
99+
args.num_iter,
100+
)
92101

93102
if not args.profile_only:
94-
run_e2e(shape, dtype, channels_last, backward, args.device, args.num_iter)
103+
run_e2e(
104+
shape,
105+
dtype,
106+
channels_last,
107+
backward,
108+
args.device,
109+
args.num_iter,
110+
)
95111

96112
def parse_args():
97-
parser = argparse.ArgumentParser(description='OP Benchmark')
98-
parser.add_argument('--device', type=str, default='xpu',
99-
help='Device to run on (e.g., "cpu", "cuda", "xpu")')
113+
parser = argparse.ArgumentParser(description="OP Benchmark")
114+
parser.add_argument(
115+
"--device",
116+
type=str,
117+
default='xpu',
118+
help='Device to run on (e.g., "cpu", "cuda", "xpu")'
119+
)
100120
group = parser.add_mutually_exclusive_group()
101-
group.add_argument('--profile-only', action='store_true',
102-
help='Only Run profile timing')
103-
group.add_argument('--e2e-only', action='store_true',
104-
help='Only Run E2E timing')
105-
parser.add_argument('--num-iter', type=int, default=20,
106-
help='Number of iterations')
121+
group.add_argument(
122+
"--profile-only", action="store_true", help="Only Run profile timing"
123+
)
124+
group.add_argument("--e2e-only", action="store_true", help="Only Run E2E timing")
125+
parser.add_argument("--num-iter", type=int, default=20, help="Number of iterations")
107126
return parser.parse_args()
108127

109128
if __name__ == "__main__":

test/microbench/indexing.index_fill.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def benchmark(args):
6969

7070
def parse_args():
7171
parser = argparse.ArgumentParser(description='OP Benchmark')
72-
parser.add_argument('--device', type=str, default='xpu',
72+
parser.add_argument('--device', type=str, default='xpu',
7373
help='Device to run on (e.g., "cpu", "cuda", "xpu")')
7474
group = parser.add_mutually_exclusive_group()
75-
group.add_argument('--profile-only', action='store_true',
75+
group.add_argument('--profile-only', action='store_true',
7676
help='Only Run profile timing')
77-
group.add_argument('--e2e-only', action='store_true',
77+
group.add_argument('--e2e-only', action='store_true',
7878
help='Only Run E2E timing')
79-
parser.add_argument('--num-iter', type=int, default=20,
79+
parser.add_argument('--num-iter', type=int, default=20,
8080
help='Number of iterations')
8181
return parser.parse_args()
8282

0 commit comments

Comments
 (0)