Skip to content

Commit f007255

Browse files
authored
Improve error message when BLS is used in 'initialize' or 'finalize' function (triton-inference-server#211)
* Improve error message when BLS is used in 'initialize' or 'finalize' function * Address comment
1 parent a51652b commit f007255

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/infer_request.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,15 @@ InferRequest::GetResponseSender()
373373
std::shared_ptr<InferResponse>
374374
InferRequest::Exec(const bool is_decoupled)
375375
{
376+
// BLS should not be used in "initialize" or "finalize" function.
377+
std::unique_ptr<Stub>& stub = Stub::GetOrCreateInstance();
378+
if (!stub->IsInitialized() || stub->IsFinalizing()) {
379+
throw PythonBackendException(
380+
"BLS is only supported during the 'execute' function.");
381+
}
382+
376383
ResponseBatch* response_batch = nullptr;
377384
bool responses_is_set = false;
378-
std::unique_ptr<Stub>& stub = Stub::GetOrCreateInstance();
379385
std::unique_ptr<SharedMemoryManager>& shm_pool = stub->SharedMemory();
380386
bi::managed_external_buffer::handle_t* response_handle = nullptr;
381387

@@ -529,8 +535,7 @@ InferRequest::Exec(const bool is_decoupled)
529535

530536
for (auto& output_tensor : error_response->OutputTensors()) {
531537
if (!output_tensor->IsCPU()) {
532-
uint64_t memory_release_id =
533-
output_tensor->Memory()->MemoryReleaseId();
538+
uint64_t memory_release_id = output_tensor->Memory()->MemoryReleaseId();
534539
output_tensor->Memory()->SetMemoryReleaseCallback(
535540
[&memory_manager_message_queue, memory_release_id]() {
536541
memory_manager_message_queue->Push(memory_release_id);

src/pb_stub.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Stub::Instantiate(
8484
name_ = name;
8585
health_mutex_ = nullptr;
8686
initialized_ = false;
87+
finalizing_ = false;
8788
stub_to_parent_thread_ = false;
8889
parent_to_stub_thread_ = false;
8990

@@ -799,6 +800,7 @@ Stub::UpdateHealth()
799800
void
800801
Stub::Finalize()
801802
{
803+
finalizing_ = true;
802804
// Call finalize if exists.
803805
if (initialized_ && py::hasattr(model_instance_, "finalize")) {
804806
try {
@@ -1120,6 +1122,18 @@ Stub::SaveResponseIterator(std::shared_ptr<ResponseIterator> response_iterator)
11201122
response_iterator->Id(), response_iterator));
11211123
}
11221124

1125+
bool
1126+
Stub::IsInitialized()
1127+
{
1128+
return initialized_;
1129+
}
1130+
1131+
bool
1132+
Stub::IsFinalizing()
1133+
{
1134+
return finalizing_;
1135+
}
1136+
11231137
std::unique_ptr<Logger> Logger::log_instance_;
11241138

11251139
std::unique_ptr<Logger>&

src/pb_stub.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ class Stub {
256256
/// Add cleanup id to queue
257257
void EnqueueCleanupId(void* id);
258258

259+
/// Is the stub initialized
260+
bool IsInitialized();
261+
262+
/// Is the stub in the finalize stage
263+
bool IsFinalizing();
264+
259265

260266
private:
261267
bi::interprocess_mutex* stub_mutex_;
@@ -282,6 +288,7 @@ class Stub {
282288
parent_to_stub_mq_;
283289
std::unique_ptr<MessageQueue<uint64_t>> memory_manager_message_queue_;
284290
bool initialized_;
291+
bool finalizing_;
285292
static std::unique_ptr<Stub> stub_instance_;
286293
std::vector<std::shared_ptr<PbTensor>> gpu_tensors_;
287294
std::queue<std::unique_ptr<PbLog>> log_request_buffer_;

0 commit comments

Comments
 (0)