Skip to content

Commit c42afe1

Browse files
committed
Fix up
1 parent 7bf6d9f commit c42afe1

File tree

6 files changed

+25
-68
lines changed

6 files changed

+25
-68
lines changed

src/pb_stub.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,7 @@ Stub::ProcessReturnedResponses(
820820
std::string(py::str(py_responses[i].get_type())) + "'.");
821821
}
822822

823-
std::shared_ptr<InferResponse> response =
824-
py_responses[i].cast<std::shared_ptr<InferResponse>>();
823+
InferResponse* response = py_responses[i].cast<InferResponse*>();
825824
request->GetResponseSender()->UpdateStateAndCounters(
826825
response, TRITONSERVER_RESPONSE_COMPLETE_FINAL);
827826
}
@@ -845,9 +844,13 @@ Stub::ProcessReturnedResponses(
845844
// Check the return type of execute function.
846845
InferRequest* infer_request = py_requests[i].cast<InferRequest*>();
847846
InferResponse* infer_response = py_responses[i].cast<InferResponse*>();
848-
infer_response->PruneOutputTensors(infer_request->RequestedOutputNames());
849-
ProcessResponse(infer_response);
850-
responses_shm_handle[i] = infer_response->ShmHandle();
847+
if (!py::isinstance<py::none>(py_responses[i])) {
848+
infer_response->PruneOutputTensors(infer_request->RequestedOutputNames());
849+
ProcessResponse(infer_response);
850+
responses_shm_handle[i] = infer_response->ShmHandle();
851+
} else {
852+
responses_shm_handle[i] = 0;
853+
}
851854
}
852855
response_batch_shm_ptr->batch_size = requests_size;
853856
}

src/python_be.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,13 +1026,7 @@ ModelInstanceState::SendMessageAndReceiveResponse(
10261026
SendMessageToStub(message);
10271027

10281028
bi::managed_external_buffer::handle_t response_message;
1029-
auto error = Stub()->ReceiveMessageFromStub(response_message);
1030-
if (error != nullptr) {
1031-
RespondErrorToAllRequests(
1032-
TRITONSERVER_ErrorMessage(error), responses, requests, request_count);
1033-
1034-
return;
1035-
}
1029+
Stub()->ReceiveMessageFromStub(response_message);
10361030

10371031
response = response_message;
10381032
}
@@ -1355,6 +1349,14 @@ ModelInstanceState::ProcessRequests(
13551349
(*responses)[r] = nullptr;
13561350
continue;
13571351
}
1352+
1353+
if (response_shm_handle[r] == 0) {
1354+
LOG_IF_ERROR(
1355+
TRITONBACKEND_ResponseDelete((*responses)[r]),
1356+
"failed to delete response");
1357+
(*responses)[r] = nullptr;
1358+
continue;
1359+
}
13581360
infer_response = InferResponse::LoadFromSharedMemory(
13591361
Stub()->ShmPool(), response_shm_handle[r],
13601362
false /* open_cuda_handle */);

src/response_sender.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ResponseSender::~ResponseSender()
7474

