Skip to content

Commit 174fc9a

Browse files
committed
[reconstruct] metric_v2; [bug fix] split batch,init logger [enhancement] generate V3_results.rst
1 parent fd0356c commit 174fc9a

File tree

14 files changed

+305
-314
lines changed

14 files changed

+305
-314
lines changed

docs/mrt/V3_results.rst

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,86 @@ MRT Quantization Results
55

66
.. _mrt_quantization_results:
77

8-
**alexnet**:
9-
Iteration: 312 | evalfunc: top1=55.91% top5=78.75% | quantize: top1=51.54% top5=77.40% | Total Sample: 50080
8+
**alexnet**:Iteration: 312 | evalfunc: top1=55.90% top5=78.74% | quantize: top1=51.44% top5=77.23% | Total Sample: 50080
9+
10+
11+
12+
**vgg19**:Iteration: 781 | evalfunc: top1=74.13% top5=91.77% | quantize: top1=73.29% top5=91.52% | Total Sample: 50048
13+
14+
15+
16+
**densenet161**:Iteration: 312 | evalfunc: top1=77.62% top5=93.82% | quantize: top1=77.26% top5=93.67% | Total Sample: 50080
17+
18+
19+
20+
**mobilenetv2_1.0**:Iteration: 312 | evalfunc: top1=72.05% top5=90.58% | quantize: top1=69.79% top5=89.14% | Total Sample: 50080
21+
22+
23+
24+
**resnet18_v1**:Iteration: 312 | evalfunc: top1=70.96% top5=89.93% | quantize: top1=70.11% top5=89.61% | Total Sample: 50080
25+
26+
27+
28+
**resnet18_v1b_0.89**:Iteration: 312 | evalfunc: top1=67.20% top5=87.45% | quantize: top1=63.79% top5=85.62% | Total Sample: 50080
29+
30+
31+
32+
**resnet50_v1**:Iteration: 312 | evalfunc: top1=77.39% top5=93.59% | quantize: top1=76.45% top5=93.29% | Total Sample: 50080
33+
34+
35+
36+
**resnet50_v2**:Iteration: 312 | evalfunc: top1=77.15% top5=93.44% | quantize: top1=74.15% top5=91.74% | Total Sample: 50080
37+
38+
39+
40+
**squeezenet1.0**:Iteration: 312 | evalfunc: top1=57.19% top5=80.04% | quantize: top1=54.91% top5=78.64% | Total Sample: 50080
41+
42+
43+
44+
**mobilenet1_0**:Iteration: 312 | evalfunc: top1=70.77% top5=89.97% | quantize: top1=66.11% top5=87.35% | Total Sample: 50080
45+
46+
47+
48+
**shufflenet_v1**:Iteration: 312 | evalfunc: top1=63.48% top5=85.12% | quantize: top1=60.45% top5=82.95% | Total Sample: 50080
49+
50+
51+
52+
**tf_inception_v3**:Iteration: 312 | evalfunc: top1=45.16% top5=67.93% | quantize: top1=49.62% top5=74.71% | Total Sample: 50080
53+
54+
55+
56+
**cifar_resnet20_v1**:Iteration: 62 | evalfunc: top1=92.88% top5=99.78% | quantize: top1=92.82% top5=99.75% | Total Sample: 10080
57+
58+
59+
60+
**mnist**:Iteration: 62 | evalfunc: top1=99.00% top5=100.00% | quantize: top1=98.96% top5=100.00% | Total Sample: 10080
61+
62+
63+
64+
**qd10_resnetv1_20**:Iteration: 1732 | evalfunc: top1=85.72% top5=98.71% | quantize: top1=85.73% top5=98.70% | Total Sample: 277280
65+
66+
67+
68+
**quickdraw**:Iteration: 1732 | evalfunc: top1=81.66% top5=98.22% | quantize: top1=81.57% top5=98.20% | Total Sample: 277280
69+
70+
71+
72+
**ssd**:Iteration: 76 | evalfunc: 80.30% | quantize: 80.05% | Total Sample: 4928
73+
74+
75+
76+
**ssd_512_mobilenet1.0_voc**:Iteration: 308 | evalfunc: 75.51% | quantize: 71.26% | Total Sample: 4944
77+
78+
79+
**yolo3_darknet53_voc**:Iteration: 102 | evalfunc: 81.51% | quantize: 81.51% | Total Sample: 4944
80+
81+
82+
83+
**yolo3_mobilenet1.0_voc**:Iteration: 76 | evalfunc: 76.03% | quantize: 71.56% | Total Sample: 4928
84+
85+
86+
87+
**trec**:Iteration: 3 | evalfunc: 98.19% | quantize: 97.99% | Total Sample: 640
88+
1089

1190

