Commits


guyang3532 authored and GitHub committed ef6f4a4aa1d
support broadcast shape for elementwise node in padding elimination (#16710) With PaddingElimination optimizer, input1 of element-wise op may be flattened like: ``` input1 (shape:[batch_size, seq_len, ...]) input1 (shape:[valid_tokens, ...]) \ \ \ input2 \ input2 \ / -----> \ / \ / \ / Element-wise Op Element-wise Op ``` So, the shape of input2 should be processed accordingly: 1. If input2.shape.dim_size <= input1.shape.dim_size-2, i.e. input2 has no [batch_size, seq_len] at begining, we needn't to process the shape of input2 because it's compatible with the flattened shape of input1 (shape:[valid_tokens, ...]). 2. If the shape of input2 has the same dim_size with shape of input1 and has [batch_size, seqlen] at begening, to be compatible with flattened shape of input1, we need to insert flatten pattern for input2 also, which flatten the shape of input2 from [batch_size, seq_len, ...] to [valida_tokens, ...]. 3. (which done in this pr) In other case for shape of input2, like [1, seq_len, ...] or [batch_size, 1, ...], we firstly need to expand it to [batch_size, seq_len, ...] which is convenient to flatten. And then insert flatten pattern.