From 6a9610ed13cec275afc69061e38b186bd3afa0e5 Mon Sep 17 00:00:00 2001 From: 0x45f <23097963+0x45f@users.noreply.github.com> Date: Tue, 20 Jul 2021 13:55:56 +0800 Subject: [PATCH 1/3] [Dy2Stat]Support Nest sequtial container (#34246) * support Nest sequtial container * rename model path --- .../dygraph_to_static/convert_call_func.py | 2 +- .../dygraph_to_static/test_container.py | 38 +++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py b/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py index a621f68c6545a..b62c16989fbe7 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py @@ -88,7 +88,7 @@ def is_unsupported(func): for v in m.__dict__.values(): func_in_dict = func == v if isinstance(func_in_dict, (list, numpy.ndarray)): - func_in_dict = any(func_in_dict) + func_in_dict = numpy.array(func_in_dict).any() if func_in_dict: translator_logger.log( 2, diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_container.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_container.py index 647c9e9672cf0..2c82f5c699087 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_container.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_container.py @@ -47,10 +47,30 @@ def forward(self, x): return out +class NestSequentialNet(paddle.nn.Layer): + def __init__(self): + super().__init__() + group1 = paddle.nn.Sequential( + paddle.nn.Linear(10, 10), + paddle.nn.Sigmoid(), ) + group2 = paddle.nn.Sequential( + paddle.nn.Linear(10, 3), + paddle.nn.ReLU(), ) + self.layers = paddle.nn.Sequential(group1, group2) + + def forward(self, x): + return self.layers(x) + + class TestSequential(unittest.TestCase): def setUp(self): paddle.set_device('cpu') self.seed = 2021 + self._init_config() + + def _init_config(self): + self.net = SequentialNet(BufferLayers, 10, 3) + self.model_path = './sequential_net' def _init_seed(self): paddle.seed(self.seed) @@ -58,13 +78,12 @@ def _init_seed(self): def _run(self, to_static): self._init_seed() - net = SequentialNet(BufferLayers, 10, 3) if to_static: - net = paddle.jit.to_static(net) + self.net = paddle.jit.to_static(self.net) x = paddle.rand([16, 10], 'float32') - out = net(x) + out = self.net(x) if to_static: - load_out = self._test_load(net, x) + load_out = self._test_load(self.net, x) self.assertTrue( np.allclose(load_out, out), msg='load_out is {}\st_out is {}'.format(load_out, out)) @@ -80,12 +99,17 @@ def test_train(self): msg='dygraph_res is {}\nstatic_res is {}'.format(dy_out, st_out)) def _test_load(self, net, x): - model_path = './sequential_net' - paddle.jit.save(net, model_path) - load_net = paddle.jit.load(model_path) + paddle.jit.save(net, self.model_path) + load_net = paddle.jit.load(self.model_path) out = load_net(x) return out +class TestNestSequential(TestSequential): + def _init_config(self): + self.net = NestSequentialNet() + self.model_path = './nested_sequential_net' + + if __name__ == '__main__': unittest.main() From 301fb64d83cffcdd0ac3ae83763bff2d1adcd93a Mon Sep 17 00:00:00 2001 From: Wilber Date: Tue, 20 Jul 2021 14:19:07 +0800 Subject: [PATCH 2/3] add cuda102cudnn7trt6.0.1.8 images (#34241) --- tools/dockerfile/build_scripts/install_trt.sh | 17 ++++++++++++++++- tools/dockerfile/centos7_manylinux.sh | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/dockerfile/build_scripts/install_trt.sh b/tools/dockerfile/build_scripts/install_trt.sh index 69552871211fd..a461e2a4f24b3 100644 --- a/tools/dockerfile/build_scripts/install_trt.sh +++ b/tools/dockerfile/build_scripts/install_trt.sh @@ -16,6 +16,16 @@ VERSION=$(nvcc --version | grep release | grep -oEi "release ([0-9]+)\.([0-9])"| sed "s/release //") +CUDNN_MAJOR=$(cat /usr/include/cudnn.h | grep -v CUDNN_VERSION | grep CUDNN_MAJOR | cut -d' ' -f3) +CUDNN_MINOR=$(cat /usr/include/cudnn.h | grep -v CUDNN_VERSION | grep CUDNN_MINOR | cut -d' ' -f3) +CUDNN_PATCHLEVEL=$(cat /usr/include/cudnn.h | grep -v CUDNN_VERSION | grep CUDNN_PATCHLEVEL | cut -d' ' -f3) +if [[ -z "${CUDNN_MAJOR}" ]]; then + CUDNN_MAJOR=$(cat /usr/include/cudnn_version.h | grep -v CUDNN_VERSION | grep CUDNN_MAJOR | cut -d' ' -f3) + CUDNN_MINOR=$(cat /usr/include/cudnn_version.h | grep -v CUDNN_VERSION | grep CUDNN_MINOR | cut -d' ' -f3) + CUDNN_PATCHLEVEL=$(cat /usr/include/cudnn_version.h | grep -v CUDNN_VERSION | grep CUDNN_PATCHLEVEL | cut -d' ' -f3) +fi +CUDNN_VERSION="${CUDNN_MAJOR}.${CUDNN_MINOR}.${CUDNN_PATCHLEVEL}" + if [[ "$VERSION" == "10.1" ]];then wget -q https://paddle-ci.gz.bcebos.com/TRT/TensorRT6-cuda10.1-cudnn7.tar.gz --no-check-certificate tar -zxf TensorRT6-cuda10.1-cudnn7.tar.gz -C /usr/local @@ -36,7 +46,12 @@ elif [[ "$VERSION" == "11.0" ]];then tar -zxf TensorRT-7.1.3.4.Ubuntu-16.04.x86_64-gnu.cuda-11.0.cudnn8.0.tar.gz -C /usr/local cp -rf /usr/local/TensorRT-7.1.3.4/include/* /usr/include/ && cp -rf /usr/local/TensorRT-7.1.3.4/lib/* /usr/lib/ rm TensorRT-7.1.3.4.Ubuntu-16.04.x86_64-gnu.cuda-11.0.cudnn8.0.tar.gz -elif [[ "$VERSION" == "10.2" ]];then +elif [[ "$VERSION" == "10.2" && "$CUDNN_VERSION" == "7.6.5" ]];then + wget https://paddle-ci.gz.bcebos.com/TRT/TensorRT-6.0.1.8.CentOS-7.6.x86_64-gnu.cuda-10.2.cudnn7.6.tar.gz --no-check-certificate + tar -zxf TensorRT-6.0.1.8.CentOS-7.6.x86_64-gnu.cuda-10.2.cudnn7.6.tar.gz -C /usr/local + cp -rf /usr/local/TensorRT-6.0.1.8/include/* /usr/include/ && cp -rf /usr/local/TensorRT-6.0.1.8/lib/* /usr/lib/ + rm -f TensorRT-6.0.1.8.CentOS-7.6.x86_64-gnu.cuda-10.2.cudnn7.6.tar.gz +elif [[ "$VERSION" == "10.2" && "$CUDNN_VERSION" == "8.1.1" ]];then wget https://paddle-ci.gz.bcebos.com/TRT/TensorRT-7.2.3.4.CentOS-7.9.x86_64-gnu.cuda-10.2.cudnn8.1.tar.gz --no-check-certificate tar -zxf TensorRT-7.2.3.4.CentOS-7.9.x86_64-gnu.cuda-10.2.cudnn8.1.tar.gz -C /usr/local cp -rf /usr/local/TensorRT-7.2.3.4/include/* /usr/include/ && cp -rf /usr/local/TensorRT-7.2.3.4/lib/* /usr/lib/ diff --git a/tools/dockerfile/centos7_manylinux.sh b/tools/dockerfile/centos7_manylinux.sh index 9710ec0232095..d268341db9ae2 100755 --- a/tools/dockerfile/centos7_manylinux.sh +++ b/tools/dockerfile/centos7_manylinux.sh @@ -42,6 +42,11 @@ function make_cuda102cudnn7() { sed -i "s#RUN bash build_scripts/build.sh#RUN bash build_scripts/install_gcc.sh gcc82 \nRUN mv /usr/bin/cc /usr/bin/cc.bak \&\& ln -s /usr/local/gcc-8.2/bin/gcc /usr/bin/cc \nENV PATH=/usr/local/gcc-8.2/bin:\$PATH \nRUN bash build_scripts/build.sh#g" Dockerfile.tmp } +function make_cuda102cudnn7gcc54() { + sed 's//10.2-cudnn7-devel-centos7/g' Dockerfile.centos >Dockerfile.tmp + sed -i "s#RUN bash build_scripts/build.sh#RUN bash build_scripts/install_gcc.sh gcc54 \nRUN mv /usr/bin/cc /usr/bin/cc.bak \&\& ln -s /usr/local/gcc-8.2/bin/gcc /usr/bin/cc \nENV PATH=/usr/local/gcc-8.2/bin:\$PATH \nRUN bash build_scripts/build.sh#g" Dockerfile.tmp +} + function make_cuda102cudnn8() { sed 's//10.2-cudnn8-devel-centos7/g' Dockerfile.centos >Dockerfile.tmp sed -i "s#RUN bash build_scripts/build.sh#RUN bash build_scripts/install_gcc.sh gcc82 \nRUN mv /usr/bin/cc /usr/bin/cc.bak \&\& ln -s /usr/local/gcc-8.2/bin/gcc /usr/bin/cc \nENV PATH=/usr/local/gcc-8.2/bin:\$PATH \nRUN bash build_scripts/build.sh#g" Dockerfile.tmp @@ -94,6 +99,9 @@ function main() { cuda102cudnn7) make_cuda102cudnn7 ;; + cuda102cudnn7gcc54) + make_cuda102cudnn7gcc54 + ;; cuda102cudnn8) make_cuda102cudnn8 ;; From 1f6f2235e0751248ee1a684667023b78834f9d1f Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Tue, 20 Jul 2021 14:31:10 +0800 Subject: [PATCH 3/3] Revert "fix cifar label dimension. test=develop (#33475)" (#34242) This reverts commit 6c110344cd759338d7298d27b6b4fce967d93e0a. --- python/paddle/tests/test_dataset_cifar.py | 12 ------------ python/paddle/vision/datasets/cifar.py | 7 +++---- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/python/paddle/tests/test_dataset_cifar.py b/python/paddle/tests/test_dataset_cifar.py index 2e9efddf9712e..abf79fb1e3974 100644 --- a/python/paddle/tests/test_dataset_cifar.py +++ b/python/paddle/tests/test_dataset_cifar.py @@ -32,8 +32,6 @@ def test_main(self): self.assertTrue(data.shape[2] == 3) self.assertTrue(data.shape[1] == 32) self.assertTrue(data.shape[0] == 32) - self.assertTrue(len(label.shape) == 1) - self.assertTrue(label.shape[0] == 1) self.assertTrue(0 <= int(label) <= 9) @@ -51,8 +49,6 @@ def test_main(self): self.assertTrue(data.shape[2] == 3) self.assertTrue(data.shape[1] == 32) self.assertTrue(data.shape[0] == 32) - self.assertTrue(len(label.shape) == 1) - self.assertTrue(label.shape[0] == 1) self.assertTrue(0 <= int(label) <= 9) # test cv2 backend @@ -67,8 +63,6 @@ def test_main(self): self.assertTrue(data.shape[2] == 3) self.assertTrue(data.shape[1] == 32) self.assertTrue(data.shape[0] == 32) - self.assertTrue(len(label.shape) == 1) - self.assertTrue(label.shape[0] == 1) self.assertTrue(0 <= int(label) <= 99) with self.assertRaises(ValueError): @@ -89,8 +83,6 @@ def test_main(self): self.assertTrue(data.shape[2] == 3) self.assertTrue(data.shape[1] == 32) self.assertTrue(data.shape[0] == 32) - self.assertTrue(len(label.shape) == 1) - self.assertTrue(label.shape[0] == 1) self.assertTrue(0 <= int(label) <= 99) @@ -108,8 +100,6 @@ def test_main(self): self.assertTrue(data.shape[2] == 3) self.assertTrue(data.shape[1] == 32) self.assertTrue(data.shape[0] == 32) - self.assertTrue(len(label.shape) == 1) - self.assertTrue(label.shape[0] == 1) self.assertTrue(0 <= int(label) <= 99) # test cv2 backend @@ -124,8 +114,6 @@ def test_main(self): self.assertTrue(data.shape[2] == 3) self.assertTrue(data.shape[1] == 32) self.assertTrue(data.shape[0] == 32) - self.assertTrue(len(label.shape) == 1) - self.assertTrue(label.shape[0] == 1) self.assertTrue(0 <= int(label) <= 99) with self.assertRaises(ValueError): diff --git a/python/paddle/vision/datasets/cifar.py b/python/paddle/vision/datasets/cifar.py index 97ffb239fe7ad..74ae8ef11e3de 100644 --- a/python/paddle/vision/datasets/cifar.py +++ b/python/paddle/vision/datasets/cifar.py @@ -148,8 +148,7 @@ def _load_data(self): six.b('labels'), batch.get(six.b('fine_labels'), None)) assert labels is not None for sample, label in six.moves.zip(data, labels): - self.data.append((sample, - np.array([label]).astype('int64'))) + self.data.append((sample, label)) def __getitem__(self, idx): image, label = self.data[idx] @@ -162,9 +161,9 @@ def __getitem__(self, idx): image = self.transform(image) if self.backend == 'pil': - return image, label.astype('int64') + return image, np.array(label).astype('int64') - return image.astype(self.dtype), label.astype('int64') + return image.astype(self.dtype), np.array(label).astype('int64') def __len__(self): return len(self.data)