@@ -38,9 +38,13 @@ namespace py = pybind11;
3838namespace triton { namespace backend { namespace python {
3939
4040#ifdef TRITON_PB_STUB
41- PbTensor::PbTensor (const std::string& name, py::object numpy_array)
41+ PbTensor::PbTensor (const std::string& name, py::array& numpy_array)
4242 : name_(name)
4343{
44+ if (name == " " ) {
45+ throw PythonBackendException (" Tensor name cannot be an empty string." );
46+ }
47+
4448 dtype_ = numpy_to_triton_type (numpy_array.attr (" dtype" ));
4549 memory_type_ = TRITONSERVER_MEMORY_CPU;
4650 memory_type_id_ = 0 ;
@@ -76,10 +80,14 @@ PbTensor::PbTensor(const std::string& name, py::object numpy_array)
7680}
7781
7882PbTensor::PbTensor (
79- const std::string& name, py::object numpy_array,
83+ const std::string& name, py::array& numpy_array,
8084 TRITONSERVER_DataType dtype)
8185 : name_(name)
8286{
87+ if (name == " " ) {
88+ throw PythonBackendException (" Tensor name cannot be an empty string." );
89+ }
90+
8391 if (numpy_to_triton_type (numpy_array.attr (" dtype" )) != dtype) {
8492 numpy_array = numpy_array.attr (" view" )(triton_to_numpy_type (dtype));
8593 }
@@ -124,6 +132,10 @@ PbTensor::PbTensor(
124132 int64_t memory_type_id, void * memory_ptr, uint64_t byte_size,
125133 DLManagedTensor* dl_managed_tensor)
126134{
135+ if (name == " " ) {
136+ throw PythonBackendException (" Tensor name cannot be an empty string." );
137+ }
138+
127139 name_ = name;
128140 memory_ptr_ = memory_ptr;
129141 memory_type_ = memory_type;
@@ -214,7 +226,7 @@ delete_unused_dltensor(PyObject* dlp)
214226}
215227
216228std::shared_ptr<PbTensor>
217- PbTensor::FromNumpy (const std::string& name, py::object numpy_array)
229+ PbTensor::FromNumpy (const std::string& name, py::array& numpy_array)
218230{
219231 return std::make_shared<PbTensor>(name, numpy_array);
220232}
@@ -292,6 +304,10 @@ PbTensor::Memory()
292304std::shared_ptr<PbTensor>
293305PbTensor::FromDLPack (const std::string& name, const py::capsule& dlpack_tensor)
294306{
307+ if (name == " " ) {
308+ throw PythonBackendException (" Tensor name cannot be an empty string." );
309+ }
310+
295311 DLManagedTensor* dl_managed_tensor =
296312 static_cast <DLManagedTensor*>(dlpack_tensor.get_pointer ());
297313
0 commit comments