diff --git a/torch_xla/csrc/helpers.cpp b/torch_xla/csrc/helpers.cpp index f689d2dcfa9..36c95b7630f 100644 --- a/torch_xla/csrc/helpers.cpp +++ b/torch_xla/csrc/helpers.cpp @@ -6,6 +6,7 @@ #include #include +#include "absl/status/status.h" #include "absl/strings/str_join.h" #include "torch_xla/csrc/convert_ops.h" #include "torch_xla/csrc/dtype.h" @@ -1042,9 +1043,11 @@ absl::StatusOr XlaHelpers::WrapXlaComputation( xla::XlaOp orig_result = xla::Call(&builder, computation, inner_params); // Rebuild aliasing. - for (const int64_t i : buffer_donor_indices) { - builder.AddBufferDonor(/*param_number=*/0, - /*param_index=*/xla::ShapeIndex({i})); + if (buffer_donor_indices.size() > 0) { + for (size_t i : buffer_donor_indices) { + builder.AddBufferDonor(/*param_number=*/0, + /*param_index=*/xla::ShapeIndex({i})); + } } return builder.Build(orig_result);