From edaeca8df1dd3c555159f870f6c7afbca3530dd1 Mon Sep 17 00:00:00 2001 From: nsiddharth Date: Sat, 20 Jun 2026 12:40:02 -0700 Subject: [PATCH] fix: Treat empty DLPack tensors as contiguous PbTensor::FromDLPackCapsule rejected tensors with a zero-size dimension (e.g. shape (0, 0, 0)) as "not contiguous", because the C-order stride check compares against framework-reported strides that are inconsistent for empty tensors. An empty tensor has zero elements and no meaningful memory layout, so it is trivially contiguous. Skip the stride check when any dimension is zero. Mirrors the size-1 handling added in #281. Fixes triton-inference-server/server#6960 Signed-off-by: nsiddharth --- src/pb_tensor.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pb_tensor.cc b/src/pb_tensor.cc index 02c37845..011050e2 100644 --- a/src/pb_tensor.cc +++ b/src/pb_tensor.cc @@ -493,8 +493,20 @@ PbTensor::FromDLPackCapsule( dl_managed_tensor->dl_tensor.shape, dl_managed_tensor->dl_tensor.shape + ndim); - // Check if the input is contiguous and in C order - if (strides != nullptr) { + // Check if the input is contiguous and in C order. + // An empty tensor (any zero-size dimension, i.e. zero elements) has no + // meaningful memory layout and is trivially contiguous; skip the stride + // check, which can otherwise reject it because frameworks report + // inconsistent strides for empty tensors. See: + // https://github.com/triton-inference-server/server/issues/6960 + bool is_empty = false; + for (auto dim : dims) { + if (dim == 0) { + is_empty = true; + break; + } + } + if (strides != nullptr && !is_empty) { int64_t calculated_stride{1}; bool is_contiguous_c_order = true; for (size_t i = 1; i < dims.size(); i++) {