python/mrt/V3/evaluate.py

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
MRT_CFG.EVALUATE.DEVICE_IDS = None
3434
MRT_CFG.EVALUATE.ITER_NUM = 10
3535

36+
def forward(net, data, ctx, baxis, olen):
37+
#TODO(ryt.dev) documentation
38+
""" Multiple xpu run support.
39+
"""
40+
data = gluon.utils.split_and_load(
41+
data, ctx_list=ctx, batch_axis=baxis, even_split=False)
42+
outs = [net(d) for d in data]
43+
if olen == 1:
44+
outs = nd.concatenate(outs)
45+
else:
46+
outs = [nd.concatenate([outs[i][j] \
47+
for i in range(len(outs))]) for j in range(olen)]
48+
return outs
49+
3650
def get_evaluation_info(cm_cfg, pass_cfg, logger=None):
3751
model_dir = cm_cfg.MODEL_DIR
3852
model_name = cm_cfg.MODEL_NAME
@@ -60,7 +74,6 @@ def get_evaluation_info(cm_cfg, pass_cfg, logger=None):
6074
# forward function for the orginal model
6175
model_prefix_fixed = model_prefix + ".fixed"
6276
omodel = Model.load(*load_fname(model_prefix_fixed))
63-
#TODO(ryt.dev) [bug fix] load revised model
6477
graph = omodel.to_graph(ctx=ctx)
6578
dataset_name = conf_map["dataset_name"]
6679
input_shape = conf_map["input_shape"]
@@ -70,30 +83,26 @@ def get_evaluation_info(cm_cfg, pass_cfg, logger=None):
7083
baxis = get_batch_axis(input_shape)
7184
olen = len(omodel.symbol)
7285

73-
def forward(net, data, ctx):
74-
""" Multiple xpu run support.
75-
"""
76-
data = gluon.utils.split_and_load(
77-
data, ctx_list=ctx, batch_axis=baxis, even_split=False)
78-
outs = [net(d) for d in data]
79-
if olen == 1:
80-
outs = nd.concatenate(outs)
81-
else:
82-
outs = [nd.concatenate([outs[i][j] \
83-
for i in range(len(outs))]) for j in range(olen)]
84-
return outs
86+
# def forward(net, data, ctx):
87+
# """ Multiple xpu run support.
88+
# """
89+
# data = gluon.utils.split_and_load(
90+
# data, ctx_list=ctx, batch_axis=baxis, even_split=False)
91+
# outs = [net(d) for d in data]
92+
# if olen == 1:
93+
# outs = nd.concatenate(outs)
94+
# else:
95+
# outs = [nd.concatenate([outs[i][j] \
96+
# for i in range(len(outs))]) for j in range(olen)]
97+
# return outs
8598

8699
def evalfunc(data, label):
87-
outs = forward(graph, data, ctx=ctx)
100+
# outs = forward(graph, data, ctx=ctx)
101+
outs = forward(graph, data, ctx, baxis, olen)
88102
acc = dataset.validate(metric, outs, label)
89103
return acc
90104

91105
# forward function for the quantized model
92-
# TODO(ryt.dev) [bug fix] remove split batch check
93-
num_xpus = len(ctx)
94-
if batch % num_xpus:
95-
raise RuntimeError("Batch must be divisible by the number of xpus")
96-
split_batch = batch // num_xpus
97106
if conf_map.get("split_keys", "") != "":
98107
sym_all_file, prm_all_file, ext_all_file = load_fname(
99108
model_prefix, suffix="all.quantize", with_ext=True)
@@ -110,14 +119,13 @@ def evalfunc(data, label):
110119
oscales = mrt.get_output_scales()
111120
inputs_ext = mrt.get_inputs_ext()
112121
qmodel = mrt.current_model
113-
rqmodel = reduce_graph(qmodel, {
114-
'data': set_batch(input_shape, split_batch)})
115-
qgraph = rqmodel.to_graph(ctx=ctx)
122+
qgraph = qmodel.to_graph(ctx=ctx)
116123
qmetric = dataset.metrics()
117124

118125
def quantize(data, label):
119126
data = sim.load_real_data(data, 'data', inputs_ext)
120-
outs = forward(qgraph, data, ctx)
127+
# outs = forward(qgraph, data, ctx)
128+
outs = forward(qgraph, data, ctx, baxis, olen)
121129
outs = outs / oscales[0] if olen == 1 \
122130
else [(t / oscales[i]) for i, t in enumerate(outs)]
123131
acc = dataset.validate(qmetric, outs, label)
@@ -143,20 +151,6 @@ def evaluate(cm_cfg, pass_cfg, logger=None):
143151
else:
144152
logger.info("evaluatation stage skipped")
145153

