Caffe2 - Python API
A deep learning, cross platform ML framework
convnet_benchmarks.py
1 ## @package convnet_benchmarks
2 # Module caffe2.python.convnet_benchmarks
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
7 """
8 Benchmark for common convnets.
9 
10 Speed on Titan X, with 10 warmup steps and 10 main steps and with different
11 versions of cudnn, are as follows (time reported below is per-batch time,
12 forward / forward+backward):
13 
14  CuDNN V3 CuDNN v4
15 AlexNet 32.5 / 108.0 27.4 / 90.1
16 OverFeat 113.0 / 342.3 91.7 / 276.5
17 Inception 134.5 / 485.8 125.7 / 450.6
18 VGG (batch 64) 200.8 / 650.0 164.1 / 551.7
19 
20 Speed on Inception with varied batch sizes and CuDNN v4 is as follows:
21 
22 Batch Size Speed per batch Speed per image
23  16 22.8 / 72.7 1.43 / 4.54
24  32 38.0 / 127.5 1.19 / 3.98
25  64 67.2 / 233.6 1.05 / 3.65
26 128 125.7 / 450.6 0.98 / 3.52
27 
28 Speed on Tesla M40, which 10 warmup steps and 10 main steps and with cudnn
29 v4, is as follows:
30 
31 AlexNet 68.4 / 218.1
32 OverFeat 210.5 / 630.3
33 Inception 300.2 / 1122.2
34 VGG (batch 64) 405.8 / 1327.7
35 
36 (Note that these numbers involve a "full" backprop, i.e. the gradient
37 with respect to the input image is also computed.)
38 
39 To get the numbers, simply run:
40 
41 for MODEL in AlexNet OverFeat Inception; do
42  PYTHONPATH=../gen:$PYTHONPATH python convnet_benchmarks.py \
43  --batch_size 128 --model $MODEL --forward_only True
44 done
45 for MODEL in AlexNet OverFeat Inception; do
46  PYTHONPATH=../gen:$PYTHONPATH python convnet_benchmarks.py \
47  --batch_size 128 --model $MODEL
48 done
49 PYTHONPATH=../gen:$PYTHONPATH python convnet_benchmarks.py \
50  --batch_size 64 --model VGGA --forward_only True
51 PYTHONPATH=../gen:$PYTHONPATH python convnet_benchmarks.py \
52  --batch_size 64 --model VGGA
53 
54 for BS in 16 32 64 128; do
55  PYTHONPATH=../gen:$PYTHONPATH python convnet_benchmarks.py \
56  --batch_size $BS --model Inception --forward_only True
57  PYTHONPATH=../gen:$PYTHONPATH python convnet_benchmarks.py \
58  --batch_size $BS --model Inception
59 done
60 
61 Note that VGG needs to be run at batch 64 due to memory limit on the backward
62 pass.
63 """
64 
65 import argparse
66 
67 from caffe2.python import brew, cnn, workspace
68 from caffe2.python.model_helper import ModelHelper
69 
70 from caffe2.python.models import resnet
71 import numpy as np
72 
73 def MLP(order, cudnn_ws, mkl):
74  model = ModelHelper(name="benchmark")
75  d = 256
76  depth = 20
77  width = 3
78  for i in range(depth):
79  for j in range(width):
80  current = "fc_{}_{}".format(i, j) if i > 0 else "data"
81  next_ = "fc_{}_{}".format(i + 1, j)
82  brew.fc(
83  model,
84  current, next_,
85  dim_in=d, dim_out=d,
86  weight_init=('XavierFill', {}),
87  bias_init=('XavierFill', {}))
88 
89  brew.sum(model, ["fc_{}_{}".format(depth, j) for j in range(width)], ["sum"])
90  brew.fc(model, "sum", "last",
91  dim_in=d, dim_out=1000,
92  weight_init=('XavierFill', {}),
93  bias_init=('XavierFill', {}))
94  xent = model.LabelCrossEntropy(["last", "label"], "xent")
95  if not mkl:
96  model.AveragedLoss(xent, "loss")
97  return model, d
98 
99 
100 def ResNet50(order, cudnn_ws, mkl):
101  my_arg_scope = {'order': order, 'use_cudnn': True,
102  'cudnn_exhaustive_search': True,
103  'ws_nbytes_limit': str(cudnn_ws)}
104  model = ModelHelper(name="alexnet", arg_scope=my_arg_scope)
105  resnet.create_resnet50(model, "data", 3, 1000, is_test=True,
106  final_avg_kernel=14)
107  return model, 448
108 
109 def AlexNet(order, cudnn_ws, mkl):
110  my_arg_scope = {'order': order, 'use_cudnn': True,
111  'cudnn_exhaustive_search': True,
112  'ws_nbytes_limit': str(cudnn_ws)}
113  model = ModelHelper(name="alexnet", arg_scope=my_arg_scope)
114  conv1 = brew.conv(
115  model,
116  "data",
117  "conv1",
118  3,
119  64,
120  11,
121  ('XavierFill', {}),
122  ('ConstantFill', {}),
123  stride=4,
124  pad=2
125  )
126  relu1 = brew.relu(model, conv1, "conv1")
127  pool1 = brew.max_pool(model, relu1, "pool1", kernel=3, stride=2)
128  conv2 = brew.conv(
129  model,
130  pool1,
131  "conv2",
132  64,
133  192,
134  5,
135  ('XavierFill', {}),
136  ('ConstantFill', {}),
137  pad=2
138  )
139  relu2 = brew.relu(model, conv2, "conv2")
140  pool2 = brew.max_pool(model, relu2, "pool2", kernel=3, stride=2)
141  conv3 = brew.conv(
142  model,
143  pool2,
144  "conv3",
145  192,
146  384,
147  3,
148  ('XavierFill', {}),
149  ('ConstantFill', {}),
150  pad=1
151  )
152  relu3 = brew.relu(model, conv3, "conv3")
153  conv4 = brew.conv(
154  model,
155  relu3,
156  "conv4",
157  384,
158  256,
159  3,
160  ('XavierFill', {}),
161  ('ConstantFill', {}),
162  pad=1
163  )
164  relu4 = brew.relu(model, conv4, "conv4")
165  conv5 = brew.conv(
166  model,
167  relu4,
168  "conv5",
169  256,
170  256,
171  3,
172  ('XavierFill', {}),
173  ('ConstantFill', {}),
174  pad=1
175  )
176  relu5 = brew.relu(model, conv5, "conv5")
177  pool5 = brew.max_pool(model, relu5, "pool5", kernel=3, stride=2)
178  fc6 = brew.fc(
179  model, pool5, "fc6", 256 * 6 * 6, 4096, ('XavierFill', {}),
180  ('ConstantFill', {})
181  )
182  relu6 = brew.relu(model, fc6, "fc6")
183  fc7 = brew.fc(
184  model, relu6, "fc7", 4096, 4096, ('XavierFill', {}), ('ConstantFill', {})
185  )
186  relu7 = brew.relu(model, fc7, "fc7")
187  fc8 = brew.fc(
188  model, relu7, "fc8", 4096, 1000, ('XavierFill', {}), ('ConstantFill', {})
189  )
190  pred = brew.softmax(model, fc8, "pred")
191  xent = model.LabelCrossEntropy([pred, "label"], "xent")
192  if not mkl:
193  loss = model.AveragedLoss(xent, "loss")
194  return model, 224
195 
196 
197 def OverFeat(order, cudnn_ws, mkl):
198  my_arg_scope = {'order': order, 'use_cudnn': True,
199  'cudnn_exhaustive_search': True,
200  'ws_nbytes_limit': str(cudnn_ws)}
201  model = ModelHelper(name='overfeat', arg_scope=my_arg_scope)
202  conv1 = brew.conv(
203  model,
204  "data",
205  "conv1",
206  3,
207  96,
208  11,
209  ('XavierFill', {}),
210  ('ConstantFill', {}),
211  stride=4
212  )
213  relu1 = brew.relu(model, conv1, "conv1")
214  pool1 = brew.max_pool(model, relu1, "pool1", kernel=2, stride=2)
215  conv2 = brew.conv(
216  model, pool1, "conv2", 96, 256, 5, ('XavierFill', {}), ('ConstantFill', {})
217  )
218  relu2 = brew.relu(model, conv2, "conv2")
219  pool2 = brew.max_pool(model, relu2, "pool2", kernel=2, stride=2)
220  conv3 = brew.conv(
221  model,
222  pool2,
223  "conv3",
224  256,
225  512,
226  3,
227  ('XavierFill', {}),
228  ('ConstantFill', {}),
229  pad=1
230  )
231  relu3 = brew.relu(model, conv3, "conv3")
232  conv4 = brew.conv(
233  model,
234  relu3,
235  "conv4",
236  512,
237  1024,
238  3,
239  ('XavierFill', {}),
240  ('ConstantFill', {}),
241  pad=1
242  )
243  relu4 = brew.relu(model, conv4, "conv4")
244  conv5 = brew.conv(
245  model,
246  relu4,
247  "conv5",
248  1024,
249  1024,
250  3,
251  ('XavierFill', {}),
252  ('ConstantFill', {}),
253  pad=1
254  )
255  relu5 = brew.relu(model, conv5, "conv5")
256  pool5 = brew.max_pool(model, relu5, "pool5", kernel=2, stride=2)
257  fc6 = brew.fc(
258  model, pool5, "fc6", 1024 * 6 * 6, 3072, ('XavierFill', {}),
259  ('ConstantFill', {})
260  )
261  relu6 = brew.relu(model, fc6, "fc6")
262  fc7 = brew.fc(
263  model, relu6, "fc7", 3072, 4096, ('XavierFill', {}), ('ConstantFill', {})
264  )
265  relu7 = brew.relu(model, fc7, "fc7")
266  fc8 = brew.fc(
267  model, relu7, "fc8", 4096, 1000, ('XavierFill', {}), ('ConstantFill', {})
268  )
269  pred = brew.softmax(model, fc8, "pred")
270  xent = model.LabelCrossEntropy([pred, "label"], "xent")
271  if not mkl:
272  loss = model.AveragedLoss(xent, "loss")
273  return model, 231
274 
275 
276 def VGGA(order, cudnn_ws, mkl):
277  my_arg_scope = {'order': order, 'use_cudnn': True,
278  'cudnn_exhaustive_search': True,
279  'ws_nbytes_limit': str(cudnn_ws)}
280  model = ModelHelper(name='vgg-a', arg_scope=my_arg_scope)
281  conv1 = brew.conv(
282  model,
283  "data",
284  "conv1",
285  3,
286  64,
287  3,
288  ('XavierFill', {}),
289  ('ConstantFill', {}),
290  pad=1
291  )
292  relu1 = brew.relu(model, conv1, "conv1")
293  pool1 = brew.max_pool(model, relu1, "pool1", kernel=2, stride=2)
294  conv2 = brew.conv(
295  model,
296  pool1,
297  "conv2",
298  64,
299  128,
300  3,
301  ('XavierFill', {}),
302  ('ConstantFill', {}),
303  pad=1
304  )
305  relu2 = brew.relu(model, conv2, "conv2")
306  pool2 = brew.max_pool(model, relu2, "pool2", kernel=2, stride=2)
307  conv3 = brew.conv(
308  model,
309  pool2,
310  "conv3",
311  128,
312  256,
313  3,
314  ('XavierFill', {}),
315  ('ConstantFill', {}),
316  pad=1
317  )
318  relu3 = brew.relu(model, conv3, "conv3")
319  conv4 = brew.conv(
320  model,
321  relu3,
322  "conv4",
323  256,
324  256,
325  3,
326  ('XavierFill', {}),
327  ('ConstantFill', {}),
328  pad=1
329  )
330  relu4 = brew.relu(model, conv4, "conv4")
331  pool4 = brew.max_pool(model, relu4, "pool4", kernel=2, stride=2)
332  conv5 = brew.conv(
333  model,
334  pool4,
335  "conv5",
336  256,
337  512,
338  3,
339  ('XavierFill', {}),
340  ('ConstantFill', {}),
341  pad=1
342  )
343  relu5 = brew.relu(model, conv5, "conv5")
344  conv6 = brew.conv(
345  model,
346  relu5,
347  "conv6",
348  512,
349  512,
350  3,
351  ('XavierFill', {}),
352  ('ConstantFill', {}),
353  pad=1
354  )
355  relu6 = brew.relu(model, conv6, "conv6")
356  pool6 = brew.max_pool(model, relu6, "pool6", kernel=2, stride=2)
357  conv7 = brew.conv(
358  model,
359  pool6,
360  "conv7",
361  512,
362  512,
363  3,
364  ('XavierFill', {}),
365  ('ConstantFill', {}),
366  pad=1
367  )
368  relu7 = brew.relu(model, conv7, "conv7")
369  conv8 = brew.conv(
370  model,
371  relu7,
372  "conv8",
373  512,
374  512,
375  3,
376  ('XavierFill', {}),
377  ('ConstantFill', {}),
378  pad=1
379  )
380  relu8 = brew.relu(model, conv8, "conv8")
381  pool8 = brew.max_pool(model, relu8, "pool8", kernel=2, stride=2)
382 
383  fcix = brew.fc(
384  model, pool8, "fcix", 512 * 7 * 7, 4096, ('XavierFill', {}),
385  ('ConstantFill', {})
386  )
387  reluix = brew.relu(model, fcix, "fcix")
388  fcx = brew.fc(
389  model, reluix, "fcx", 4096, 4096, ('XavierFill', {}), ('ConstantFill', {})
390  )
391  relux = brew.relu(model, fcx, "fcx")
392  fcxi = brew.fc(
393  model, relux, "fcxi", 4096, 1000, ('XavierFill', {}), ('ConstantFill', {})
394  )
395  pred = brew.softmax(model, fcxi, "pred")
396  xent = model.LabelCrossEntropy([pred, "label"], "xent")
397  if not mkl:
398  loss = model.AveragedLoss(xent, "loss")
399  return model, 231
400 
401 
402 def _InceptionModule(
403  model, input_blob, input_depth, output_name, conv1_depth, conv3_depths,
404  conv5_depths, pool_depth
405 ):
406  # path 1: 1x1 conv
407  conv1 = brew.conv(
408  model, input_blob, output_name + ":conv1", input_depth, conv1_depth, 1,
409  ('XavierFill', {}), ('ConstantFill', {})
410  )
411  conv1 = brew.relu(model, conv1, conv1)
412  # path 2: 1x1 conv + 3x3 conv
413  conv3_reduce = brew.conv(
414  model, input_blob, output_name + ":conv3_reduce", input_depth,
415  conv3_depths[0], 1, ('XavierFill', {}), ('ConstantFill', {})
416  )
417  conv3_reduce = brew.relu(model, conv3_reduce, conv3_reduce)
418  conv3 = brew.conv(
419  model,
420  conv3_reduce,
421  output_name + ":conv3",
422  conv3_depths[0],
423  conv3_depths[1],
424  3,
425  ('XavierFill', {}),
426  ('ConstantFill', {}),
427  pad=1
428  )
429  conv3 = brew.relu(model, conv3, conv3)
430  # path 3: 1x1 conv + 5x5 conv
431  conv5_reduce = brew.conv(
432  model, input_blob, output_name + ":conv5_reduce", input_depth,
433  conv5_depths[0], 1, ('XavierFill', {}), ('ConstantFill', {})
434  )
435  conv5_reduce = brew.relu(model, conv5_reduce, conv5_reduce)
436  conv5 = brew.conv(
437  model,
438  conv5_reduce,
439  output_name + ":conv5",
440  conv5_depths[0],
441  conv5_depths[1],
442  5,
443  ('XavierFill', {}),
444  ('ConstantFill', {}),
445  pad=2
446  )
447  conv5 = brew.relu(model, conv5, conv5)
448  # path 4: pool + 1x1 conv
449  pool = brew.max_pool(
450  model,
451  input_blob,
452  output_name + ":pool",
453  kernel=3,
454  stride=1,
455  pad=1
456  )
457  pool_proj = brew.conv(
458  model, pool, output_name + ":pool_proj", input_depth, pool_depth, 1,
459  ('XavierFill', {}), ('ConstantFill', {})
460  )
461  pool_proj = brew.relu(model, pool_proj, pool_proj)
462  output = brew.concat(model, [conv1, conv3, conv5, pool_proj], output_name)
463  return output
464 
465 
466 def Inception(order, cudnn_ws, mkl):
467  my_arg_scope = {'order': order, 'use_cudnn': True,
468  'cudnn_exhaustive_search': True,
469  'ws_nbytes_limit': str(cudnn_ws)}
470  model = ModelHelper(name="inception", arg_scope=my_arg_scope)
471  conv1 = brew.conv(
472  model,
473  "data",
474  "conv1",
475  3,
476  64,
477  7,
478  ('XavierFill', {}),
479  ('ConstantFill', {}),
480  stride=2,
481  pad=3
482  )
483  relu1 = brew.relu(model, conv1, "conv1")
484  pool1 = brew.max_pool(model, relu1, "pool1", kernel=3, stride=2, pad=1)
485  conv2a = brew.conv(
486  model, pool1, "conv2a", 64, 64, 1,
487  ('XavierFill', {}), ('ConstantFill', {})
488  )
489  conv2a = brew.relu(model, conv2a, conv2a)
490  conv2 = brew.conv(
491  model,
492  conv2a,
493  "conv2",
494  64,
495  192,
496  3,
497  ('XavierFill', {}),
498  ('ConstantFill', {}),
499  pad=1
500  )
501  relu2 = brew.relu(model, conv2, "conv2")
502  pool2 = brew.max_pool(model, relu2, "pool2", kernel=3, stride=2, pad=1)
503  # Inception modules
504  inc3 = _InceptionModule(
505  model, pool2, 192, "inc3", 64, [96, 128], [16, 32], 32
506  )
507  inc4 = _InceptionModule(
508  model, inc3, 256, "inc4", 128, [128, 192], [32, 96], 64
509  )
510  pool5 = brew.max_pool(model, inc4, "pool5", kernel=3, stride=2, pad=1)
511  inc5 = _InceptionModule(
512  model, pool5, 480, "inc5", 192, [96, 208], [16, 48], 64
513  )
514  inc6 = _InceptionModule(
515  model, inc5, 512, "inc6", 160, [112, 224], [24, 64], 64
516  )
517  inc7 = _InceptionModule(
518  model, inc6, 512, "inc7", 128, [128, 256], [24, 64], 64
519  )
520  inc8 = _InceptionModule(
521  model, inc7, 512, "inc8", 112, [144, 288], [32, 64], 64
522  )
523  inc9 = _InceptionModule(
524  model, inc8, 528, "inc9", 256, [160, 320], [32, 128], 128
525  )
526  pool9 = brew.max_pool(model, inc9, "pool9", kernel=3, stride=2, pad=1)
527  inc10 = _InceptionModule(
528  model, pool9, 832, "inc10", 256, [160, 320], [32, 128], 128
529  )
530  inc11 = _InceptionModule(
531  model, inc10, 832, "inc11", 384, [192, 384], [48, 128], 128
532  )
533  pool11 = brew.average_pool(model, inc11, "pool11", kernel=7, stride=1)
534  fc = brew.fc(
535  model, pool11, "fc", 1024, 1000,
536  ('XavierFill', {}), ('ConstantFill', {})
537  )
538  # It seems that Soumith's benchmark does not have softmax on top
539  # for Inception. We will add it anyway so we can have a proper
540  # backward pass.
541  pred = brew.softmax(model, fc, "pred")
542  xent = model.LabelCrossEntropy([pred, "label"], "xent")
543  if not mkl:
544  loss = model.AveragedLoss(xent, "loss")
545  return model, 224
546 
547 
548 def AddParameterUpdate(model):
549  """ Simple plain SGD update -- not tuned to actually train the models """
550  ITER = brew.iter(model, "iter")
551  LR = model.LearningRate(
552  ITER, "LR", base_lr=-1e-8, policy="step", stepsize=10000, gamma=0.999)
553  ONE = model.param_init_net.ConstantFill([], "ONE", shape=[1], value=1.0)
554  for param in model.params:
555  param_grad = model.param_to_grad[param]
556  model.WeightedSum([param, ONE, param_grad, LR], param)
557 
558 
559 def Benchmark(model_gen, arg):
560  model, input_size = model_gen(arg.order, arg.cudnn_ws, arg.mkl)
561  model.Proto().type = arg.net_type
562  model.Proto().num_workers = arg.num_workers
563 
564  # In order to be able to run everything without feeding more stuff, let's
565  # add the data and label blobs to the parameter initialization net as well.
566  if arg.order == "NCHW":
567  input_shape = [arg.batch_size, 3, input_size, input_size]
568  else:
569  input_shape = [arg.batch_size, input_size, input_size, 3]
570  if arg.model == "MLP":
571  input_shape = [arg.batch_size, input_size]
572 
573  model.param_init_net.GaussianFill(
574  [],
575  "data",
576  shape=input_shape,
577  mean=0.0,
578  std=1.0
579  )
580  #MKL doesn't support int, so have to use numpy
581  if arg.mkl:
582  label = np.random.randint(low=0, high=1000, size=(arg.batch_size,)).astype(np.int32)
583  workspace.FeedBlob("label", label)
584  else:
585  model.param_init_net.UniformIntFill(
586  [],
587  "label",
588  shape=[arg.batch_size, ],
589  min=0,
590  max=999
591  )
592 
593  if arg.forward_only:
594  print('{}: running forward only.'.format(arg.model))
595  else:
596  if arg.mkl:
597  print(
598  '==WARNING==\n'
599  'forward-backward not supported yet in MKL, so exiting'
600  )
601  print('{}: running forward-backward.'.format(arg.model))
602  model.AddGradientOperators(["loss"])
603  AddParameterUpdate(model)
604  if arg.order == 'NHWC':
605  print(
606  '==WARNING==\n'
607  'NHWC order with CuDNN may not be supported yet, so I might\n'
608  'exit suddenly.'
609  )
610 
611  if not arg.cpu:
612  if arg.mkl:
613  model.param_init_net.RunAllOnMKL()
614  model.net.RunAllOnMKL()
615  else:
616  model.param_init_net.RunAllOnGPU()
617  model.net.RunAllOnGPU()
618 
619  if arg.engine:
620  for op in model.net.Proto().op:
621  op.engine = arg.engine
622 
623  if arg.dump_model:
624  # Writes out the pbtxt for benchmarks on e.g. Android
625  with open(
626  "{0}_init_batch_{1}.pbtxt".format(arg.model, arg.batch_size), "w"
627  ) as fid:
628  fid.write(str(model.param_init_net.Proto()))
629  with open("{0}.pbtxt".format(arg.model, arg.batch_size), "w") as fid:
630  fid.write(str(model.net.Proto()))
631 
632  workspace.RunNetOnce(model.param_init_net)
633  workspace.CreateNet(model.net)
634  workspace.BenchmarkNet(
635  model.net.Proto().name, arg.warmup_iterations, arg.iterations,
636  arg.layer_wise_benchmark)
637 
638 
639 def GetArgumentParser():
640  parser = argparse.ArgumentParser(description="Caffe2 benchmark.")
641  parser.add_argument(
642  "--batch_size",
643  type=int,
644  default=128,
645  help="The batch size."
646  )
647  parser.add_argument("--model", type=str, help="The model to benchmark.")
648  parser.add_argument(
649  "--order",
650  type=str,
651  default="NCHW",
652  help="The order to evaluate."
653  )
654  parser.add_argument(
655  "--cudnn_ws",
656  type=int,
657  help="The cudnn workspace size."
658  )
659  parser.add_argument(
660  "--iterations",
661  type=int,
662  default=10,
663  help="Number of iterations to run the network."
664  )
665  parser.add_argument(
666  "--warmup_iterations",
667  type=int,
668  default=10,
669  help="Number of warm-up iterations before benchmarking."
670  )
671  parser.add_argument(
672  "--forward_only",
673  action='store_true',
674  help="If set, only run the forward pass."
675  )
676  parser.add_argument(
677  "--layer_wise_benchmark",
678  action='store_true',
679  help="If True, run the layer-wise benchmark as well."
680  )
681  parser.add_argument(
682  "--cpu",
683  action='store_true',
684  help="If True, run testing on CPU instead of GPU."
685  )
686  parser.add_argument(
687  "--mkl",
688  action='store_true',
689  help="If True, run testing on CPU-MKL instead of GPU."
690  )
691  parser.add_argument(
692  "--engine",
693  type=str,
694  default="",
695  help="If set, blindly prefer the given engine(s) for every op.")
696  parser.add_argument(
697  "--dump_model",
698  action='store_true',
699  help="If True, dump the model prototxts to disk."
700  )
701  parser.add_argument("--net_type", type=str, default="simple")
702  parser.add_argument("--num_workers", type=int, default=2)
703  parser.add_argument("--use-nvtx", default=False, action='store_true')
704  parser.add_argument("--htrace_span_log_path", type=str)
705  return parser
706 
707 
708 if __name__ == '__main__':
709  args, extra_args = GetArgumentParser().parse_known_args()
710  if (
711  not args.batch_size or not args.model or not args.order
712  ):
713  GetArgumentParser().print_help()
714  else:
715  workspace.GlobalInit(
716  ['caffe2', '--caffe2_log_level=0'] + extra_args +
717  (['--caffe2_use_nvtx'] if args.use_nvtx else []) +
718  (['--caffe2_htrace_span_log_path=' + args.htrace_span_log_path]
719  if args.htrace_span_log_path else []))
720 
721  model_map = {
722  'AlexNet': AlexNet,
723  'OverFeat': OverFeat,
724  'VGGA': VGGA,
725  'Inception': Inception,
726  'ResNet50': ResNet50,
727  'MLP': MLP,
728  }
729  Benchmark(model_map[args.model], args)