diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 032da0cad85ce43ab2630123f9f2cfd8dee4224e..7d3f49a7e1ff4ee1ffa7b31bc34f9db08e266909 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -520,6 +520,7 @@ paddle.fluid.unique_name.guard (ArgSpec(args=['new_generator'], varargs=None, ke paddle.fluid.recordio_writer.convert_reader_to_recordio_file (ArgSpec(args=['filename', 'reader_creator', 'feeder', 'compressor', 'max_num_records', 'feed_order'], varargs=None, keywords=None, defaults=(Compressor.Snappy, 1000, None)), ('document', '65c7523e86f0c50bb729b01667f36310')) paddle.fluid.recordio_writer.convert_reader_to_recordio_files (ArgSpec(args=['filename', 'batch_per_file', 'reader_creator', 'feeder', 'compressor', 'max_num_records', 'feed_order'], varargs=None, keywords=None, defaults=(Compressor.Snappy, 1000, None)), ('document', 'bc643f0f5f1b9db57ff0d8a57d379bd7')) paddle.fluid.Scope Scope() -> paddle.fluid.core._Scope +paddle.fluid.install_check.run_check (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '66b7c84a17ed32fec2df9628367be2b9')) paddle.reader.cache (ArgSpec(args=['reader'], varargs=None, keywords=None, defaults=None), ('document', '1676886070eb607cb608f7ba47be0d3c')) paddle.reader.map_readers (ArgSpec(args=['func'], varargs='readers', keywords=None, defaults=None), ('document', '77cbadb09df588e21e5cc0819b69c87d')) paddle.reader.buffered (ArgSpec(args=['reader', 'size'], varargs=None, keywords=None, defaults=None), ('document', '0d6186f109feceb99f60ec50a0a624cb')) diff --git a/python/paddle/fluid/__init__.py b/python/paddle/fluid/__init__.py index 63b7b28948a783bc5910d53f6e65a8c09d77bdb1..18f01ca1374a24cec3bf882d347596dd38f4fd21 100644 --- a/python/paddle/fluid/__init__.py +++ b/python/paddle/fluid/__init__.py @@ -59,13 +59,14 @@ from .parallel_executor import * from . import compiler from .compiler import * from paddle.fluid.layers.math_op_patch import monkey_patch_variable +from . import install_check Tensor = LoDTensor __all__ = framework.__all__ + executor.__all__ + \ trainer.__all__ + inferencer.__all__ + transpiler.__all__ + \ parallel_executor.__all__ + lod_tensor.__all__ + \ - data_feed_desc.__all__ + async_executor.__all__ + compiler.__all__ + [ + data_feed_desc.__all__ + async_executor.__all__ + compiler.__all__ + [ 'io', 'initializer', 'layers', @@ -91,6 +92,7 @@ __all__ = framework.__all__ + executor.__all__ + \ 'unique_name', 'recordio_writer', 'Scope', + 'install_check', ] diff --git a/python/paddle/fluid/install_check.py b/python/paddle/fluid/install_check.py new file mode 100644 index 0000000000000000000000000000000000000000..3569a8bc357daf9408e8ae3eb53ad9d2942cfeaa --- /dev/null +++ b/python/paddle/fluid/install_check.py @@ -0,0 +1,69 @@ +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .framework import Program, program_guard, unique_name, default_startup_program +from .param_attr import ParamAttr +from .initializer import Constant +from . import layers +from . import backward +from .imperative import Layer, nn +from . import executor + +from . import core +import numpy as np + +__all__ = ['run_check'] + + +class SimpleLayer(Layer): + def __init__(self, name_scope): + super(SimpleLayer, self).__init__(name_scope) + self._fc1 = nn.FC(self.full_name(), + 3, + ParamAttr(initializer=Constant(value=0.1))) + + def forward(self, inputs): + x = self._fc1(inputs) + x = layers.reduce_sum(x) + return x + + +def run_check(): + ''' intall check to verify if install is success + + This func should not be called only if you need to verify installation + ''' + print("Running Verify Fluid Program ... ") + prog = Program() + startup_prog = Program() + scope = core.Scope() + with executor.scope_guard(scope): + with program_guard(prog, startup_prog): + with unique_name.guard(): + np_inp = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32) + inp = layers.data( + name="inp", shape=[2, 2], append_batch_size=False) + simple_layer = SimpleLayer("simple_layer") + out = simple_layer(inp) + param_grads = backward.append_backward( + out, parameter_list=[simple_layer._fc1._w.name])[0] + exe = executor.Executor(core.CPUPlace( + ) if not core.is_compiled_with_cuda() else core.CUDAPlace(0)) + exe.run(default_startup_program()) + exe.run(feed={inp.name: np_inp}, + fetch_list=[out.name, param_grads[1].name]) + + print( + "Your Paddle Fluid is installed successfully! Let's start deep Learning with Paddle Fluid now" + ) diff --git a/python/paddle/fluid/tests/unittests/test_install_check.py b/python/paddle/fluid/tests/unittests/test_install_check.py new file mode 100644 index 0000000000000000000000000000000000000000..5802e2ed0a3dfd7e1c45e91037a6c40b1b6bd2fc --- /dev/null +++ b/python/paddle/fluid/tests/unittests/test_install_check.py @@ -0,0 +1,22 @@ +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function +import unittest +import paddle.fluid as fluid + + +class TestInstallCheck(unittest.TestCase): + def test_install_check(self): + fluid.install_check.run_check()