Skip to content
Merged
13 changes: 0 additions & 13 deletions paddle/common/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1726,19 +1726,6 @@ PHI_DEFINE_EXPORTED_int64(alloc_fill_value,
"Whether to fill fixed value after allocation. "
"This is useful for debugging.");

/**
* Apply shape optimization pass to PIR FLAG
* Name: pir_apply_shape_optimization_pass
* Since Version: 3.0.0
* Value Range: bool, default=false
* Example:
* Note: If True, will apply shape_optimization pass to PIR.
*/
PHI_DEFINE_EXPORTED_bool(pir_apply_shape_optimization_pass,
false,
"Whether to apply shape_optimization pass "
"to infer symbolic shape");

PHI_DEFINE_EXPORTED_int64(
pir_broadcast_tree_limit,
32,
Expand Down
5 changes: 1 addition & 4 deletions paddle/fluid/pybind/pir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ using pybind11::return_value_policy;
namespace name_analysis = pir::utils::name_analysis;

COMMON_DECLARE_bool(print_ir);
COMMON_DECLARE_bool(pir_apply_shape_optimization_pass);

namespace paddle {
namespace pybind {
Expand Down Expand Up @@ -2585,9 +2584,7 @@ void InferSymbolicShapePass(
pir::Program &program) { // NOLINT
pir::IrContext *ctx = pir::IrContext::Instance();
ctx->GetOrRegisterDialect<pir::shape::ShapeDialect>();
if (FLAGS_pir_apply_shape_optimization_pass) {
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
}
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
}

std::shared_ptr<Program> ApplyCommonSubexpressionEliminationPass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include "paddle/pir/include/pass/pass_manager.h"
#include "paddle/pir/include/pass/pass_registry.h"

COMMON_DECLARE_bool(pir_apply_shape_optimization_pass);

constexpr int vlog_level = 3;

// TODO(zhangbopd): Some op results inferred by InferSymbolicShape is NOT
Expand Down Expand Up @@ -458,9 +456,7 @@ void AddShapeOptimizationPass(
pir::Program& program) { // NOLINT
pir::IrContext* ctx = pir::IrContext::Instance();
ctx->GetOrRegisterDialect<pir::shape::ShapeDialect>();
if (FLAGS_pir_apply_shape_optimization_pass) {
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
}
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
}

} // namespace pir::shape
Expand Down
7 changes: 0 additions & 7 deletions python/paddle/jit/dy2static/pir_partial_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,6 @@ def _create_program(self, is_infer_mode=False) -> RunnableProgram:
if is_infer_mode:

def pass_fn(forward_program, backward_program, program_name_attr):
# common pass
pm = paddle.base.libpaddle.pir.PassManager()
paddle.base.libpaddle.pir.infer_symbolic_shape_pass(
pm, forward_program
)
pm.run(forward_program)

apply_general_passes(
forward_program,
enable_cse=cse_is_enabled(),
Expand Down
2 changes: 0 additions & 2 deletions python/paddle/tensorrt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def _add_pass_(pm, passes, disable_passes):

pm = pir.PassManager(opt_level=4)
pm.enable_print_statistics()
paddle.base.libpaddle.pir.infer_symbolic_shape_pass(pm, program)
if scope is None:
scope = paddle.static.global_scope()
place = paddle.CUDAPlace(0)
Expand Down Expand Up @@ -121,7 +120,6 @@ def _add_pass_(pm, passes, disable_passes):
def run_trt_partition(program):
pm = pir.PassManager(opt_level=4)
pm.enable_print_statistics()
paddle.base.libpaddle.pir.infer_symbolic_shape_pass(pm, program)
pm.add_pass("trt_sub_graph_extract_pass", {})
pm.run(program)
return program
Expand Down
4 changes: 2 additions & 2 deletions test/ir/pir/cinn/performance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ if(WITH_GPU)
${CMAKE_COMMAND} -E env
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
FLAGS_check_infer_symbolic=1 FLAGS_enable_pir_api=1
FLAGS_prim_enable_dynamic=true FLAGS_pir_apply_shape_optimization_pass=1
FLAGS_cinn_new_group_scheduler=1 ${PYTHON_EXECUTABLE}
FLAGS_prim_enable_dynamic=true FLAGS_cinn_new_group_scheduler=1
${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/${cinn_pir_test_name}.py
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

Expand Down
12 changes: 5 additions & 7 deletions test/ir/pir/cinn/symbolic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ if(WITH_GPU)
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
FLAGS_check_infer_symbolic=1 FLAGS_enable_pir_api=1
FLAGS_prim_enable_dynamic=true FLAGS_prim_all=True
FLAGS_pir_apply_shape_optimization_pass=1
FLAGS_cinn_new_group_scheduler=1 ${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/${cinn_pir_test_name}.py
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down Expand Up @@ -68,9 +67,9 @@ if(WITH_GPU)
COMMAND
${CMAKE_COMMAND} -E env
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
FLAGS_prim_all=true FLAGS_pir_apply_shape_optimization_pass=true
FLAGS_enable_pir_api=true FLAGS_prim_enable_dynamic=true
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_llama_if_dy.py
FLAGS_prim_all=true FLAGS_enable_pir_api=true
FLAGS_prim_enable_dynamic=true ${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/test_llama_if_dy.py
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(test_llama_if_dy PROPERTIES LABELS "RUN_TYPE=CINN")

Expand All @@ -79,8 +78,7 @@ if(WITH_GPU)
COMMAND
${CMAKE_COMMAND} -E env
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
FLAGS_pir_apply_shape_optimization_pass=1 FLAGS_enable_pir_api=1
${PYTHON_EXECUTABLE}
FLAGS_enable_pir_api=1 ${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/test_cinn_reduce_symbolic_demo.py
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(test_cinn_reduce_symbolic_demo
Expand All @@ -92,7 +90,7 @@ if(WITH_GPU)
${CMAKE_COMMAND} -E env
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
FLAGS_cinn_convert_static_dim_to_dynamic_dim=64:S0 FLAGS_enable_pir_api=1
FLAGS_pir_apply_shape_optimization_pass=1 ${PYTHON_EXECUTABLE}
${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/test_sub_graph_for_backend.py
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(test_sub_graph_for_backend PROPERTIES LABELS
Expand Down
93 changes: 0 additions & 93 deletions test/ir/pir/cinn/symbolic/test_infer_sym_shape_unary_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,99 +577,6 @@ def test_eval_symbolic(self):
return True


class ReshapeNet(paddle.nn.Layer):
def __init__(self):
super().__init__()

def forward(self, x):
out1 = paddle.reshape(x, [-1, 4, 5])
out2 = paddle.reshape(x, [0, 0, 12])
return out1, out2


class ReshapeOpInferSymbolicShapeTest(TestBase):
def prepare_data(self):
self.cases = [np.random.rand(4, 5, 6)]
self.expected = [
[
'shape[Mul(S0, S1, 3, 1 / (5)), 4, 5], data[NULL]',
'shape[S0, S1, 12], data[NULL]',
]
]

def test_eval_symbolic(self):
net = ReshapeNet()

for i in range(len(self.cases)):
x = self.cases[i]
x_spec = InputSpec(
shape=[None for index in range(len(x.shape))], dtype='float32'
)

input_spec = [x_spec]
net = apply_to_static(net, False, input_spec)
net.eval()

check_infer_results(
net, input_spec, 'pd_op.reshape', self.expected[i]
)

return True


class SplitNet(paddle.nn.Layer):
def __init__(self):
super().__init__()

def forward(self, x):
out = paddle.split(x, [-1], axis=1)
out = paddle.split(x, [1, 2, -1], axis=1)
out = paddle.split(x, [1, -1], axis=1)
out = paddle.split(x, [1, 2, 3], axis=1)

out = x.split([-1], axis=1)
out = x.split([1, 2, -1], axis=1)
out = x.split([1, -1], axis=1)
out = x.split([1, 2, 3], axis=1)

return out


class SplitOpInferSymbolicShapeTest(TestBase):
def prepare_data(self):
self.cases = [np.random.rand(4, 6, 5)]
self.expected = [
'shape[S0, 6, S2], data[NULL]',
'shape[S0, 1, S2], data[NULL], shape[S0, 2, S2], data[NULL], shape[S0, 3, S2], data[NULL]',
'shape[S0, 1, S2], data[NULL], shape[S0, 5, S2], data[NULL]',
'shape[S0, 1, S2], data[NULL], shape[S0, 2, S2], data[NULL], shape[S0, 3, S2], data[NULL]',
'shape[S0, 6, S2], data[NULL]',
'shape[S0, 1, S2], data[NULL], shape[S0, 2, S2], data[NULL], shape[S0, 3, S2], data[NULL]',
'shape[S0, 1, S2], data[NULL], shape[S0, 5, S2], data[NULL]',
'shape[S0, 1, S2], data[NULL], shape[S0, 2, S2], data[NULL], shape[S0, 3, S2], data[NULL]',
]

def test_eval_symbolic(self):
net = SplitNet()

for i in range(len(self.cases)):
x = self.cases[i]
x_spec = InputSpec(
shape=[None for index in range(len(x.shape))], dtype='float32'
)
input_spec = [x_spec]
net = apply_to_static(net, False, input_spec)
net.eval()

# check the infer result
check_infer_results(net, input_spec, 'pd_op.split', self.expected)

# TODO(fty1777): Add builtin.split op infer symbolic shape test
# Not added because attribute `sym_shape_str` does not support multi-output op now.
# See also: paddle/fluid/pir/transforms/shape_optimization_pass.cc:144.
return True


class TopkNet(paddle.nn.Layer):
def __init__(self):
super().__init__()
Expand Down
3 changes: 1 addition & 2 deletions test/prim/pir_prim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ if(WITH_CINN)
FLAGS_prim_check_ops=true
FLAGS_enable_pir_api=true
FLAGS_prim_enable_dynamic=true
FLAGS_prim_vjp_skip_default_ops=false
FLAGS_pir_apply_shape_optimization_pass=1)
FLAGS_prim_vjp_skip_default_ops=false)
set_tests_properties(${target} PROPERTIES LABELS "RUN_TYPE=CINN")
endforeach()
endif()
Expand Down
Loading