From df5e319d05778e6773e7703dc61fa6baaf4fe3b3 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Sat, 23 May 2020 09:43:17 -0700 Subject: [PATCH] Make the tf2xla "tensor list size not set" error message a bit more ergonomic PiperOrigin-RevId: 312916547 Change-Id: Idbbe406a35205a0fb6dc5e620e04cf3bccefa43d --- .../compiler/tf2xla/kernels/tensor_list_ops.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tensorflow/compiler/tf2xla/kernels/tensor_list_ops.cc b/tensorflow/compiler/tf2xla/kernels/tensor_list_ops.cc index d01f094dc2e..976ff91f6ce 100644 --- a/tensorflow/compiler/tf2xla/kernels/tensor_list_ops.cc +++ b/tensorflow/compiler/tf2xla/kernels/tensor_list_ops.cc @@ -136,8 +136,11 @@ class TensorListReserveOp : public XlaOpKernel { OP_REQUIRES_OK(ctx, ctx->ConstantInputAsIntScalar(1, &num_elements)); OP_REQUIRES( ctx, num_elements >= 0, - errors::InvalidArgument("XLA compilation requires a fixed tensor list " - "size. Set the number of elements.")); + errors::InvalidArgument( + "XLA compilation requires a fixed tensor list size. Set the number " + "of elements. This could also happen if you're using a TensorArray " + "in a while loop that does not have its maximum_iteration set, you " + "can fix this by setting maximum_iteration to a suitable value.")); // If element shape is compile time constant and it's not "unknown rank" // shape (-1), create an initialized TensorList. Otherwise create an @@ -197,10 +200,13 @@ class EmptyTensorListOp : public XlaOpKernel { void Compile(XlaOpKernelContext* ctx) override { int64 max_num_elements; OP_REQUIRES_OK(ctx, ctx->ConstantInputAsIntScalar(1, &max_num_elements)); - OP_REQUIRES( - ctx, max_num_elements >= 0, - errors::InvalidArgument("XLA compilation requires a fixed tensor list " - "size. Set the max number of elements.")); + OP_REQUIRES(ctx, max_num_elements >= 0, + errors::InvalidArgument( + "XLA compilation requires a fixed tensor list size. Set " + "the max number of elements. This could also happen if " + "you're using a TensorArray in a while loop that does not " + "have its maximum_iteration set, you can fix this by " + "setting maximum_iteration to a suitable value.")); if (dtype_ != DT_VARIANT) { // We are creating a non-nested TensorList.