diff --git a/paddle/fluid/framework/ipu/CMakeLists.txt b/paddle/fluid/framework/ipu/CMakeLists.txt index 318d3d68a66a7..8f507765bd0ef 100644 --- a/paddle/fluid/framework/ipu/CMakeLists.txt +++ b/paddle/fluid/framework/ipu/CMakeLists.txt @@ -10,6 +10,6 @@ set(POPART_CANONICALIZATION_SRC cc_library(ipu_device SRCS device.cc DEPS enforce popart) cc_library(ipu_utils SRCS ipu_utils.cc DEPS memory framework_proto popart) -cc_library(ipu_build_strategy SRCS ipu_build_strategy.cc DEPS popart graph framework_proto enforce) -cc_library(ipu_backend SRCS ipu_backend.cc DEPS popart graph framework_proto enforce ipu_utils ipu_build_strategy ipu_device graph_helper) +cc_library(ipu_strategy SRCS ipu_strategy.cc DEPS popart graph framework_proto enforce) +cc_library(ipu_backend SRCS ipu_backend.cc DEPS popart graph framework_proto enforce ipu_utils ipu_strategy ipu_device graph_helper) cc_library(popart_canonicalization_utils SRCS ${POPART_CANONICALIZATION_SRC} DEPS framework_proto enforce ipu_utils) diff --git a/paddle/fluid/framework/ipu/ipu_backend.cc b/paddle/fluid/framework/ipu/ipu_backend.cc index 2be5706b81dd6..ac37c4042aeb8 100644 --- a/paddle/fluid/framework/ipu/ipu_backend.cc +++ b/paddle/fluid/framework/ipu/ipu_backend.cc @@ -138,7 +138,7 @@ void IpuBackend::Prepare() { platform::errors::Unavailable("IPU device isn't attached, please call " "IpuBackend::AttachDevice(id) first.")); - if (ipu_build_strategy_ != nullptr && ipu_build_strategy_->is_training_) { + if (ipu_strategy_ != nullptr && ipu_strategy_->is_training_) { VLOG(1) << "Creating TrainingSession from Onnx Model..."; auto popart_optimizer = GetPopartOptimizer(); auto it = tensors_.find(optimizer_.loss_); @@ -368,7 +368,7 @@ void IpuBackend::LowerBody(const ir::Graph* graph) { auto inputs = GetOpInputs(op); auto outputs = op->Output("__outputs__"); // num_outputs training mode 5, inference mode 1 - auto num_outputs = ipu_build_strategy_->is_training_ ? 5 : 1; + auto num_outputs = ipu_strategy_->is_training_ ? 5 : 1; auto epsilon = BOOST_GET_CONST(float, op->GetAttr("epsilon")); auto momentum = BOOST_GET_CONST(float, op->GetAttr("momentum")); auto result = builder_->aiOnnxOpset11().batchnormalization( diff --git a/paddle/fluid/framework/ipu/ipu_backend.h b/paddle/fluid/framework/ipu/ipu_backend.h index 7b94ff91db112..96b2f131c85c4 100644 --- a/paddle/fluid/framework/ipu/ipu_backend.h +++ b/paddle/fluid/framework/ipu/ipu_backend.h @@ -32,7 +32,7 @@ limitations under the License. */ #include "paddle/fluid/framework/feed_fetch_type.h" #include "paddle/fluid/framework/ipu/device.h" -#include "paddle/fluid/framework/ipu/ipu_build_strategy.h" +#include "paddle/fluid/framework/ipu/ipu_strategy.h" #include "paddle/fluid/framework/ir/graph.h" #include "paddle/fluid/framework/scope.h" #include "paddle/fluid/framework/tensor.h" @@ -42,7 +42,7 @@ namespace paddle { namespace framework { namespace ipu { -using ipu::IpuBuildStrategy; +using ipu::IpuStrategy; struct Optimizer { std::string type_; std::string loss_; @@ -88,8 +88,8 @@ class IpuBackend { auto *GetLRFromScope(const std::string &name) { return scope_->GetVar(name); } - void SetIpuBuildStrategy(const IpuBuildStrategy &strategy) { - ipu_build_strategy_ = &strategy; + void SetIpuStrategy(const IpuStrategy &strategy) { + ipu_strategy_ = &strategy; } size_t GetNumDevices(); std::vector GetDeviceIds(); @@ -114,7 +114,7 @@ class IpuBackend { Optimizer optimizer_; bool is_prepared_ = false; const Scope *scope_ = nullptr; - const IpuBuildStrategy *ipu_build_strategy_ = nullptr; + const IpuStrategy *ipu_strategy_ = nullptr; std::vector inputs_; std::vector outputs_; diff --git a/paddle/fluid/framework/ipu/ipu_build_strategy.cc b/paddle/fluid/framework/ipu/ipu_strategy.cc similarity index 90% rename from paddle/fluid/framework/ipu/ipu_build_strategy.cc rename to paddle/fluid/framework/ipu/ipu_strategy.cc index a9936f1941801..97edfda046f4d 100644 --- a/paddle/fluid/framework/ipu/ipu_build_strategy.cc +++ b/paddle/fluid/framework/ipu/ipu_strategy.cc @@ -12,7 +12,7 @@ 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. */ -#include "paddle/fluid/framework/ipu/ipu_build_strategy.h" +#include "paddle/fluid/framework/ipu/ipu_strategy.h" #include "paddle/fluid/framework/ir/ipu/ipu_graph_builder_pass.h" #include @@ -20,8 +20,6 @@ limitations under the License. */ namespace paddle { namespace framework { -namespace ipu { - -} +namespace ipu {} } } diff --git a/paddle/fluid/framework/ipu/ipu_build_strategy.h b/paddle/fluid/framework/ipu/ipu_strategy.h similarity index 97% rename from paddle/fluid/framework/ipu/ipu_build_strategy.h rename to paddle/fluid/framework/ipu/ipu_strategy.h index b7c7675b5a4f1..2dad6302fe682 100644 --- a/paddle/fluid/framework/ipu/ipu_build_strategy.h +++ b/paddle/fluid/framework/ipu/ipu_strategy.h @@ -34,7 +34,7 @@ namespace framework { namespace ipu { -struct IpuBuildStrategy { +struct IpuStrategy { bool is_training_ = true; popart::SessionOptions popart_options_; }; diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index fbfb1808bb5d7..6e14fa8e60157 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -3208,19 +3208,19 @@ All parameter, weight, gradient are variables in Paddle. .def("device_count", &ParallelExecutor::DeviceCount); #ifdef PADDLE_WITH_IPU - py::class_>( - m, "IpuBackend") + py::class_>(m, "IpuBackend") .def(py::init(&ipu::IpuBackend::GetInstance)) .def("set_scope", &ipu::IpuBackend::SetScope) - .def("set_ipu_build_strategy", &ipu::IpuBackend::SetIpuBuildStrategy); + .def("set_ipu_strategy", &ipu::IpuBackend::SetIpuStrategy); // TODO(xiaobingw): maybe refactor at future - py::class_(m, "IpuBuildStrategy") + py::class_(m, "IpuStrategy") .def(py::init()) .def_property( "is_training", - [](const ipu::IpuBuildStrategy &self) { return self.is_training_; }, - [](ipu::IpuBuildStrategy &self, bool is_training) { + [](const ipu::IpuStrategy &self) { return self.is_training_; }, + [](ipu::IpuStrategy &self, bool is_training) { self.is_training_ = is_training; }); #endif diff --git a/python/paddle/fluid/compiler.py b/python/paddle/fluid/compiler.py index 64cf24f3cae82..a97af1ab5f7f7 100644 --- a/python/paddle/fluid/compiler.py +++ b/python/paddle/fluid/compiler.py @@ -489,14 +489,14 @@ class IpuCompiler(object): Args: program(framework.Program): This argument is the Program being executed. scope: This argument is the scope which contains model parameters. - ipu_build_strategy: This argument is used to build the program with the + ipu_strategy: This argument is used to build the program with the specified options, such as operators' replacement, dtype, etc. Returns: framework.Program """ - def __init__(self, program, scope=None, ipu_build_strategy=None): + def __init__(self, program, scope=None, ipu_strategy=None): if not isinstance(program, framework.Program): raise TypeError( "The type of program is wrong, expected Program, but got %s" % @@ -513,14 +513,14 @@ def __init__(self, program, scope=None, ipu_build_strategy=None): else: self._scope = paddle.static.global_scope() - if ipu_build_strategy is not None: - self._ipu_build_strategy = ipu_build_strategy + if ipu_strategy is not None: + self._ipu_strategy = ipu_strategy else: - self._ipu_build_strategy = get_ipu_build_strategy() + self._ipu_strategy = get_ipu_strategy() self._backend = core.IpuBackend() self._backend.set_scope(self._scope) - self._backend.set_ipu_build_strategy(self._ipu_build_strategy) + self._backend.set_ipu_strategy(self._ipu_strategy) self._graph_passes = [ "optimizer_extract_pass", "forward_graph_extract_pass", "popart_canonicalization_pass" @@ -550,17 +550,17 @@ def compile(self, feed_list, fetch_list, scope=None): return program -def get_ipu_build_strategy(): +def get_ipu_strategy(): """ - Create and return IpuBuildStrategy instance. We get IpuBuildStrategy from - python side, and the set by IpuBackend.set_ipu_build_strategy. + Create and return IpuStrategy instance. We get IpuStrategy from + python side, and the set by IpuBackend.set_ipu_strategy. """ if not core.is_compiled_with_ipu(): raise ValueError( - "Can't get ipu_build_strategy, since PaddlePaddle is not compiled" \ + "Can't get ipu_strategy, since PaddlePaddle is not compiled" \ " with IPU" ) - ipu_build_strategy = core.IpuBuildStrategy() + ipu_strategy = core.IpuStrategy() - return ipu_build_strategy + return ipu_strategy diff --git a/python/paddle/fluid/tests/unittests/ipu/ernie_training.py b/python/paddle/fluid/tests/unittests/ipu/ernie_training.py index 8bbad84124be4..0712fb1fdff50 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ernie_training.py +++ b/python/paddle/fluid/tests/unittests/ipu/ernie_training.py @@ -787,9 +787,9 @@ def get_task_output(self, task, task_labels): main_prog = paddle.static.default_main_program() if args.run_on_ipu: - ipu_build_strategy = compiler.get_ipu_build_strategy() + ipu_strategy = compiler.get_ipu_strategy() ipu_compiler = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy) + main_prog, ipu_strategy=ipu_strategy) program = ipu_compiler.compile(feed_list, fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/ipu_batch_norm_test.py b/python/paddle/fluid/tests/unittests/ipu/ipu_batch_norm_test.py index 403f4bd0ceca3..c9e90e2c16c1d 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ipu_batch_norm_test.py +++ b/python/paddle/fluid/tests/unittests/ipu/ipu_batch_norm_test.py @@ -59,11 +59,11 @@ def _test(self, run_ipu=True): if run_ipu: feed_list = [image.name] fetch_list = [loss.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = True + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = True program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/ipu_conv_test.py b/python/paddle/fluid/tests/unittests/ipu/ipu_conv_test.py index bba677e826ad1..91c2d0b905939 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ipu_conv_test.py +++ b/python/paddle/fluid/tests/unittests/ipu/ipu_conv_test.py @@ -58,11 +58,11 @@ def _test(self, run_ipu=True): if run_ipu: feed_list = [image.name] fetch_list = [loss.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = True + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = True program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/ipu_graph_with_variable.py b/python/paddle/fluid/tests/unittests/ipu/ipu_graph_with_variable.py index d4c7eea2c23f7..1c8acd9847696 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ipu_graph_with_variable.py +++ b/python/paddle/fluid/tests/unittests/ipu/ipu_graph_with_variable.py @@ -23,7 +23,7 @@ y = paddle.static.nn.fc(x=x, size=2, name='y') # 运行期:先运行一次startup program初始化网络参数,然后调用飞桨的Executor和CompiledProgram API运行网络。 -place = paddle.IPUPlace() # 使用何种设备运行网络,IPUPlace表示使用IPU运行 +place = paddle.IPUPlace(0) # 使用何种设备运行网络,IPUPlace表示使用IPU运行 executor = paddle.static.Executor(place) # 创建执行器 compiled_program = paddle.static.CompiledProgram( paddle.static.default_startup_program()) diff --git a/python/paddle/fluid/tests/unittests/ipu/ipu_groupnorm_test.py b/python/paddle/fluid/tests/unittests/ipu/ipu_groupnorm_test.py index 626ea3a401b0f..3e8a85c3700cd 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ipu_groupnorm_test.py +++ b/python/paddle/fluid/tests/unittests/ipu/ipu_groupnorm_test.py @@ -69,11 +69,11 @@ def _test(self, run_ipu=True): if run_ipu: feed_list = [image.name] fetch_list = [loss.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = True + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = True program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/ipu_pool_test.py b/python/paddle/fluid/tests/unittests/ipu/ipu_pool_test.py index 47e71aee4792b..cc4cafd8dccf5 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ipu_pool_test.py +++ b/python/paddle/fluid/tests/unittests/ipu/ipu_pool_test.py @@ -65,11 +65,11 @@ def _test(self, run_ipu=True): if run_ipu: feed_list = [image.name] fetch_list = [loss.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = True + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = True program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/ipu_relu_test.py b/python/paddle/fluid/tests/unittests/ipu/ipu_relu_test.py index 9dd7fc4abf30d..738fcac92c04f 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ipu_relu_test.py +++ b/python/paddle/fluid/tests/unittests/ipu/ipu_relu_test.py @@ -52,12 +52,12 @@ def _test(self, run_ipu=True): if run_ipu: feed_list = [image.name] fetch_list = [out.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = False + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = False print(main_prog) program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) print(program) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/ipu_sgd_test.py b/python/paddle/fluid/tests/unittests/ipu/ipu_sgd_test.py index 578bd3a7377f4..47a8cbbb4e786 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ipu_sgd_test.py +++ b/python/paddle/fluid/tests/unittests/ipu/ipu_sgd_test.py @@ -57,11 +57,11 @@ def _test_sgd(self, run_ipu=True): if run_ipu: feed_list = [image.name] fetch_list = [loss.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = True + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = True program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/ipu_training_test.py b/python/paddle/fluid/tests/unittests/ipu/ipu_training_test.py index 40a5d86448cf6..188eb8c21270c 100644 --- a/python/paddle/fluid/tests/unittests/ipu/ipu_training_test.py +++ b/python/paddle/fluid/tests/unittests/ipu/ipu_training_test.py @@ -61,11 +61,10 @@ main_prog = paddle.static.default_main_program() if run_on_ipu: - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = False # default True + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = False # default True program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/test_mul_op.py b/python/paddle/fluid/tests/unittests/ipu/test_mul_op.py index 6f5aae6dd894b..e814d08dbd50f 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_mul_op.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_mul_op.py @@ -51,11 +51,11 @@ def _test_mul(self, run_ipu=True): if run_ipu: feed_list = [] fetch_list = [out.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = False + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = False program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/test_pow_op.py b/python/paddle/fluid/tests/unittests/ipu/test_pow_op.py index b0085e2c7da82..5c5ca96b38a6c 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_pow_op.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_pow_op.py @@ -52,11 +52,11 @@ def _test_pow(self, run_ipu=True): if run_ipu: feed_list = [] fetch_list = [out.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = False + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = False program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/test_softmax_op.py b/python/paddle/fluid/tests/unittests/ipu/test_softmax_op.py index a05362696b042..ca55735457c1f 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_softmax_op.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_softmax_op.py @@ -53,11 +53,11 @@ def _test_softmax(self, run_ipu=True): if run_ipu: feed_list = [a.name] fetch_list = [out.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = False + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = False program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog diff --git a/python/paddle/fluid/tests/unittests/ipu/test_sum_op.py b/python/paddle/fluid/tests/unittests/ipu/test_sum_op.py index ff40fa3610178..6d66dbb400bb6 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_sum_op.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_sum_op.py @@ -53,11 +53,11 @@ def _test_sum(self, run_ipu=True): if run_ipu: feed_list = [] fetch_list = [out.name] - ipu_build_strategy = compiler.get_ipu_build_strategy() - ipu_build_strategy.is_training = False + ipu_strategy = compiler.get_ipu_strategy() + ipu_strategy.is_training = False program = compiler.IpuCompiler( - main_prog, ipu_build_strategy=ipu_build_strategy).compile( - feed_list, fetch_list) + main_prog, ipu_strategy=ipu_strategy).compile(feed_list, + fetch_list) else: program = main_prog