MCPcopy Index your code
hub / github.com/pytorch/pytorch / Benchmark

Function Benchmark

caffe2/experiments/python/convnet_benchmarks.py:553–622  ·  view source on GitHub ↗
(model_gen, arg)

Source from the content-addressed store, hash-verified

551
552
553def Benchmark(model_gen, arg):
554 model, input_size = model_gen(arg.order)
555 model.Proto().type = arg.net_type
556 model.Proto().num_workers = arg.num_workers
557
558 # In order to be able to run everything without feeding more stuff, let's
559 # add the data and label blobs to the parameter initialization net as well.
560
561 if arg.order == "NCHW":
562 input_shape = [arg.batch_size, 3, input_size, input_size]
563 else:
564 input_shape = [arg.batch_size, input_size, input_size, 3]
565 if arg.model == "MLP":
566 input_shape = [arg.batch_size, input_size]
567
568 model.param_init_net.GaussianFill(
569 [],
570 "data",
571 shape=input_shape,
572 mean=0.0,
573 std=1.0
574 )
575 model.param_init_net.UniformIntFill(
576 [],
577 "label",
578 shape=[arg.batch_size, ],
579 min=0,
580 max=999
581 )
582
583 if arg.forward_only:
584 print('{}: running forward only.'.format(arg.model))
585 else:
586 print('{}: running forward-backward.'.format(arg.model))
587 model.AddGradientOperators(["loss"])
588 AddParameterUpdate(model)
589
590 if arg.order == 'NHWC':
591 print(
592 '==WARNING==\n'
593 'NHWC order with CuDNN may not be supported yet, so I might\n'
594 'exit suddenly.'
595 )
596
597 if not arg.cpu:
598 model.param_init_net.RunAllOnGPU()
599 model.net.RunAllOnGPU()
600
601 if arg.dump_model:
602 # Writes out the pbtxt for benchmarks on e.g. Android
603 with open(
604 "{0}_init_batch_{1}.pbtxt".format(arg.model, arg.batch_size), "w"
605 ) as fid:
606 fid.write(str(model.param_init_net.Proto()))
607 with open("{0}.pbtxt".format(arg.model), "w") as fid:
608 fid.write(str(model.net.Proto()))
609
610 workspace.RunNetOnce(model.param_init_net)

Callers 1

Calls 8

AddStepMethod · 0.95
AddParameterUpdateFunction · 0.70
rangeFunction · 0.50
ProtoMethod · 0.45
formatMethod · 0.45
AddGradientOperatorsMethod · 0.45
RunAllOnGPUMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…