146-
def forward(net, data, ctx, baxis, olen):
147-
#TODO(ryt.dev) documentation
148-
""" Multiple xpu run support.
149-
"""
150-
data = gluon.utils.split_and_load(
151-
data, ctx_list=ctx, batch_axis=baxis, even_split=False)
152-
outs = [net(d) for d in data]
153-
if olen == 1:
154-
outs = nd.concatenate(outs)
155-
else:
156-
outs = [nd.concatenate([outs[i][j] \
157-
for i in range(len(outs))]) for j in range(olen)]
158-
return outs
159-
160154
def get_ctx_eval(ctx):
161155
#TODO(ryt.dev) documentation
162156
if isinstance(ctx, mx.Context):

python/mrt/V3/execute.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from mrt.V3.quantize import quantize
1313
from mrt.V3.evaluate import evaluate
1414
from mrt.V3.mrt_compile import mrt_compile
15+
from mrt.V3.utils import get_logger
1516

1617
thismodule = sys.modules[__name__]
1718

@@ -68,6 +69,7 @@ def run(cfg, logger=None):
6869
Console logger.
6970
"""
7071
pass_name = cfg.COMMON.PASS_NAME
72+
logger = get_logger(cfg.COMMON.VERBOSITY)
7173
if pass_name == "all":
7274
yaml_main(cfg, logger=logger)
7375
else:

python/mrt/dataset.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ def data_loader():
611611
yield nd.transpose(nd.array(data)), nd.array(label)
612612
data, label = [], []
613613
yield nd.transpose(nd.array(data)), nd.array(label)
614-
raise RuntimeError("Data loader have been the end")
615614

616615
self.data = data_loader()
617616

python/mrt/transformer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def to_cvm(self, model_name, datadir="/data/stdout",
109109
device_ids=device_ids)
110110

111111
def fix_original_model(self, model_dir, model_name):
112+
# unify graph names and check graph params
112113
_sym, _prm = tpass.unify_name_json(self.symbol, self.params)
113114
self.symbol, self.params = tpass.remove_params_prefix(_sym, _prm)
114115
model_prefix = path.join(model_dir, model_name+".fixed")
@@ -122,11 +123,6 @@ def init(model, input_shape=None):
122123
logger.info("Model initializing...")
123124

124125
_sym, _prm = model.symbol, model.params
125-
126-
# unify graph names and check graph params
127-
# TODO(ryt.dev) [bug fix, reconstruct] write fixed model in conf_map, move to fix_orginal_model
128-
# _sym, _prm = fix_original_model(sym, parmas)
129-
130126
tpass.name_duplicate_check(_sym, _prm)
131127

132128
if isinstance(input_shape, dict):

tests/mrt/model_zoo/alexnet.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ CALIBRATE:
88
LAMBD: 16
99
DATASET_NAME: imagenet
1010
DEVICE_TYPE: gpu
11-
DEVICE_IDS: [2]
11+
DEVICE_IDS: [0]
1212
QUANTIZE:
1313
INPUT_PRECISION: 8
1414
OUTPUT_PRECISION: 8
1515
DEVICE_TYPE: gpu
16-
DEVICE_IDS: [2]
16+
DEVICE_IDS: [0]
1717
EVALUATE:
1818
BATCH: 160
1919
DEVICE_TYPE: gpu

tests/mrt/model_zoo/ssd_512_mobilenet1.0_voc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ QUANTIZE:
4242
["ssd0_slice_axis43", "ssd0_normalizedboxcenterdecoder0_concat0"],
4343
]
4444
EVALUATE:
45-
BATCH: 64
45+
BATCH: 16
4646
DEVICE_TYPE: gpu
4747
DEVICE_IDS: [0]
4848
ITER_NUM: 2000

tests/mrt/model_zoo/yolo3_mobilenet1.0_voc.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ CALIBRATE:
1616
NUM_CALIB: 1
1717
DATASET_NAME: voc
1818
DEVICE_TYPE: gpu
19-
DEVICE_IDS: [2]
19+
DEVICE_IDS: [0]
2020
QUANTIZE:
2121
OUTPUT_PRECISION: 30
2222
DEVICE_TYPE: gpu
23-
DEVICE_IDS: [2]
23+
DEVICE_IDS: [0]
2424
THRESHOLDS: [
2525
["mrt_rewrite_mobilenet0_conv23_weight_0", 11],
2626
["yolov30_yolooutputv30_tile0", 416],
@@ -43,5 +43,5 @@ QUANTIZE:
4343
EVALUATE:
4444
BATCH: 64
4545
DEVICE_TYPE: gpu
46-
DEVICE_IDS: [2]
46+
DEVICE_IDS: [0]
4747
ITER_NUM: 2000

0 commit comments

Comments
 (0)