Compare commits
8 Commits
develop
...
musl/fix_f
Author | SHA1 | Date |
---|---|---|
|
3b31fe0f38 | 4 years ago |
|
ed37fdd925 | 4 years ago |
|
67d95abfef | 4 years ago |
|
d63ab6b6f9 | 4 years ago |
|
bb8fc3916f | 4 years ago |
|
5b20131c96 | 4 years ago |
|
3b1b2f5fa3 | 4 years ago |
|
cc8f0516bf | 4 years ago |
@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2020 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
|
||||
import paddle.fluid as fluid
|
||||
|
||||
from test_desc_clone import get_model, program_equal
|
||||
|
||||
|
||||
def get_transpiler(trainer_id, main_program, pserver_endpoints, trainers):
|
||||
t = fluid.DistributeTranspiler()
|
||||
t.transpile(
|
||||
trainer_id=trainer_id,
|
||||
program=main_program,
|
||||
pservers=pserver_endpoints,
|
||||
trainers=trainers)
|
||||
return t
|
||||
|
||||
|
||||
class TestDistMnist(unittest.TestCase):
|
||||
def test_desc_clone(self):
|
||||
paddle.enable_static()
|
||||
get_model(batch_size=20)
|
||||
|
||||
pserver_endpoints = "127.0.0.1:9123"
|
||||
trainers = 1
|
||||
current_endpoint = "127.0.0.1:9123"
|
||||
t = get_transpiler(0,
|
||||
fluid.default_main_program(), pserver_endpoints,
|
||||
trainers)
|
||||
|
||||
pserver_prog = t.get_pserver_program(current_endpoint)
|
||||
startup_prog = t.get_startup_program(current_endpoint, pserver_prog)
|
||||
main = pserver_prog.clone()
|
||||
startup = startup_prog.clone()
|
||||
self.assertTrue(program_equal(main, pserver_prog))
|
||||
self.assertTrue(program_equal(startup, startup_prog))
|
@ -0,0 +1,81 @@
|
||||
# Copyright (c) 2020 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 sys
|
||||
|
||||
import paddle
|
||||
import paddle.fluid as fluid
|
||||
import paddle.fluid.layers as layers
|
||||
from paddle.fluid.layers.io import ListenAndServ
|
||||
from paddle.fluid.layers.io import Recv
|
||||
from paddle.fluid.layers.io import Send
|
||||
import paddle.fluid.layers.ops as ops
|
||||
|
||||
|
||||
class TestProgram2Code(unittest.TestCase):
|
||||
@unittest.skipIf(sys.platform == "win32",
|
||||
"Windows does not support distribution")
|
||||
def test_print(self):
|
||||
paddle.enable_static()
|
||||
place = fluid.CPUPlace()
|
||||
self.init_serv(place)
|
||||
self.init_client(place, 9123)
|
||||
|
||||
def init_serv(self, place):
|
||||
main = fluid.Program()
|
||||
|
||||
with fluid.program_guard(main):
|
||||
serv = ListenAndServ("127.0.0.1:0", ["X"], optimizer_mode=False)
|
||||
with serv.do():
|
||||
out_var = main.global_block().create_var(
|
||||
name="scale_0.tmp_0",
|
||||
psersistable=True,
|
||||
dtype="float32",
|
||||
shape=[32, 32])
|
||||
x = layers.data(
|
||||
shape=[32, 32],
|
||||
dtype='float32',
|
||||
name="X",
|
||||
append_batch_size=False)
|
||||
fluid.initializer.Constant(value=1.0)(x, main.global_block())
|
||||
ops._scale(x=x, scale=10.0, out=out_var)
|
||||
|
||||
print(main)
|
||||
|
||||
def init_client(self, place, port):
|
||||
main = fluid.Program()
|
||||
with fluid.program_guard(main):
|
||||
x = layers.data(
|
||||
shape=[32, 32],
|
||||
dtype='float32',
|
||||
name='X',
|
||||
append_batch_size=False)
|
||||
fluid.initializer.Constant(value=2.3)(x, main.global_block())
|
||||
get_var = main.global_block().create_var(
|
||||
name="scale_0.tmp_0", # server side var
|
||||
dtype="float32",
|
||||
persistable=False,
|
||||
shape=[32, 32])
|
||||
fluid.initializer.Constant(value=2.3)(get_var, main.global_block())
|
||||
Send("127.0.0.1:%d" % port, [x])
|
||||
o = Recv("127.0.0.1:%d" % port, [get_var])
|
||||
|
||||
print(main)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Binary file not shown.
Loading…
Reference in new issue