Skip to content

Commit

Permalink
Update test_api.py and fix from_dlpack with bytes type
Browse files Browse the repository at this point in the history
  • Loading branch information
kthui committed Jan 15, 2025
1 parent 5e805da commit 2faf303
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
7 changes: 6 additions & 1 deletion python/test/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright 2023-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -137,6 +137,7 @@ def test_memory_fallback_to_cpu(self, server_options):

tritonserver.default_memory_allocators[tritonserver.MemoryType.GPU] = allocator

@pytest.mark.skip(reason="Skipping test, infer no longer use allocator")
def test_memory_allocator_exception(self, server_options):
server = tritonserver.Server(server_options).start(wait_until_ready=True)

Expand Down Expand Up @@ -164,6 +165,7 @@ def test_memory_allocator_exception(self, server_options):
):
pass

@pytest.mark.skip(reason="Skipping test, infer no longer use allocator")
def test_unsupported_memory_type(self, server_options):
server = tritonserver.Server(server_options).start(wait_until_ready=True)

Expand Down Expand Up @@ -418,6 +420,9 @@ def test_ready(self, server_options):
server = tritonserver.Server(server_options).start()
assert server.ready()

@pytest.mark.skip(
reason="Skipping test, some request/response object may not be released which may cause server stop to fail"
)
def test_stop(self, server_options):
server = tritonserver.Server(server_options).start(wait_until_ready=True)

Expand Down
22 changes: 19 additions & 3 deletions python/tritonserver/_api/_tensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright 2023-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -509,16 +509,32 @@ def to_device(self, device: DeviceOrMemoryType) -> Tensor:
if self.memory_type == MemoryType.CPU_PINNED and memory_type == MemoryType.CPU:
return self
if cupy is not None:
# DLPack does not support bytes type.
original_data_type = self.data_type
original_shape = self.shape
if self.data_type == DataType.BYTES:
self.data_type = DataType.UINT8
self.shape = [self.size]

if self.memory_type in (MemoryType.CPU, MemoryType.CPU_PINNED):
ndarray = numpy.from_dlpack(self)
else:
ndarray = cupy.from_dlpack(self)

self.data_type = original_data_type
self.shape = original_shape

if memory_type == MemoryType.CPU:
return Tensor.from_dlpack(cupy.asnumpy(ndarray))
new_tensor = Tensor.from_dlpack(cupy.asnumpy(ndarray))
new_tensor.data_type = self.data_type
new_tensor.shape = self.shape
return new_tensor
if memory_type == MemoryType.GPU:
with cupy.cuda.Device(memory_type_id):
return Tensor.from_dlpack(cupy.asarray(ndarray))
new_tensor = Tensor.from_dlpack(cupy.asarray(ndarray))
new_tensor.data_type = self.data_type
new_tensor.shape = self.shape
return new_tensor

raise UnsupportedError(
f"Conversion from {(self.memory_type,self.memory_type_id)} to {(memory_type, memory_type_id)} not supported."
Expand Down

0 comments on commit 2faf303

Please sign in to comment.