Skip to content

Commit 30fc5b3

Browse files
committed
add system test
1 parent 6e761f8 commit 30fc5b3

23 files changed

Lines changed: 498 additions & 16 deletions

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ venv/
2626
python/jittor.egg-info
2727
dist/
2828
!doc/source/*
29+
__data__

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exclude __data__
2+
exclude __pycache__

extern/cuda/cub/ops/cub_where_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "cub_where_op.h"
1111
#ifdef JIT_cuda
1212
#include "executor.h"
13+
#include <cuda_runtime.h>
14+
#include "helper_cuda.h"
1315
#include <assert.h>
1416
#include <executor.h>
1517
#include <cub/cub.cuh>

extern/cuda/cutt/ops/cutt_transpose_op.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "cutt.h"
1010
#include "cutt_warper.h"
1111
#include "misc/stack_vector.h"
12+
#include "helper_cuda.h"
1213

1314
namespace jittor {
1415

python/jittor/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This file is subject to the terms and conditions defined in
88
# file 'LICENSE.txt', which is part of this source code package.
99
# ***************************************************************
10-
__version__ = '1.2.1.3'
10+
__version__ = '1.2.2.0'
1111
from . import lock
1212
with lock.lock_scope():
1313
ori_int = int
@@ -92,6 +92,7 @@ class log_capture_scope(_call_no_record_scope):
9292
print(logs)
9393
"""
9494
def __init__(self, **jt_flags):
95+
jt_flags["use_parallel_op_compiler"] = 0
9596
self.fs = flag_scope(**jt_flags)
9697

9798
def __enter__(self):

python/jittor/compile_extern.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def setup_mkl():
7878

7979

8080
def install_cub(root_folder):
81-
url = "https://github.com/NVIDIA/cub/archive/1.11.0-rc1.tar.gz"
82-
filename = "cub-1.11.0-rc1.tgz"
83-
md5 = "f395687060bed7eaeb5fa8a689276ede"
81+
url = "https://github.com/NVIDIA/cub/archive/1.11.0.tar.gz"
82+
filename = "cub-1.11.0.tgz"
83+
md5 = "97196a885598e40592100e1caaf3d5ea"
8484
fullname = os.path.join(root_folder, filename)
8585
dirname = os.path.join(root_folder, filename.replace(".tgz",""))
8686

python/jittor/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __iter__(x):
3333
return result.__iter__()
3434
jt.Var.__iter__ = __iter__
3535

36-
def all(x,dim):
36+
def all(x, dim=[]):
3737
return x.all_(dim).bool()
3838
jt.Var.all = all
3939

python/jittor/models/res2net.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ def execute(self, input):
175175
x = self.layer4(x)
176176
return x, low_level_feat
177177

178-
def res2net50(output_stride):
178+
def res2net50(output_stride=16):
179179
model = Res2Net(Bottle2neck, [3,4,6,3], output_stride)
180180
return model
181181

182-
def res2net101(output_stride):
182+
def res2net101(output_stride=16):
183183
model = Res2Net(Bottle2neck, [3,4,23,3], output_stride)
184184
return model

python/jittor/test/perf/perf.py

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
import sys, os
2+
3+
suffix = ""
4+
5+
import jittor as jt
6+
import time
7+
from pathlib import Path
8+
home_path = str(Path.home())
9+
perf_path = os.path.join(home_path, ".cache", "jittor_perf")
10+
11+
def main():
12+
os.makedirs(perf_path+"/src/jittor", exist_ok=True)
13+
os.makedirs(perf_path+"/src/jittor_utils", exist_ok=True)
14+
os.system(f"cp -rL {jt.flags.jittor_path} {perf_path+'/src/'}")
15+
os.system(f"cp -rL {jt.flags.jittor_path}/../jittor_utils {perf_path+'/src/'}")
16+
use_torch_1_4 = os.environ.get("use_torch_1_4", "0") == "1"
17+
dockerfile_src = r"""
18+
FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
19+
20+
RUN echo \
21+
"deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse\n\
22+
deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse\n\
23+
deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse\n\
24+
deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse" > /etc/apt/sources.list
25+
26+
# RUN rm -rf /var/lib/apt/lists/*
27+
RUN apt update || true
28+
29+
RUN apt install wget \
30+
python3.7 python3.7-dev \
31+
g++ build-essential -y
32+
33+
WORKDIR /usr/src
34+
35+
RUN apt download python3-distutils && dpkg-deb -x ./python3-distutils* / \
36+
&& wget -O - https://bootstrap.pypa.io/get-pip.py | python3.7
37+
38+
# change tsinghua mirror
39+
RUN pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
40+
41+
RUN pip3 install \
42+
pybind11 \
43+
numpy \
44+
tqdm \
45+
pillow \
46+
astunparse
47+
48+
RUN pip3 install torch torchvision
49+
"""
50+
global suffix
51+
if use_torch_1_4:
52+
suffix = "_1_4"
53+
dockerfile_src = dockerfile_src.replace("torch ", "torch==1.4.0 ")
54+
dockerfile_src = dockerfile_src.replace("torchvision", "torchvision==0.5.0")
55+
with open("/tmp/perf_dockerfile", 'w') as f:
56+
f.write(dockerfile_src)
57+
assert os.system("sudo nvidia-smi -lgc 1500") == 0
58+
assert os.system(f"sudo docker build --tag jittor/jittor-perf{suffix} -f /tmp/perf_dockerfile .") == 0
59+
# run once for compile source
60+
jt_fps = test_main("jittor", "resnet50", 1)
61+
62+
logs = ""
63+
# resnext50_32x4d with bs=8 cannot pass this test
64+
#### inference test
65+
for model_name in ["resnet50", "wide_resnet50_2", # "resnext50_32x4d",
66+
"resnet152", "wide_resnet101_2", "resnext101_32x8d",
67+
"alexnet", "vgg11", "squeezenet1_1", "mobilenet_v2",
68+
"densenet121", "densenet169", "densenet201",
69+
"res2net50", "res2net101"]:
70+
for bs in [1, 2, 4, 8, 16, 32, 64, 128]:
71+
jt_fps = test_main("jittor", model_name, bs)
72+
logs += f"jittor-{model_name}-{bs} {jt_fps}\n"
73+
tc_fps = test_main("torch", model_name, bs)
74+
logs += f"torch-{model_name}-{bs} {tc_fps}\n"
75+
logs += f"compare-{model_name}-{bs} {jt_fps/tc_fps}\n"
76+
print(logs)
77+
#### train test
78+
for model_name in ["train_resnet50", "train_resnet101"
79+
]:
80+
for bs in [1, 2, 4, 8, 16, 32, 64, 128]:
81+
jt_fps = test_main("jittor", model_name, bs)
82+
logs += f"jittor-{model_name}-{bs} {jt_fps}\n"
83+
tc_fps = test_main("torch", model_name, bs)
84+
logs += f"torch-{model_name}-{bs} {tc_fps}\n"
85+
logs += f"compare-{model_name}-{bs} {jt_fps/tc_fps}\n"
86+
print(logs)
87+
with open(f"{perf_path}/jittor-perf{suffix}-latest.txt", "w") as f:
88+
f.write(logs)
89+
from datetime import datetime
90+
with open(f"{perf_path}/jittor-perf{suffix}-{datetime.now()}.txt", "w") as f:
91+
f.write(logs)
92+
93+
def test_main(name, model_name, bs):
94+
cmd = f"sudo docker run --gpus all --rm -v {perf_path}:/root/.cache/jittor --network host jittor/jittor-perf{suffix} bash -c 'PYTHONPATH=/root/.cache/jittor/src python3.7 /root/.cache/jittor/src/jittor/test/perf/perf.py {name} {model_name} {bs}'"
95+
fps = -1
96+
try:
97+
print("run cmd:", cmd)
98+
if os.system(cmd) == 0:
99+
with open(f"{perf_path}/{name}-{model_name}-{bs}.txt", 'r') as f:
100+
fps = float(f.read().split()[3])
101+
except:
102+
pass
103+
return fps
104+
105+
def time_iter(duration=2, min_iter=5):
106+
start = time.time()
107+
for i in range(10000000):
108+
yield i
109+
end = time.time()
110+
if end-start>duration and i>=min_iter:
111+
return
112+
113+
def test(name, model_name, bs):
114+
print("hello", name, model_name, bs)
115+
import numpy as np
116+
import time
117+
is_train = False
118+
_model_name = model_name
119+
if model_name.startswith("train_"):
120+
is_train = True
121+
model_name = model_name[6:]
122+
if name == "torch":
123+
import torch
124+
import torchvision.models as tcmodels
125+
from torch import optim
126+
from torch import nn
127+
torch.backends.cudnn.deterministic = False
128+
torch.backends.cudnn.benchmark = True
129+
model = tcmodels.__dict__[model_name]()
130+
model = model.cuda()
131+
else:
132+
import jittor as jt
133+
from jittor import optim
134+
from jittor import nn
135+
jt.flags.use_cuda = 1
136+
jt.cudnn.set_algorithm_cache_size(10000)
137+
import jittor.models as jtmodels
138+
model = jtmodels.__dict__[model_name]()
139+
if (model == "resnet152" or model == "resnet101") and bs == 128 and is_train:
140+
jt.cudnn.set_max_workspace_ratio(0.05)
141+
if is_train:
142+
model.train()
143+
else:
144+
model.eval()
145+
img_size = 224
146+
if model_name == "inception_v3":
147+
img_size = 300
148+
test_img = np.random.random((bs, 3, img_size, img_size)).astype("float32")
149+
if is_train:
150+
label = (np.random.random((bs,)) * 1000).astype("int32")
151+
if name == "torch":
152+
test_img = torch.Tensor(test_img).cuda()
153+
if is_train:
154+
label = torch.LongTensor(label).cuda()
155+
opt = optim.SGD(model.parameters(), 0.001)
156+
sync = lambda: torch.cuda.synchronize()
157+
jt = torch
158+
else:
159+
test_img = jt.array(test_img).stop_grad()
160+
if is_train:
161+
label = jt.array(label).stop_grad()
162+
opt = optim.SGD(model.parameters(), 0.001)
163+
sync = lambda: jt.sync_all(True)
164+
165+
sync()
166+
use_profiler = os.environ.get("use_profiler", "0") == "1"
167+
if hasattr(jt, "nograd"):
168+
ng = jt.no_grad()
169+
ng.__enter__()
170+
def iter():
171+
x = model(test_img)
172+
if isinstance(x, tuple):
173+
x = x[0]
174+
if is_train:
175+
loss = nn.CrossEntropyLoss()(x, label)
176+
if name == "jittor":
177+
opt.step(loss)
178+
else:
179+
opt.zero_grad()
180+
loss.backward()
181+
opt.step()
182+
else:
183+
x.sync()
184+
sync()
185+
for i in time_iter():
186+
iter()
187+
sync()
188+
for i in time_iter():
189+
iter()
190+
sync()
191+
if use_profiler:
192+
if name == "torch":
193+
prof = torch.autograd.profiler.profile(use_cuda=True)
194+
else:
195+
prof = jt.profile_scope()
196+
prof.__enter__()
197+
if name == "jittor":
198+
if hasattr(jt.flags, "use_parallel_op_compiler"):
199+
jt.flags.use_parallel_op_compiler = 0
200+
start = time.time()
201+
for i in time_iter(10):
202+
iter()
203+
sync()
204+
end = time.time()
205+
if use_profiler:
206+
prof.__exit__(None,None,None)
207+
if name == "torch":
208+
print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=30))
209+
total_iter = i+1
210+
print("duration:", end-start, "FPS:", total_iter*bs/(end-start))
211+
fpath = f"{home_path}/.cache/jittor/{name}-{_model_name}-{bs}.txt"
212+
with open(fpath, 'w') as f:
213+
f.write(f"duration: {end-start} FPS: {total_iter*bs/(end-start)}")
214+
os.chmod(fpath, 0x666)
215+
216+
if len(sys.argv) <= 1:
217+
main()
218+
else:
219+
name, model, bs = sys.argv[1:]
220+
bs = int(bs)
221+
test(name, model, bs)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bash python/jittor/test/system/test_cuda10.0_ubuntu16.04.sh
2+
bash python/jittor/test/system/test_cuda10.0_ubuntu18.04.sh
3+
bash python/jittor/test/system/test_cuda11.1_ubuntu16.04.sh
4+
bash python/jittor/test/system/test_cuda11.1_ubuntu18.04.sh
5+
bash python/jittor/test/system/test_cuda11.1_ubuntu20.04.sh
6+
bash python/jittor/test/system/test_nocuda_ubuntu18.04.sh

0 commit comments

Comments
 (0)