Skip to content

Commit 54a7357

Browse files
authored
Feature/install check (#16044)
* test=develop, add install check * test=develop, add install check scripts * test=develop, refine language * test=develop, add api spec * test=develop, change cdn to bj to pass ci
1 parent 9993651 commit 54a7357

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

paddle/fluid/API.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ paddle.fluid.unique_name.guard (ArgSpec(args=['new_generator'], varargs=None, ke
520520
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'))
521521
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'))
522522
paddle.fluid.Scope Scope() -> paddle.fluid.core._Scope
523+
paddle.fluid.install_check.run_check (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '66b7c84a17ed32fec2df9628367be2b9'))
523524
paddle.reader.cache (ArgSpec(args=['reader'], varargs=None, keywords=None, defaults=None), ('document', '1676886070eb607cb608f7ba47be0d3c'))
524525
paddle.reader.map_readers (ArgSpec(args=['func'], varargs='readers', keywords=None, defaults=None), ('document', '77cbadb09df588e21e5cc0819b69c87d'))
525526
paddle.reader.buffered (ArgSpec(args=['reader', 'size'], varargs=None, keywords=None, defaults=None), ('document', '0d6186f109feceb99f60ec50a0a624cb'))

python/paddle/fluid/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@
5959
from . import compiler
6060
from .compiler import *
6161
from paddle.fluid.layers.math_op_patch import monkey_patch_variable
62+
from . import install_check
6263

6364
Tensor = LoDTensor
6465

6566
__all__ = framework.__all__ + executor.__all__ + \
6667
trainer.__all__ + inferencer.__all__ + transpiler.__all__ + \
6768
parallel_executor.__all__ + lod_tensor.__all__ + \
68-
data_feed_desc.__all__ + async_executor.__all__ + compiler.__all__ + [
69+
data_feed_desc.__all__ + async_executor.__all__ + compiler.__all__ + [
6970
'io',
7071
'initializer',
7172
'layers',
@@ -91,6 +92,7 @@
9192
'unique_name',
9293
'recordio_writer',
9394
'Scope',
95+
'install_check',
9496
]
9597

9698

python/paddle/fluid/install_check.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from .framework import Program, program_guard, unique_name, default_startup_program
16+
from .param_attr import ParamAttr
17+
from .initializer import Constant
18+
from . import layers
19+
from . import backward
20+
from .imperative import Layer, nn
21+
from . import executor
22+
23+
from . import core
24+
import numpy as np
25+
26+
__all__ = ['run_check']
27+
28+
29+
class SimpleLayer(Layer):
30+
def __init__(self, name_scope):
31+
super(SimpleLayer, self).__init__(name_scope)
32+
self._fc1 = nn.FC(self.full_name(),
33+
3,
34+
ParamAttr(initializer=Constant(value=0.1)))
35+
36+
def forward(self, inputs):
37+
x = self._fc1(inputs)
38+
x = layers.reduce_sum(x)
39+
return x
40+
41+
42+
def run_check():
43+
''' intall check to verify if install is success
44+
45+
This func should not be called only if you need to verify installation
46+
'''
47+
print("Running Verify Fluid Program ... ")
48+
prog = Program()
49+
startup_prog = Program()
50+
scope = core.Scope()
51+
with executor.scope_guard(scope):
52+
with program_guard(prog, startup_prog):
53+
with unique_name.guard():
54+
np_inp = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
55+
inp = layers.data(
56+
name="inp", shape=[2, 2], append_batch_size=False)
57+
simple_layer = SimpleLayer("simple_layer")
58+
out = simple_layer(inp)
59+
param_grads = backward.append_backward(
60+
out, parameter_list=[simple_layer._fc1._w.name])[0]
61+
exe = executor.Executor(core.CPUPlace(
62+
) if not core.is_compiled_with_cuda() else core.CUDAPlace(0))
63+
exe.run(default_startup_program())
64+
exe.run(feed={inp.name: np_inp},
65+
fetch_list=[out.name, param_grads[1].name])
66+
67+
print(
68+
"Your Paddle Fluid is installed successfully! Let's start deep Learning with Paddle Fluid now"
69+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import print_function
16+
import unittest
17+
import paddle.fluid as fluid
18+
19+
20+
class TestInstallCheck(unittest.TestCase):
21+
def test_install_check(self):
22+
fluid.install_check.run_check()

0 commit comments

Comments
 (0)