7575
void
7676
ResponseSender::UpdateStateAndCounters(
77-
const std::shared_ptr<InferResponse>& response, const uint32_t flags)
77+
InferResponse* response, const uint32_t flags)
7878
{
7979
if (is_decoupled_ == nullptr) {
8080
// TODO: Can a model access the response sender on a BLS infer request?
@@ -106,6 +106,7 @@ ResponseSender::UpdateStateAndCounters(
106106
}
107107

108108
if (flags == TRITONSERVER_RESPONSE_COMPLETE_FINAL) {
109+
response_factory_deleted_.exchange(true);
109110
closed_ = true;
110111
}
111112
number_of_response_sent_++;
@@ -123,7 +124,7 @@ ResponseSender::Send(
123124
py::gil_scoped_release release;
124125

125126
CheckResponseSenderArguments(infer_response, flags);
126-
UpdateStateAndCounters(infer_response, flags);
127+
UpdateStateAndCounters(infer_response.get(), flags);
127128
if (infer_response) {
128129
infer_response->PruneOutputTensors(requested_output_names_);
129130
}

src/response_sender.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class ResponseSender {
4646
~ResponseSender();
4747
void Send(std::shared_ptr<InferResponse> response, const uint32_t flags);
4848
bool IsCancelled();
49-
void UpdateStateAndCounters(
50-
const std::shared_ptr<InferResponse>& response, const uint32_t flags);
49+
void UpdateStateAndCounters(InferResponse* response, const uint32_t flags);
5150

5251
// Can be useful at stopping the model from sending any more responses.
5352
void Close();

src/stub_launcher.cc

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ StubLauncher::ModelInstanceStubProcess()
593593
stub_message_queue_->Push(initialize_message->ShmHandle());
594594

595595
bi::managed_external_buffer::handle_t message;
596-
RETURN_IF_ERROR(ReceiveMessageFromStub(message));
596+
ReceiveMessageFromStub(message);
597597

598598
std::unique_ptr<IPCMessage> initialize_response_message =
599599
IPCMessage::LoadFromSharedMemory(shm_pool_, message);
@@ -724,58 +724,11 @@ StubLauncher::KillStubProcess()
724724
#endif
725725
}
726726

727-
TRITONSERVER_Error*
727+
void
728728
StubLauncher::ReceiveMessageFromStub(
729729
bi::managed_external_buffer::handle_t& message)
730730
{
731-
bool success = false;
732-
while (!success) {
733-
uint64_t timeout_miliseconds = 1000;
734-
{
735-
boost::posix_time::ptime timeout =
736-
boost::get_system_time() +
737-
boost::posix_time::milliseconds(timeout_miliseconds);
738-
739-
bi::scoped_lock<bi::interprocess_mutex> lock(*health_mutex_, timeout);
740-
741-
// Check if lock has been acquired.
742-
if (lock) {
743-
ipc_control_->stub_health = false;
744-
} else {
745-
// If it failed to obtain the lock, it means that the stub has been
746-
// stuck or exited while holding the health mutex lock.
747-
return TRITONSERVER_ErrorNew(
748-
TRITONSERVER_ERROR_INTERNAL, "Failed to obtain the health mutex.");
749-
}
750-
}
751-
752-
message = parent_message_queue_->Pop(
753-
timeout_miliseconds /* duration ms */, success);
754-
755-
bool is_stub_alive = false;
756-
{
757-
boost::posix_time::ptime timeout =
758-
boost::get_system_time() + boost::posix_time::seconds(1);
759-
bi::scoped_lock<bi::interprocess_mutex> lock(*health_mutex_, timeout);
760-
if (lock) {
761-
is_stub_alive = ipc_control_->stub_health;
762-
} else {
763-
// If It failed to obtain the lock, it means that the stub has been
764-
// stuck or exited while holding the health mutex lock.
765-
is_stub_alive = false;
766-
}
767-
}
768-
769-
if (!success && !is_stub_alive) {
770-
return TRITONSERVER_ErrorNew(
771-
TRITONSERVER_ERROR_INTERNAL,
772-
(std::string("Stub process '") + model_instance_name_ +
773-
"' is not healthy.")
774-
.c_str());
775-
}
776-
}
777-
778-
return nullptr; // success
731+
message = parent_message_queue_->Pop();
779732
}
780733

781734
void

src/stub_launcher.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ class StubLauncher {
146146
void KillStubProcess();
147147

148148
// Get a message from the stub process
149-
TRITONSERVER_Error* ReceiveMessageFromStub(
150-
bi::managed_external_buffer::handle_t& message);
149+
void ReceiveMessageFromStub(bi::managed_external_buffer::handle_t& message);
151150

152151
// Wait for stub process
153152
void WaitForStubProcess();

0 commit comments

Comments
 (0)