In slice.cc, also set the output to dynamic if the input tensor has unspecified dimension. For example, if the input shape is [-1, 10], with begin=[0,0] and size=[5,5]. The current logic will fail at Prepare.

PiperOrigin-RevId: 438410823
diff --git a/tensorflow/lite/kernels/slice.cc b/tensorflow/lite/kernels/slice.cc
index a68c3a8..4efaaaf 100644
--- a/tensorflow/lite/kernels/slice.cc
+++ b/tensorflow/lite/kernels/slice.cc
@@ -136,8 +136,9 @@
                      "Slice op only supports 1D-5D input arrays.");
 
   // Postpone allocation of output if any of the indexing tensors is not
-  // constant
-  if (!(IsConstantTensor(begin) && IsConstantTensor(size))) {
+  // constant, or the input tensor has dynamic dimension.
+  if (!(IsConstantTensor(begin) && IsConstantTensor(size)) ||
+      HasUnspecifiedDimension(input)) {
     SetTensorToDynamic(output);
     return kTfLiteOk;
   }