提交 5920d69d 编写于 作者: S ShenLiang 提交者: Yi Liu

Avoid treating broadcast as initialization operation (#19857)

* treat broadcast as non-initial, test=develop

* rename the class name

* rename the class name, test=develop
上级 c670058a
...@@ -1833,6 +1833,11 @@ class Block(object): ...@@ -1833,6 +1833,11 @@ class Block(object):
init_ops = [] init_ops = []
for op in block.ops: for op in block.ops:
if var.name in op.output_arg_names: if var.name in op.output_arg_names:
# In startup_program, "c_broadcast" and "c_sync_comm_stream"
# are treated as initialization ops that cause error.
# Think of "c_broadcast" and "c_sync_comm_stream" as a special case here.
if op.type in ["c_broadcast", "c_sync_comm_stream"]:
continue
init_ops.append(op) init_ops.append(op)
return init_ops return init_ops
......
...@@ -39,6 +39,7 @@ if(WIN32) ...@@ -39,6 +39,7 @@ if(WIN32)
LIST(REMOVE_ITEM TEST_OPS test_boxps) LIST(REMOVE_ITEM TEST_OPS test_boxps)
LIST(REMOVE_ITEM TEST_OPS test_trainer_desc) LIST(REMOVE_ITEM TEST_OPS test_trainer_desc)
LIST(REMOVE_ITEM TEST_OPS test_multiprocess_reader_exception) LIST(REMOVE_ITEM TEST_OPS test_multiprocess_reader_exception)
LIST(REMOVE_ITEM TEST_OPS test_avoid_twice_initialization)
endif() endif()
LIST(REMOVE_ITEM TEST_OPS test_launch) LIST(REMOVE_ITEM TEST_OPS test_launch)
......
# 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 TestAvoidTwiceInitialization(unittest.TestCase):
def test_avoid_twice_initialization(self):
cur_program = fluid.Program()
cur_block = cur_program.current_block()
var = cur_block.create_parameter(
initializer=fluid.initializer.Constant(value=0.01),
shape=[2, 2],
dtype='float32',
name='var_a')
cur_block.append_op(
type="c_broadcast",
inputs={"X": [var]},
outputs={"Out": [var]},
attrs={'root': 0,
'ring_id': 0,
'use_calc_stream': False})
cur_block.append_op(
type="c_sync_comm_stream",
inputs={'X': [var]},
outputs={'Out': [var]},
attrs={'ring_id': 0})
var2 = cur_block.create_parameter(
initializer=fluid.initializer.Constant(value=0.01),
shape=[2, 2],
dtype='float32',
name='var_a')
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册