Skip to content

Commit 3912864

Browse files
authored
[CINN]Delete shape_optimization flag And Refine ApplyCinnPass (#70947)
* add FLAGS_check_jit_instrction_shape * add log * add flag in runtime/flags * fix * tix typo * delete FLAGS_pir_apply_shape_optimization_pass * delete symbolic shape pass in trt * delete the test case of reshape and split op
1 parent a332f27 commit 3912864

File tree

9 files changed

+10
-135
lines changed

9 files changed

+10
-135
lines changed

paddle/common/flags.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,19 +1726,6 @@ PHI_DEFINE_EXPORTED_int64(alloc_fill_value,
17261726
"Whether to fill fixed value after allocation. "
17271727
"This is useful for debugging.");
17281728

1729-
/**
1730-
* Apply shape optimization pass to PIR FLAG
1731-
* Name: pir_apply_shape_optimization_pass
1732-
* Since Version: 3.0.0
1733-
* Value Range: bool, default=false
1734-
* Example:
1735-
* Note: If True, will apply shape_optimization pass to PIR.
1736-
*/
1737-
PHI_DEFINE_EXPORTED_bool(pir_apply_shape_optimization_pass,
1738-
false,
1739-
"Whether to apply shape_optimization pass "
1740-
"to infer symbolic shape");
1741-
17421729
PHI_DEFINE_EXPORTED_int64(
17431730
pir_broadcast_tree_limit,
17441731
32,

paddle/fluid/pybind/pir.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ using pybind11::return_value_policy;
137137
namespace name_analysis = pir::utils::name_analysis;
138138

139139
COMMON_DECLARE_bool(print_ir);
140-
COMMON_DECLARE_bool(pir_apply_shape_optimization_pass);
141140

142141
namespace paddle {
143142
namespace pybind {
@@ -2585,9 +2584,7 @@ void InferSymbolicShapePass(
25852584
pir::Program &program) { // NOLINT
25862585
pir::IrContext *ctx = pir::IrContext::Instance();
25872586
ctx->GetOrRegisterDialect<pir::shape::ShapeDialect>();
2588-
if (FLAGS_pir_apply_shape_optimization_pass) {
2589-
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
2590-
}
2587+
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
25912588
}
25922589

25932590
std::shared_ptr<Program> ApplyCommonSubexpressionEliminationPass(

paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include "paddle/pir/include/pass/pass_manager.h"
2929
#include "paddle/pir/include/pass/pass_registry.h"
3030

31-
COMMON_DECLARE_bool(pir_apply_shape_optimization_pass);
32-
3331
constexpr int vlog_level = 3;
3432

3533
// TODO(zhangbopd): Some op results inferred by InferSymbolicShape is NOT
@@ -465,9 +463,7 @@ void AddShapeOptimizationPass(
465463
pir::Program& program) { // NOLINT
466464
pir::IrContext* ctx = pir::IrContext::Instance();
467465
ctx->GetOrRegisterDialect<pir::shape::ShapeDialect>();
468-
if (FLAGS_pir_apply_shape_optimization_pass) {
469-
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
470-
}
466+
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
471467
}
472468

473469
} // namespace pir::shape

python/paddle/jit/dy2static/pir_partial_program.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -770,13 +770,6 @@ def _create_program(self, is_infer_mode=False) -> RunnableProgram:
770770
if is_infer_mode:
771771

772772
def pass_fn(forward_program, backward_program, program_name_attr):
773-
# common pass
774-
pm = paddle.base.libpaddle.pir.PassManager()
775-
paddle.base.libpaddle.pir.infer_symbolic_shape_pass(
776-
pm, forward_program
777-
)
778-
pm.run(forward_program)
779-
780773
apply_general_passes(
781774
forward_program,
782775
enable_cse=cse_is_enabled(),

python/paddle/tensorrt/util.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def _add_pass_(pm, passes, disable_passes):
7878

7979
pm = pir.PassManager(opt_level=4)
8080
pm.enable_print_statistics()
81-
paddle.base.libpaddle.pir.infer_symbolic_shape_pass(pm, program)
8281
if scope is None:
8382
scope = paddle.static.global_scope()
8483
place = paddle.CUDAPlace(0)
@@ -121,7 +120,6 @@ def _add_pass_(pm, passes, disable_passes):
121120
def run_trt_partition(program):
122121
pm = pir.PassManager(opt_level=4)
123122
pm.enable_print_statistics()
124-
paddle.base.libpaddle.pir.infer_symbolic_shape_pass(pm, program)
125123
pm.add_pass("trt_sub_graph_extract_pass", {})
126124
pm.run(program)
127125
return program

test/ir/pir/cinn/performance/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ if(WITH_GPU)
1212
${CMAKE_COMMAND} -E env
1313
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
1414
FLAGS_check_infer_symbolic=1 FLAGS_enable_pir_api=1
15-
FLAGS_prim_enable_dynamic=true FLAGS_pir_apply_shape_optimization_pass=1
16-
FLAGS_cinn_new_group_scheduler=1 ${PYTHON_EXECUTABLE}
15+
FLAGS_prim_enable_dynamic=true FLAGS_cinn_new_group_scheduler=1
16+
${PYTHON_EXECUTABLE}
1717
${CMAKE_CURRENT_SOURCE_DIR}/${cinn_pir_test_name}.py
1818
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
1919

test/ir/pir/cinn/symbolic/CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ if(WITH_GPU)
3434
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
3535
FLAGS_check_infer_symbolic=1 FLAGS_enable_pir_api=1
3636
FLAGS_prim_enable_dynamic=true FLAGS_prim_all=True
37-
FLAGS_pir_apply_shape_optimization_pass=1
3837
FLAGS_cinn_new_group_scheduler=1 ${PYTHON_EXECUTABLE}
3938
${CMAKE_CURRENT_SOURCE_DIR}/${cinn_pir_test_name}.py
4039
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
@@ -68,9 +67,9 @@ if(WITH_GPU)
6867
COMMAND
6968
${CMAKE_COMMAND} -E env
7069
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
71-
FLAGS_prim_all=true FLAGS_pir_apply_shape_optimization_pass=true
72-
FLAGS_enable_pir_api=true FLAGS_prim_enable_dynamic=true
73-
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_llama_if_dy.py
70+
FLAGS_prim_all=true FLAGS_enable_pir_api=true
71+
FLAGS_prim_enable_dynamic=true ${PYTHON_EXECUTABLE}
72+
${CMAKE_CURRENT_SOURCE_DIR}/test_llama_if_dy.py
7473
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
7574
set_tests_properties(test_llama_if_dy PROPERTIES LABELS "RUN_TYPE=CINN")
7675

@@ -79,8 +78,7 @@ if(WITH_GPU)
7978
COMMAND
8079
${CMAKE_COMMAND} -E env
8180
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
82-
FLAGS_pir_apply_shape_optimization_pass=1 FLAGS_enable_pir_api=1
83-
${PYTHON_EXECUTABLE}
81+
FLAGS_enable_pir_api=1 ${PYTHON_EXECUTABLE}
8482
${CMAKE_CURRENT_SOURCE_DIR}/test_cinn_reduce_symbolic_demo.py
8583
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
8684
set_tests_properties(test_cinn_reduce_symbolic_demo
@@ -92,7 +90,7 @@ if(WITH_GPU)
9290
${CMAKE_COMMAND} -E env
9391
PYTHONPATH=${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/python/:$ENV{PYTHONPATH}
9492
FLAGS_cinn_convert_static_dim_to_dynamic_dim=64:S0 FLAGS_enable_pir_api=1
95-
FLAGS_pir_apply_shape_optimization_pass=1 ${PYTHON_EXECUTABLE}
93+
${PYTHON_EXECUTABLE}
9694
${CMAKE_CURRENT_SOURCE_DIR}/test_sub_graph_for_backend.py
9795
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
9896
set_tests_properties(test_sub_graph_for_backend PROPERTIES LABELS

test/ir/pir/cinn/symbolic/test_infer_sym_shape_unary_op.py

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -577,99 +577,6 @@ def test_eval_symbolic(self):
577577
return True
578578

579579

580-
class ReshapeNet(paddle.nn.Layer):
581-
def __init__(self):
582-
super().__init__()
583-
584-
def forward(self, x):
585-
out1 = paddle.reshape(x, [-1, 4, 5])
586-
out2 = paddle.reshape(x, [0, 0, 12])
587-
return out1, out2
588-
589-
590-
class ReshapeOpInferSymbolicShapeTest(TestBase):
591-
def prepare_data(self):
592-
self.cases = [np.random.rand(4, 5, 6)]
593-
self.expected = [
594-
[
595-
'shape[Mul(S0, S1, 3, 1 / (5)), 4, 5], data[NULL]',
596-
'shape[S0, S1, 12], data[NULL]',
597-
]
598-
]
599-
600-
def test_eval_symbolic(self):
601-
net = ReshapeNet()
602-
603-
for i in range(len(self.cases)):
604-
x = self.cases[i]
605-
x_spec = InputSpec(
606-
shape=[None for index in range(len(x.shape))], dtype='float32'
607-
)
608-
609-
input_spec = [x_spec]
610-
net = apply_to_static(net, False, input_spec)
611-
net.eval()
612-
613-
check_infer_results(
614-
net, input_spec, 'pd_op.reshape', self.expected[i]
615-
)
616-
617-
return True
618-
619-
620-
class SplitNet(paddle.nn.Layer):
621-
def __init__(self):
622-
super().__init__()
623-
624-
def forward(self, x):
625-
out = paddle.split(x, [-1], axis=1)
626-
out = paddle.split(x, [1, 2, -1], axis=1)
627-
out = paddle.split(x, [1, -1], axis=1)
628-
out = paddle.split(x, [1, 2, 3], axis=1)
629-
630-
out = x.split([-1], axis=1)
631-
out = x.split([1, 2, -1], axis=1)
632-
out = x.split([1, -1], axis=1)
633-
out = x.split([1, 2, 3], axis=1)
634-
635-
return out
636-
637-
638-
class SplitOpInferSymbolicShapeTest(TestBase):
639-
def prepare_data(self):
640-
self.cases = [np.random.rand(4, 6, 5)]
641-
self.expected = [
642-
'shape[S0, 6, S2], data[NULL]',
643-
'shape[S0, 1, S2], data[NULL], shape[S0, 2, S2], data[NULL], shape[S0, 3, S2], data[NULL]',
644-
'shape[S0, 1, S2], data[NULL], shape[S0, 5, S2], data[NULL]',
645-
'shape[S0, 1, S2], data[NULL], shape[S0, 2, S2], data[NULL], shape[S0, 3, S2], data[NULL]',
646-
'shape[S0, 6, S2], data[NULL]',
647-
'shape[S0, 1, S2], data[NULL], shape[S0, 2, S2], data[NULL], shape[S0, 3, S2], data[NULL]',
648-
'shape[S0, 1, S2], data[NULL], shape[S0, 5, S2], data[NULL]',
649-
'shape[S0, 1, S2], data[NULL], shape[S0, 2, S2], data[NULL], shape[S0, 3, S2], data[NULL]',
650-
]
651-
652-
def test_eval_symbolic(self):
653-
net = SplitNet()
654-
655-
for i in range(len(self.cases)):
656-
x = self.cases[i]
657-
x_spec = InputSpec(
658-
shape=[None for index in range(len(x.shape))], dtype='float32'
659-
)
660-
input_spec = [x_spec]
661-
net = apply_to_static(net, False, input_spec)
662-
net.eval()
663-
664-
# check the infer result
665-
check_infer_results(net, input_spec, 'pd_op.split', self.expected)
666-
667-
# TODO(fty1777): Add builtin.split op infer symbolic shape test
668-
# Not added because attribute `sym_shape_str` does not support multi-output op now.
669-
# See also: paddle/fluid/pir/transforms/shape_optimization_pass.cc:144.
670-
return True
671-
672-
673580
class TopkNet(paddle.nn.Layer):
674581
def __init__(self):
675582
super().__init__()

test/prim/pir_prim/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ if(WITH_CINN)
8282
FLAGS_prim_check_ops=true
8383
FLAGS_enable_pir_api=true
8484
FLAGS_prim_enable_dynamic=true
85-
FLAGS_prim_vjp_skip_default_ops=false
86-
FLAGS_pir_apply_shape_optimization_pass=1)
85+
FLAGS_prim_vjp_skip_default_ops=false)
8786
set_tests_properties(${target} PROPERTIES LABELS "RUN_TYPE=CINN")
8887
endforeach()
8988
endif()

0 commit comments

Comments
 (0)