From 5016170ff124987aa32636e3528fb8f07a034490 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Tue, 5 Feb 2019 23:12:50 +0000 Subject: [PATCH 1/7] Relax constexpr restriction --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8ca708018b13..e6a62306a1db 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ CFLAGS = -DMSHADOW_FORCE_STREAM $(WARNFLAGS) ifeq ($(DEV), 1) CFLAGS += -g -Werror - NVCCFLAGS += -Werror cross-execution-space-call + NVCCFLAGS += -Werror cross-execution-space-call --expt-relaxed-constexpr endif # CFLAGS for debug From 30bfab21e9233d42f12a03cb3226b85cd41657bc Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Tue, 19 Mar 2019 22:58:13 +0000 Subject: [PATCH 2/7] Image classifcation mkldnn --- example/quantization/imagenet_gen_qsym_mkldnn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/example/quantization/imagenet_gen_qsym_mkldnn.py b/example/quantization/imagenet_gen_qsym_mkldnn.py index 3f644fc771a7..a19b5deaa0f5 100644 --- a/example/quantization/imagenet_gen_qsym_mkldnn.py +++ b/example/quantization/imagenet_gen_qsym_mkldnn.py @@ -179,6 +179,7 @@ def save_params(fname, arg_params, aux_params, logger=None): prefix, epoch = download_model(model_name=args.model, logger=logger) sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch) + sym.save("model_pre_quantize.json") sym = sym.get_backend_symbol('MKLDNN') sym = sym.get_backend_symbol('MKLDNN_FC') From 77259733e9368449c04e1cb4f30e7e9dd9891a33 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Thu, 11 Apr 2019 08:26:58 +0000 Subject: [PATCH 3/7] Check mem profiler greater than 0 --- src/profiler/profiler.h | 6 ++++++ src/profiler/storage_profiler.h | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/profiler/profiler.h b/src/profiler/profiler.h index adea941bda13..f1fac9ae8ddd 100644 --- a/src/profiler/profiler.h +++ b/src/profiler/profiler.h @@ -608,6 +608,12 @@ struct ProfileCounter : public ProfileObject { return IncrementValue(static_cast(v)); } } + + inline bool operator >=(int64_t v) { + CHECK_GE(v, 0); + return value_ >= static_cast(v); + } + /*! \brief operator: object = v */ inline ProfileCounter& operator = (uint64_t v) { SetValue(v); diff --git a/src/profiler/storage_profiler.h b/src/profiler/storage_profiler.h index bcbe7e7e3ffd..5ab5983267eb 100644 --- a/src/profiler/storage_profiler.h +++ b/src/profiler/storage_profiler.h @@ -66,7 +66,11 @@ class DeviceStorageProfiler { Init(); // In case of bug which tries to free first const size_t idx = prof->DeviceIndex(handle.ctx.dev_type, handle.ctx.dev_id); CHECK_LT(idx, mem_counters_.size()) << "Invalid device index: " << idx; - *mem_counters_[idx] -= handle.size; + if (*mem_counters_[idx] >= handle.size) { + *mem_counters_[idx] -= handle.size; + } else { + *mem_counters_[idx] = 0; + } } } } From a4e4e2fdd08546b7e81a7531b735efbbe1d3512f Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Thu, 11 Apr 2019 20:12:22 +0000 Subject: [PATCH 4/7] Revert "Relax constexpr restriction" This reverts commit 5016170ff124987aa32636e3528fb8f07a034490. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a2ef29157417..43d212e5f938 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ CFLAGS = -DMSHADOW_FORCE_STREAM $(WARNFLAGS) ifeq ($(DEV), 1) CFLAGS += -g -Werror - NVCCFLAGS += -Werror cross-execution-space-call --expt-relaxed-constexpr + NVCCFLAGS += -Werror cross-execution-space-call endif # CFLAGS for debug From 6cae3384931ea7aeea5794d9e86e9142296eab90 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Thu, 11 Apr 2019 20:14:54 +0000 Subject: [PATCH 5/7] Revert "Image classifcation mkldnn" This reverts commit 30bfab21e9233d42f12a03cb3226b85cd41657bc. --- example/quantization/imagenet_gen_qsym_mkldnn.py | 1 - 1 file changed, 1 deletion(-) diff --git a/example/quantization/imagenet_gen_qsym_mkldnn.py b/example/quantization/imagenet_gen_qsym_mkldnn.py index 4290f5fcba65..2ef137273cca 100644 --- a/example/quantization/imagenet_gen_qsym_mkldnn.py +++ b/example/quantization/imagenet_gen_qsym_mkldnn.py @@ -179,7 +179,6 @@ def save_params(fname, arg_params, aux_params, logger=None): prefix, epoch = download_model(model_name=args.model, logger=logger) sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch) - sym.save("model_pre_quantize.json") sym = sym.get_backend_symbol('MKLDNN') # get batch size From 1bc41c3df9ceeb60768824113c895f3dfbcc62c1 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Thu, 11 Apr 2019 22:19:21 +0000 Subject: [PATCH 6/7] Add test for profiler --- tests/python/unittest/test_exc_handling.py | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/python/unittest/test_exc_handling.py b/tests/python/unittest/test_exc_handling.py index 60799f821b8e..0a74d403e128 100644 --- a/tests/python/unittest/test_exc_handling.py +++ b/tests/python/unittest/test_exc_handling.py @@ -22,6 +22,7 @@ from mxnet.gluon import nn from mxnet.base import MXNetError from mxnet.test_utils import assert_exception, default_context, set_default_context +from mxnet.gluon.data.vision import transforms from nose.tools import assert_raises @with_seed() @@ -165,6 +166,46 @@ def test_multiple_waitalls(): assert caught, "No exception thrown" mx.nd.waitall() +@with_seed() +def test_exc_profiler(): + def run_training_iteration(data, label): + data = data.as_in_context(ctx) + label = label.as_in_context(ctx) + with mx.autograd.record(): + output = net(data) + loss = softmax_cross_entropy(output, label) + loss.backward() + + trainer.step(data.shape[0]) + + net = gluon.nn.HybridSequential() + with net.name_scope(): + net.add(gluon.nn.Conv2D(channels=20, kernel_size=5, activation='relu')) + net.add(gluon.nn.MaxPool2D(pool_size=2, strides=2)) + net.add(gluon.nn.Conv2D(channels=50, kernel_size=5, activation='relu')) + net.add(gluon.nn.MaxPool2D(pool_size=2, strides=2)) + net.add(gluon.nn.Flatten()) + net.add(gluon.nn.Dense(512, activation="relu")) + net.add(gluon.nn.Dense(10)) + + train_data = gluon.data.DataLoader(gluon.data.vision.MNIST(train=True).transform_first(transforms.ToTensor()), + batch_size=64, shuffle=True) + + ctx = default_context() + + net.collect_params().initialize(mx.init.Xavier(), ctx=ctx) + trainer = gluon.Trainer(net.collect_params(), 'sgd', {'learning_rate': 0.1}) + softmax_cross_entropy = gluon.loss.SoftmaxCrossEntropyLoss() + + itr = iter(train_data) + run_training_iteration(*next(itr)) + + data, label = next(itr) + + mx.profiler.set_state("run") + run_training_iteration(*next(itr)) + mx.nd.waitall() + mx.profiler.set_state("stop") if __name__ == '__main__': From c7b85d87f1f350cb983d1aa244147bdfa88a7ab7 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Fri, 12 Apr 2019 06:10:51 +0000 Subject: [PATCH 7/7] Simplify test --- tests/python/unittest/test_exc_handling.py | 33 +++------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/tests/python/unittest/test_exc_handling.py b/tests/python/unittest/test_exc_handling.py index 0a74d403e128..5627ac50d26e 100644 --- a/tests/python/unittest/test_exc_handling.py +++ b/tests/python/unittest/test_exc_handling.py @@ -22,7 +22,6 @@ from mxnet.gluon import nn from mxnet.base import MXNetError from mxnet.test_utils import assert_exception, default_context, set_default_context -from mxnet.gluon.data.vision import transforms from nose.tools import assert_raises @with_seed() @@ -168,42 +167,18 @@ def test_multiple_waitalls(): @with_seed() def test_exc_profiler(): - def run_training_iteration(data, label): - data = data.as_in_context(ctx) - label = label.as_in_context(ctx) - with mx.autograd.record(): - output = net(data) - loss = softmax_cross_entropy(output, label) - loss.backward() - - trainer.step(data.shape[0]) + def run_training_iteration(data): + output = net(data) net = gluon.nn.HybridSequential() with net.name_scope(): - net.add(gluon.nn.Conv2D(channels=20, kernel_size=5, activation='relu')) - net.add(gluon.nn.MaxPool2D(pool_size=2, strides=2)) - net.add(gluon.nn.Conv2D(channels=50, kernel_size=5, activation='relu')) - net.add(gluon.nn.MaxPool2D(pool_size=2, strides=2)) - net.add(gluon.nn.Flatten()) - net.add(gluon.nn.Dense(512, activation="relu")) net.add(gluon.nn.Dense(10)) - train_data = gluon.data.DataLoader(gluon.data.vision.MNIST(train=True).transform_first(transforms.ToTensor()), - batch_size=64, shuffle=True) - ctx = default_context() - net.collect_params().initialize(mx.init.Xavier(), ctx=ctx) - trainer = gluon.Trainer(net.collect_params(), 'sgd', {'learning_rate': 0.1}) - softmax_cross_entropy = gluon.loss.SoftmaxCrossEntropyLoss() - - itr = iter(train_data) - run_training_iteration(*next(itr)) - - data, label = next(itr) - + data = mx.nd.ones((3, 4)) mx.profiler.set_state("run") - run_training_iteration(*next(itr)) + run_training_iteration(data) mx.nd.waitall() mx.profiler.set_state("stop")