Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

SSD performance optimization and benchmark script #10483

Merged
merged 7 commits into from
May 24, 2018

Conversation

TaoLv
Copy link
Member

@TaoLv TaoLv commented Apr 10, 2018

Description

In this PR:

  • An inference benchmark script for SSD is added
  • Operator MultiBoxDetection is optimized to improve SSD performance on CPU
  • I tried to add a unit test for the consistency check between cpu and gpu but failed, since MultiBoxDetection on gpu cannot generate stable results for different run. I have raised a issue for this MultiBoxDetection cannot pass consistency check #10316. This code has past the consistency check with original cpu implementation.
  • Below performance is measured on skylake6148 with 2 sockets:

python benchmark_score.py
SSD-VGG16 with 20 classes and shape (3, 300, 300), img/sec

bs master +mkldnn +mkldnn+this PR
1 2.02 7.64 23.77
2 2.10 5.28 15.54
4 2.26 6.80 23.08
8 2.40 8.03 28.78
16 2.80 9.11 33.14
32 2.82 8.80 32.81

python benchmark_score.py --network resnet50
SSD-ResNet50 with 20 classes and shape (3, 300, 300), img/sec

bs master +mkldnn +mkldnn+this PR
1 8.32 30.94 40.58
2 8.58 28.71 37.65
4 8.69 39.02 54.04
8 8.59 47.72 68.90
16 8.54 47.64 77.39
32 8.79 54.74 89.62

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@TaoLv TaoLv requested a review from szha as a code owner April 10, 2018 09:45
@TaoLv
Copy link
Member Author

TaoLv commented Apr 10, 2018

@pengzhao-intel

@pengzhao-intel
Copy link
Contributor

pengzhao-intel commented Apr 10, 2018

There're huge improvements for SSD.
Is it possible to add this one to release 1.2?

@zhanghang1989
Copy link
Contributor

@zhreshold

import time
#from dataset.iterator import DetRecordIter
#from config.config import cfg
#from evaluate.eval_metric import MApMetric, VOC07MApMetric
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will do.

variances[2], variances[3]);

// [id, prob, xmin, ymin, xmax, ymax]
outputs[i * 6] = id - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do any tests exist currently for this op ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess no

@kevinthesun
Copy link
Contributor

Maybe we can also benchmark with pretrained ssd model? Since with my experience of benchmarking ssd with mkldnn on skylake, multi box_detection shouldn't take that long when using pretrained model, due to number of valid objects is much smaller than random initialized parameters. For resnet50 as body network, time of multi box_detection is about 2% of the total inference time and with vgg16_reduced it is 8%.

@zhreshold
Copy link
Member

I hold the same opinion with @kevinthesun , it is not precise to benchmark randomly intialized weights.

@piiswrong
Copy link
Contributor

So this would only help at the beginning of training?

@kevinthesun
Copy link
Contributor

MultiBoxDetection is only used for inference. @zhreshold Is this accurate?

@zhreshold
Copy link
Member

I think this should still improve the inference speed, but we would like to see how this affecting the pre-trained models. Apparently not by such a huge margin.

mod.bind(for_training = False,
inputs_need_grad = False,
data_shapes = get_data_shapes(bs))
mod.init_params(initializer=mx.init.Xavier(magnitude=2.))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try load some pre-trained models to test the real perf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Do you know where I can find pre-trained parameters for SSD? I didn't find them in data.mxnet.io.

@pengzhao-intel
Copy link
Contributor

@zhreshold @kevinthesun @piiswrong where we can get the pre-trained SSD data?

@zhreshold
Copy link
Member

@pengzhao-intel
You can find pre-trained models here: https://github.com/zhreshold/mxnet-ssd#map

@juliusshufan
Copy link
Contributor

@kevinthesun Yes, pre-trained model can be used for inference benchmarking, while it still involving dataloader and dataset, the benchmark script appended with this PR is dummy data-based and might be more flexible, I guess it is a potential utility as well. What do y ou think? :)

@kevinthesun
Copy link
Contributor

@juliusshufan Synthetic data is fine as along as pre-trained model is used.

Conflicts:
	src/operator/contrib/multibox_detection.cc
@zhreshold
Copy link
Member

LGTM for this PR, just wish the benchmarks could be updated for the pretrained models so we can have better ideas of the perf improvement.
I will merge this now.

@zhreshold zhreshold merged commit 166944c into apache:master May 24, 2018
jinhuang415 pushed a commit to jinhuang415/incubator-mxnet that referenced this pull request May 29, 2018
* add ssd benchmark

* optimize MultiBoxDetectionForward

* update default batch sizes for ssd benchmark

* remove commented python code
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* add ssd benchmark

* optimize MultiBoxDetectionForward

* update default batch sizes for ssd benchmark

* remove commented python code
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* add ssd benchmark

* optimize MultiBoxDetectionForward

* update default batch sizes for ssd benchmark

* remove commented python code
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants