diff --git a/paddle/fluid/framework/feed_fetch_method.cc b/paddle/fluid/framework/feed_fetch_method.cc index 1f2f645f97dc8..7a62b5563f30a 100644 --- a/paddle/fluid/framework/feed_fetch_method.cc +++ b/paddle/fluid/framework/feed_fetch_method.cc @@ -19,7 +19,7 @@ limitations under the License. */ #include "glog/logging.h" PHI_DECLARE_bool(enable_new_ir_in_executor); -PHI_DECLARE_bool(enable_new_ir_api); +PHI_DECLARE_bool(enable_pir_api); namespace phi { class DenseTensor; diff --git a/paddle/fluid/framework/new_executor/standalone_executor.cc b/paddle/fluid/framework/new_executor/standalone_executor.cc index 99b42bee8b73f..f06bee2c884e3 100644 --- a/paddle/fluid/framework/new_executor/standalone_executor.cc +++ b/paddle/fluid/framework/new_executor/standalone_executor.cc @@ -28,7 +28,7 @@ #include "paddle/pir/pass/pass_manager.h" PHI_DECLARE_bool(enable_new_ir_in_executor); -PHI_DECLARE_bool(enable_new_ir_api); +PHI_DECLARE_bool(enable_pir_api); PHI_DECLARE_bool(new_ir_apply_inplace_pass); namespace paddle { @@ -55,7 +55,7 @@ StandaloneExecutor::StandaloneExecutor(const platform::Place& place, const std::string& job_type = job->Type(); std::shared_ptr program = nullptr; std::shared_ptr<::pir::Program> ir_program = nullptr; - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { ir_program = plan_.IrProgram(job_type); } else { program = std::make_shared(*(plan_.Program(job_type))); @@ -69,7 +69,7 @@ StandaloneExecutor::StandaloneExecutor(const platform::Place& place, micro_batch_id, micro_batch_num)); - if (micro_batch_num > 1 && !FLAGS_enable_new_ir_api) { + if (micro_batch_num > 1 && !FLAGS_enable_pir_api) { SetColAttrForFeedFetchOps(program, micro_batch_num, micro_batch_id); } @@ -80,7 +80,7 @@ StandaloneExecutor::StandaloneExecutor(const platform::Place& place, // TODO(phlrain) we only support cpu for now if (FLAGS_enable_new_ir_in_executor) { std::shared_ptr<::pir::Program> base_program = ir_program; - if (!FLAGS_enable_new_ir_api) { + if (!FLAGS_enable_pir_api) { VLOG(6) << "begin to translate" << std::endl; base_program = paddle::TranslateLegacyProgramToProgram(*program); } diff --git a/paddle/fluid/prim/api/auto_code_generated/tensor_operants_gen.py b/paddle/fluid/prim/api/auto_code_generated/tensor_operants_gen.py index 783066f0fc906..0bc050f00d4a0 100644 --- a/paddle/fluid/prim/api/auto_code_generated/tensor_operants_gen.py +++ b/paddle/fluid/prim/api/auto_code_generated/tensor_operants_gen.py @@ -214,7 +214,7 @@ class StaticTensorOperants : public TensorOperantsBase { #include "paddle/fluid/primitive/backend/backend.h" #include "paddle/fluid/primitive/type/lazy_tensor.h" -PHI_DECLARE_bool(enable_new_ir_api); +PHI_DECLARE_bool(enable_pir_api); """ @@ -227,7 +227,7 @@ class StaticTensorOperants : public TensorOperantsBase { using LazyTensor = paddle::primitive::LazyTensor; Tensor StaticTensorOperants::add(const Tensor& x, const Scalar& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::add(x, paddle::primitive::backend::full(x.shape(), y, x.dtype(), x.place())); } else { return paddle::prim::add(x, paddle::prim::full(x.shape(), y, x.dtype(), x.place())); @@ -235,7 +235,7 @@ class StaticTensorOperants : public TensorOperantsBase { } Tensor StaticTensorOperants::subtract(const Tensor& x, const Scalar& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::subtract(x, paddle::primitive::backend::full(x.shape(), y, x.dtype(), x.place())); } else { return paddle::prim::subtract(x, paddle::prim::full(x.shape(), y, x.dtype(), x.place())); @@ -243,7 +243,7 @@ class StaticTensorOperants : public TensorOperantsBase { } Tensor StaticTensorOperants::multiply(const Tensor& x, const Scalar& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::scale(x, y, 0.0f, true); } else { return paddle::prim::scale(x, y, 0.0f, true); @@ -251,7 +251,7 @@ class StaticTensorOperants : public TensorOperantsBase { } Tensor StaticTensorOperants::divide(const Tensor& x, const Scalar& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::divide(x, paddle::primitive::backend::full(x.shape(), y, x.dtype(), x.place())); } else { return paddle::prim::divide(x, paddle::prim::full(x.shape(), y, x.dtype(), x.place())); @@ -259,7 +259,7 @@ class StaticTensorOperants : public TensorOperantsBase { } Tensor StaticTensorOperants::add(const Scalar& x, const Tensor& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::add(paddle::primitive::backend::full(y.shape(), x, y.dtype(), y.place()), y); } else { return paddle::prim::add(paddle::prim::full(y.shape(), x, y.dtype(), y.place()), y); @@ -268,7 +268,7 @@ class StaticTensorOperants : public TensorOperantsBase { Tensor StaticTensorOperants::subtract(const Scalar& x, const Tensor& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::subtract(paddle::primitive::backend::full(y.shape(), x, y.dtype(), y.place()), y); } else { return paddle::prim::subtract(paddle::prim::full(y.shape(), x, y.dtype(), y.place()), y); @@ -276,7 +276,7 @@ class StaticTensorOperants : public TensorOperantsBase { } Tensor StaticTensorOperants::multiply(const Scalar& x, const Tensor& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::scale(y, x, 0.0f, true); } else { return paddle::prim::scale(y, x, 0.0f, true); @@ -284,7 +284,7 @@ class StaticTensorOperants : public TensorOperantsBase { } Tensor StaticTensorOperants::divide(const Scalar& x, const Tensor& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::divide(paddle::primitive::backend::full(y.shape(), x, y.dtype(), y.place()), y); } else { return paddle::prim::divide(paddle::prim::full(y.shape(), x, y.dtype(), y.place()), y); @@ -292,7 +292,7 @@ class StaticTensorOperants : public TensorOperantsBase { } Tensor StaticTensorOperants::pow(const Tensor& x, const Tensor& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::elementwise_pow(x, y); } else { return paddle::prim::elementwise_pow(x, y); @@ -300,7 +300,7 @@ class StaticTensorOperants : public TensorOperantsBase { } Tensor StaticTensorOperants::pow(const Tensor& x, const Scalar& y) { - if (FLAGS_enable_new_ir_api) { + if (FLAGS_enable_pir_api) { return paddle::primitive::backend::elementwise_pow(x, paddle::primitive::backend::full(x.shape(), y, x.dtype(), x.place())); } else { return paddle::prim::elementwise_pow(x, paddle::prim::full(x.shape(), y, x.dtype(), x.place())); @@ -393,7 +393,7 @@ def gene_static_tensor_func_call(self): ) static_func_parameters = self.get_func_args() - static_tensor_func_call = f"""if (FLAGS_enable_new_ir_api) {{ + static_tensor_func_call = f"""if (FLAGS_enable_pir_api) {{ return {backend_static_func_name}({static_func_parameters}); }} else {{ return {prim_static_func_name}({static_func_parameters}); diff --git a/paddle/phi/core/flags.cc b/paddle/phi/core/flags.cc index e02868d5e2c1b..ce03cdb3f4d69 100644 --- a/paddle/phi/core/flags.cc +++ b/paddle/phi/core/flags.cc @@ -1278,15 +1278,13 @@ PHI_DEFINE_EXPORTED_bool(enable_new_ir_in_executor, /** * Using new IR API in Python - * Name: enable_new_ir_api + * Name: enable_pir_api * Since Version: 2.6.0 * Value Range: bool, default=false * Example: * Note: If Ture, New IR API will be used in Python */ -PHI_DEFINE_EXPORTED_bool(enable_new_ir_api, - false, - "Enable new IR API in Python"); +PHI_DEFINE_EXPORTED_bool(enable_pir_api, false, "Enable new IR API in Python"); /** * Using new IR in executor FLAG diff --git a/python/paddle/base/framework.py b/python/paddle/base/framework.py index 0440af415a7d0..d3f17ea6435e9 100644 --- a/python/paddle/base/framework.py +++ b/python/paddle/base/framework.py @@ -162,8 +162,8 @@ def __init__(self): self._in_to_static_mode_ = False self._functional_dygraph_context_manager = None self._dygraph_tracer_ = _dygraph_tracer_ - self._use_pir_api_ = get_flags("FLAGS_enable_new_ir_api")[ - 'FLAGS_enable_new_ir_api' + self._use_pir_api_ = get_flags("FLAGS_enable_pir_api")[ + 'FLAGS_enable_pir_api' ] def __str__(self): @@ -340,8 +340,8 @@ def in_dynamic_or_pir_mode(): >>> print(paddle.framework.in_dynamic_or_pir_mode()) False - >>> paddle.framework.set_flags({"FLAGS_enable_new_ir_api": True}) - >>> print(paddle.framework.in_dynamic_or_pir_mode()) + >>> with paddle.pir_utils.IrGuard(): + ... print(paddle.framework.in_dynamic_or_pir_mode()) True """ diff --git a/python/paddle/pir_utils.py b/python/paddle/pir_utils.py index a62fe6f61a924..9af825cfcd88b 100644 --- a/python/paddle/pir_utils.py +++ b/python/paddle/pir_utils.py @@ -19,11 +19,11 @@ class IrGuard: def __init__(self): self.in_dygraph_outside = False - old_flag = paddle.base.framework.get_flags("FLAGS_enable_new_ir_api") - paddle.base.framework.set_flags({"FLAGS_enable_new_ir_api": False}) + old_flag = paddle.base.framework.get_flags("FLAGS_enable_pir_api") + paddle.base.framework.set_flags({"FLAGS_enable_pir_api": False}) paddle.base.framework.global_var._use_pir_api_ = False - if not paddle.base.framework.get_flags("FLAGS_enable_new_ir_api")[ - "FLAGS_enable_new_ir_api" + if not paddle.base.framework.get_flags("FLAGS_enable_pir_api")[ + "FLAGS_enable_pir_api" ]: self.old_Program = paddle.static.Program self.old_program_guard = paddle.base.program_guard @@ -34,31 +34,31 @@ def __init__(self): else: raise RuntimeError( "IrGuard only init when paddle.framework.in_pir_mode(): is false, \ - please set FLAGS_enable_new_ir_api = false" + please set FLAGS_enable_pir_api = false" ) paddle.base.framework.set_flags(old_flag) paddle.base.framework.global_var._use_pir_api_ = old_flag[ - "FLAGS_enable_new_ir_api" + "FLAGS_enable_pir_api" ] def __enter__(self): self.in_dygraph_outside = paddle.base.framework.in_dygraph_mode() if self.in_dygraph_outside: paddle.enable_static() - paddle.framework.set_flags({"FLAGS_enable_new_ir_api": True}) + paddle.framework.set_flags({"FLAGS_enable_pir_api": True}) paddle.base.framework.global_var._use_pir_api_ = True self._switch_to_pir() def __exit__(self, exc_type, exc_val, exc_tb): - paddle.framework.set_flags({"FLAGS_enable_new_ir_api": False}) + paddle.framework.set_flags({"FLAGS_enable_pir_api": False}) paddle.base.framework.global_var._use_pir_api_ = False self._switch_to_old_ir() if self.in_dygraph_outside: paddle.disable_static() def _switch_to_pir(self): - if paddle.base.framework.get_flags("FLAGS_enable_new_ir_api")[ - "FLAGS_enable_new_ir_api" + if paddle.base.framework.get_flags("FLAGS_enable_pir_api")[ + "FLAGS_enable_pir_api" ]: paddle.framework.set_flags( {"FLAGS_enable_new_ir_in_executor": True} @@ -76,8 +76,8 @@ def _switch_to_pir(self): ) def _switch_to_old_ir(self): - if not paddle.base.framework.get_flags("FLAGS_enable_new_ir_api")[ - "FLAGS_enable_new_ir_api" + if not paddle.base.framework.get_flags("FLAGS_enable_pir_api")[ + "FLAGS_enable_pir_api" ]: paddle.framework.set_flags( {"FLAGS_enable_new_ir_in_executor": False} @@ -93,5 +93,5 @@ def _switch_to_old_ir(self): else: raise RuntimeError( "IrGuard._switch_to_old_ir only work when paddle.framework.in_pir_mode() is false, \ - please set FLAGS_enable_new_ir_api = false" + please set FLAGS_enable_pir_api = false" ) diff --git a/test/ir/new_ir/CMakeLists.txt b/test/ir/new_ir/CMakeLists.txt index e213eaba4c53c..75587db97c088 100644 --- a/test/ir/new_ir/CMakeLists.txt +++ b/test/ir/new_ir/CMakeLists.txt @@ -15,7 +15,7 @@ foreach(target ${TEST_INTERP_CASES}) endforeach() foreach(target ${TEST_IR_SYSTEM_CASES}) - py_test_modules(${target} MODULES ${target} ENVS FLAGS_enable_new_ir_api=true) + py_test_modules(${target} MODULES ${target} ENVS FLAGS_enable_pir_api=true) endforeach() set_tests_properties(test_pd_inplace_pass PROPERTIES TIMEOUT 60) diff --git a/test/ir/new_ir/test_ir_backward.py b/test/ir/new_ir/test_ir_backward.py index acffcf4ee28d6..c604290d34cad 100644 --- a/test/ir/new_ir/test_ir_backward.py +++ b/test/ir/new_ir/test_ir_backward.py @@ -38,7 +38,7 @@ def get_ir_program_0(): class TesBackward_1(unittest.TestCase): def tearDown(self) -> None: - paddle.framework.set_flags({"FLAGS_enable_new_ir_api": False}) + paddle.framework.set_flags({"FLAGS_enable_pir_api": False}) def test_grad(self): newir_program = get_ir_program_0() @@ -155,7 +155,7 @@ def get_ir_program_1(): class TesBackward_2(unittest.TestCase): def tearDown(self) -> None: - paddle.framework.set_flags({"FLAGS_enable_new_ir_api": False}) + paddle.framework.set_flags({"FLAGS_enable_pir_api": False}) def test_add_n(self): newir_program = get_ir_program_1() @@ -231,7 +231,7 @@ def get_ir_program_2(): class TestBackward_3(unittest.TestCase): def tearDown(self) -> None: - paddle.framework.set_flags({"FLAGS_enable_new_ir_api": False}) + paddle.framework.set_flags({"FLAGS_enable_pir_api": False}) def test_basic_network(self): newir_program = get_ir_program_2() diff --git a/test/prim/new_ir_prim/CMakeLists.txt b/test/prim/new_ir_prim/CMakeLists.txt index 1b37b432d2052..a36e905e0c9f4 100644 --- a/test/prim/new_ir_prim/CMakeLists.txt +++ b/test/prim/new_ir_prim/CMakeLists.txt @@ -3,7 +3,7 @@ set(TEST_PRIM_PURE_NEW_IR_CASES test_prim_program test_prim_simpnet foreach(target ${TEST_PRIM_PURE_NEW_IR_CASES}) py_test_modules(${target} MODULES ${target} ENVS GLOG_v=1 - FLAGS_enable_new_ir_api=true) + FLAGS_enable_pir_api=true) endforeach() file(