From 0fbebd4219cc1820d6c202308355b7449e50a397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Tue, 13 Jun 2017 15:58:11 +0200 Subject: [PATCH 1/9] ColumnQuantizer: fix ambiguous call to template --- Source/Math/ColumnQuantizer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Math/ColumnQuantizer.h b/Source/Math/ColumnQuantizer.h index 5ad54cccef3e..257c4eaedd7e 100644 --- a/Source/Math/ColumnQuantizer.h +++ b/Source/Math/ColumnQuantizer.h @@ -132,7 +132,7 @@ class ColumnQuantizer // quantize size_t ij = ColMIDX(i, colIdx, M); ElemType val = inMat[ij] + inResidual[ij]; - QWordVal qval = valQ.Quantize(val); + QWordVal qval = valQ.template Quantize(val); // compute residual ElemType uval = valQ.Unquantize(qval); From 15dee1b77b633341f5dc64fd9483aec1b083c4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Wed, 14 Jun 2017 10:39:53 +0200 Subject: [PATCH 2/9] NDArrayView: make templated function inline --- Source/CNTKv2LibraryDll/API/CNTKLibrary.h | 9 ++++++++- Source/CNTKv2LibraryDll/NDArrayView.cpp | 8 -------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/CNTKv2LibraryDll/API/CNTKLibrary.h b/Source/CNTKv2LibraryDll/API/CNTKLibrary.h index fbd4a7d7c519..6abcc5a6501e 100644 --- a/Source/CNTKv2LibraryDll/API/CNTKLibrary.h +++ b/Source/CNTKv2LibraryDll/API/CNTKLibrary.h @@ -821,8 +821,15 @@ namespace CNTK template std::shared_ptr> GetWritableMatrix(size_t rowColSplitPoint = AutoSelectRowColSplitPoint); + template - const Microsoft::MSR::CNTK::TensorView* GetTensorView() const; + inline const Microsoft::MSR::CNTK::TensorView* GetTensorView() const + { + if (AsDataType() != m_dataType) + LogicError("NDArrayView::GetTensorView: The specified ElementType %s does not match the DataType %s", typeid(ElementType).name(), DataTypeName(m_dataType)); + + return (const Microsoft::MSR::CNTK::TensorView*)(m_tensorView.get()); + } template Microsoft::MSR::CNTK::TensorView* GetWritableTensorView(); diff --git a/Source/CNTKv2LibraryDll/NDArrayView.cpp b/Source/CNTKv2LibraryDll/NDArrayView.cpp index 4ce528c35fe4..4c4b749c20a5 100644 --- a/Source/CNTKv2LibraryDll/NDArrayView.cpp +++ b/Source/CNTKv2LibraryDll/NDArrayView.cpp @@ -205,14 +205,6 @@ namespace CNTK return GetMatrixImpl(GetWritableTensorView(), rowColSplitPoint); } - template - const TensorView* NDArrayView::GetTensorView() const - { - if (AsDataType() != m_dataType) - LogicError("NDArrayView::GetTensorView: The specified ElementType %s does not match the DataType %s", typeid(ElementType).name(), DataTypeName(m_dataType)); - - return (const TensorView*)(m_tensorView.get()); - } template TensorView* NDArrayView::GetWritableTensorView() From e2da466159692265b43a603fc1f7d7635167133e Mon Sep 17 00:00:00 2001 From: Zhou Wang Date: Fri, 4 Aug 2017 14:45:33 +0200 Subject: [PATCH 3/9] use explict instantiation instead of inline to reduce the size of header file --- Source/CNTKv2LibraryDll/API/CNTKLibrary.h | 9 +-------- Source/CNTKv2LibraryDll/NDArrayView.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Source/CNTKv2LibraryDll/API/CNTKLibrary.h b/Source/CNTKv2LibraryDll/API/CNTKLibrary.h index 6abcc5a6501e..fbd4a7d7c519 100644 --- a/Source/CNTKv2LibraryDll/API/CNTKLibrary.h +++ b/Source/CNTKv2LibraryDll/API/CNTKLibrary.h @@ -821,15 +821,8 @@ namespace CNTK template std::shared_ptr> GetWritableMatrix(size_t rowColSplitPoint = AutoSelectRowColSplitPoint); - template - inline const Microsoft::MSR::CNTK::TensorView* GetTensorView() const - { - if (AsDataType() != m_dataType) - LogicError("NDArrayView::GetTensorView: The specified ElementType %s does not match the DataType %s", typeid(ElementType).name(), DataTypeName(m_dataType)); - - return (const Microsoft::MSR::CNTK::TensorView*)(m_tensorView.get()); - } + const Microsoft::MSR::CNTK::TensorView* GetTensorView() const; template Microsoft::MSR::CNTK::TensorView* GetWritableTensorView(); diff --git a/Source/CNTKv2LibraryDll/NDArrayView.cpp b/Source/CNTKv2LibraryDll/NDArrayView.cpp index 4c4b749c20a5..0dc79452e41e 100644 --- a/Source/CNTKv2LibraryDll/NDArrayView.cpp +++ b/Source/CNTKv2LibraryDll/NDArrayView.cpp @@ -205,6 +205,14 @@ namespace CNTK return GetMatrixImpl(GetWritableTensorView(), rowColSplitPoint); } + template + const TensorView* NDArrayView::GetTensorView() const + { + if (AsDataType() != m_dataType) + LogicError("NDArrayView::GetTensorView: The specified ElementType %s does not match the DataType %s", typeid(ElementType).name(), DataTypeName(m_dataType)); + + return (const TensorView*)(m_tensorView.get()); + } template TensorView* NDArrayView::GetWritableTensorView() @@ -513,6 +521,9 @@ namespace CNTK template CNTK_API const float* NDArrayView::DataBuffer() const; template CNTK_API const double* NDArrayView::DataBuffer() const; + template CNTK_API const TensorView* NDArrayView::GetTensorView() const; + template CNTK_API const TensorView* NDArrayView::GetTensorView() const; + template CNTK_API float* NDArrayView::WritableDataBuffer(); template CNTK_API double* NDArrayView::WritableDataBuffer(); From f3956e7e8e76069ccbe53f935385612c05325a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20=C5=BBak?= Date: Fri, 4 Aug 2017 16:30:13 +0000 Subject: [PATCH 4/9] changes in README.md for FasterRCNN example (#2185) simple fix of file names --- Examples/Image/Detection/FasterRCNN/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Image/Detection/FasterRCNN/README.md b/Examples/Image/Detection/FasterRCNN/README.md index ff833bc5c01b..e5e6689d5f6e 100644 --- a/Examples/Image/Detection/FasterRCNN/README.md +++ b/Examples/Image/Detection/FasterRCNN/README.md @@ -29,7 +29,7 @@ If you require other versions please follow the instructions at [https://github. We use a toy dataset of images captured from a refrigerator to demonstrate Faster R-CNN. Both the dataset and the pre-trained AlexNet model can be downloaded by running the following Python command: -`python install_data-and-model.py` +`python install_data_and_model.py` After running the script, the toy dataset will be installed under the `Image/DataSets/Grocery` folder. And the AlexNet model will be downloaded to the `Image/PretrainedModels` folder. We recommend you to keep the downloaded data in the respective folder while downloading, as the configuration files in this folder assumes that by default. From 8bcbc8c21d5f9e51479e60e3255fc97e5f4484a9 Mon Sep 17 00:00:00 2001 From: Cheng Tang Date: Mon, 31 Jul 2017 19:43:57 -0700 Subject: [PATCH 5/9] disable the memory share for gather node's input --- Source/ComputationNetworkLib/ReshapingNodes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ComputationNetworkLib/ReshapingNodes.h b/Source/ComputationNetworkLib/ReshapingNodes.h index c5c73837d803..eac61a0976d3 100644 --- a/Source/ComputationNetworkLib/ReshapingNodes.h +++ b/Source/ComputationNetworkLib/ReshapingNodes.h @@ -1945,7 +1945,7 @@ class GatherNode : public ComputationNodeNonLooping, public NumInputs< return false; } virtual bool InputUsedInComputingInputNodesGradients(size_t /*childIndex*/) const override { - return false; + return true; } virtual void /*ComputationNodeBase::*/ Validate(bool isFinalValidationPass) override From 00bd68a091c31c8645dca7c40fb02535d53b1dea Mon Sep 17 00:00:00 2001 From: Cheng Tang Date: Thu, 3 Aug 2017 15:40:40 -0700 Subject: [PATCH 6/9] add ut --- Source/ComputationNetworkLib/ReshapingNodes.h | 4 +-- .../python/cntk/ops/tests/reshaping_test.py | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Source/ComputationNetworkLib/ReshapingNodes.h b/Source/ComputationNetworkLib/ReshapingNodes.h index eac61a0976d3..f1d3d18ca0ad 100644 --- a/Source/ComputationNetworkLib/ReshapingNodes.h +++ b/Source/ComputationNetworkLib/ReshapingNodes.h @@ -1944,8 +1944,8 @@ class GatherNode : public ComputationNodeNonLooping, public NumInputs< virtual bool OutputUsedInComputingInputNodesGradients() const override { return false; } - virtual bool InputUsedInComputingInputNodesGradients(size_t /*childIndex*/) const override { - return true; + virtual bool InputUsedInComputingInputNodesGradients(size_t childIndex) const override { + return childIndex == 0; } virtual void /*ComputationNodeBase::*/ Validate(bool isFinalValidationPass) override diff --git a/bindings/python/cntk/ops/tests/reshaping_test.py b/bindings/python/cntk/ops/tests/reshaping_test.py index 3cc4d5d81275..9296f3293423 100644 --- a/bindings/python/cntk/ops/tests/reshaping_test.py +++ b/bindings/python/cntk/ops/tests/reshaping_test.py @@ -484,6 +484,34 @@ def test_gather_op(device_id, precision): expectd2 = np.asarray([[[[0., 1.],[4.,5.]],[[2., 3.],[6., 7.]]],[[[4., 5.],[8.,9.]],[[6., 7.], [10., 11.]]]]) assert np.array_equal(res2, expectd2) + #the following small model is to test the memory reuse issue of gather node. + x = C.input((3, 4)) + x1 = C.to_sequence(x) + w = C.parameter((5, 6), init=1) + z = C.gather(w, x1) + assert z.shape == (4, 6) + #need the unpack node to trigger memory reuse. + f = C.sequence.unpack(z, 0, no_mask_output=True) + y = C.input((3, 4, 6)) + loss = C.reduce_mean(C.square(f - y), axis=-1) + loss = C.reduce_mean(loss, axis=C.Axis.all_axes()) + + g = C.constant(0, shape=w.shape) + u = C.assign(w, g + 1) + learner = C.cntk_py.universal_learner([w], [g], u) + trainer = C.trainer.Trainer(loss, [loss], [learner]) + indices = np.asarray([[[1, 2, 1, 2]]]) + input = np.repeat(np.repeat(indices, 3, axis=1), 10, axis=0) + lable = np.full((10, 3, 4, 6), 2) + trainer.train_minibatch({x: input, y: lable}) + # the 2nd and 3rd rows should be udpated by gradients. + assert np.mean(w.value[1, :]) < 1 + assert np.mean(w.value[2, :]) < 1 + # the other three rows should keep as 1 + assert np.isclose(np.mean(w.value[0, :]), 1) + assert np.isclose(np.mean(w.value[3, :]), 1) + assert np.isclose(np.mean(w.value[4, :]), 1) + def test_convert_dynamic_axis(): #test fix batch size batch_size = 4 From 6fe814fbab3fe5ba8b3f31735136e36d24a832b2 Mon Sep 17 00:00:00 2001 From: Cha Zhang Date: Fri, 4 Aug 2017 16:22:20 -0700 Subject: [PATCH 7/9] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f451e3682585..419953d6b047 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ ## Latest news +***2017-08-04.*** CNTK July interation plan posted [here](https://github.com/Microsoft/CNTK/issues/2194). + ***2017-07-31.* CNTK 2.1** Release of Cognitive Toolkit v.2.1. From 5a71551e30ece27d6008b0a337b0d3c019859c2e Mon Sep 17 00:00:00 2001 From: Cha Zhang Date: Fri, 4 Aug 2017 16:23:15 -0700 Subject: [PATCH 8/9] Update README.md --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 419953d6b047..ef453159e93f 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,6 @@ Get the Release from the [CNTK Releases page](https://github.com/Microsoft/CNTK/ ***2017-07-07.*** CNTK July interation plan posted [here](https://github.com/Microsoft/CNTK/issues/2064). -***2017-06-26.*** A great class for getting started with both Deep Learning and CNTK, [Deep Learning Explained](https://www.edx.org/course/deep-learning-explained-microsoft-dat236x) is now available on edX. - -***2017-06-01.* CNTK 2.0 is released.** -The first production release of Cognitive Toolkit v.2. See more in the [Release Notes](https://docs.microsoft.com/en-us/cognitive-toolkit/ReleaseNotes/CNTK_2_0_Release_Notes), and get the Release from the [CNTK Releases page](https://github.com/Microsoft/CNTK/releases). - See [all news](https://docs.microsoft.com/en-us/cognitive-toolkit/news) ## Introduction From 6cdd48295c9827a872ffa65501be6ee38af20a81 Mon Sep 17 00:00:00 2001 From: Daniel Schneider Date: Fri, 4 Aug 2017 16:36:58 -0700 Subject: [PATCH 9/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef453159e93f..5d4d40d8b364 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Latest news -***2017-08-04.*** CNTK July interation plan posted [here](https://github.com/Microsoft/CNTK/issues/2194). +***2017-08-04.*** CNTK August interation plan posted [here](https://github.com/Microsoft/CNTK/issues/2194). ***2017-07-31.* CNTK 2.1** Release of Cognitive Toolkit v.2.1.