@@ -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-
673580class TopkNet (paddle .nn .Layer ):
674581 def __init__ (self ):
675582 super ().__init__ ()
0 commit comments