Support for simple TFLite dynamic shape computations
Open
@NatashaKnk is already working on this.
Since Jul 18, 2022.
integrations/tosa
- Dominant language
- C++
- Stars
- 3.9k
- Forks
- 1k
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 47
Description
Request description
In some simple cases we can be left with what appears to be a dynamic shape computation. In these cases it is technically expressible under tosa however requires multiple operations to be folded together and statically analyzed. A simple example is shown below.
func.func @main(%arg0: tensor<?x16xf32>) -> tensor<?x?xf32> {
%cst_0 = arith.constant dense<0> : tensor<i32>
%cst_2 = arith.constant dense<2> : tensor<i32>
%0 = "tfl.shape"(%arg0) : (tensor<?x16xf32>) -> tensor<2xi32>
%1:2 = "tfl.split"(%cst_0, %0) { num_splits = 2 : i32 } : (tensor<i32>, tensor<2xi32>) -> (tensor<1xi32>, tensor<1xi32>)
%2 = arith.constant dense<> : tensor<0xi32>
%3 = "tfl.reshape"(%1#0, %2) : (tensor<1xi32>, tensor<0xi32>) -> tensor<*xi32>
%4 = tfl.mul(%3, %cst_2) {fused_activation_function = "NONE"} : (tensor<*xi32>, tensor<i32>) -> tensor<*xi32>
%5 = arith.constant dense<8> : tensor<i32>
%6 = "tfl.pack"(%4, %5) {axis = 0 : i32, values_count = 2 : i32} : (tensor<*xi32>, tensor<i32>) -> tensor<2xi32>
%7 = "tfl.reshape"(%arg0, %6) : (tensor<?x16xf32>, tensor<2xi32>) -> tensor<?x?xf32>
return %7 : tensor<?x?xf32>
}
This case contains some basic reshaping however the output shape of the final reshape is unknown as it is technically a dynamic value. We need a method to propagate shapes forward for these static cases similar to mhlo.
What component(s) does this issue relate to?
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.