Skip to content

Commit 3037b27

Browse files
committed
always emit a message with number of threads
1 parent a4146b2 commit 3037b27

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/libtorch.cc

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,15 @@ ModelState::ParseParameters()
517517
if (intra_op_thread_count > 0) {
518518
// at::set_num_threads() does not throw if called more than once, but issues warnings.
519519
// std::call_once() is useful to limit these.
520-
std::call_once(pytorch_intraop_threads_flag, [this, intra_op_thread_count](){
520+
std::call_once(pytorch_intraop_threads_flag, [intra_op_thread_count](){
521521
at::set_num_threads(intra_op_thread_count);
522-
LOG_MESSAGE(
523-
TRITONSERVER_LOG_INFO,
524-
(std::string("Intra op thread count is set to ") +
525-
std::to_string(intra_op_thread_count) + " for model instance '" +
526-
this->Name() + "'")
527-
.c_str());
528522
});
523+
LOG_MESSAGE(
524+
TRITONSERVER_LOG_INFO,
525+
(std::string("Intra op thread count is set to ") +
526+
std::to_string(at::get_num_threads()) + " for model instance '" +
527+
Name() + "'")
528+
.c_str());
529529
}
530530
}
531531

@@ -545,26 +545,19 @@ ModelState::ParseParameters()
545545
if (inter_op_thread_count > 0) {
546546
// at::set_num_interop_threads() throws if called more than once.
547547
// std::call_once() should prevent this, but try/catch is additionally used for safety.
548-
std::call_once(pytorch_interop_threads_flag, [this, inter_op_thread_count](){
548+
std::call_once(pytorch_interop_threads_flag, [inter_op_thread_count](){
549549
try {
550550
at::set_num_interop_threads(inter_op_thread_count);
551-
LOG_MESSAGE(
552-
TRITONSERVER_LOG_INFO,
553-
(std::string("Inter op thread count is set to ") +
554-
std::to_string(inter_op_thread_count) + " for model instance '" +
555-
Name() + "'")
556-
.c_str());
557551
} catch (const c10::Error& e) {
558-
int current_inter_op_thread_count = at::get_num_interop_threads();
559-
bool current_is_requested = inter_op_thread_count == current_inter_op_thread_count;
560-
LOG_MESSAGE(
561-
TRITONSERVER_LOG_INFO,
562-
(std::string("Inter op thread count is already set to ") +
563-
std::to_string(current_inter_op_thread_count) +
564-
(current_is_requested ? "" : " and cannot be changed. Setting ignored") +
565-
" for model instance '" + this->Name() + "'").c_str());
552+
// do nothing
566553
}
567554
});
555+
LOG_MESSAGE(
556+
TRITONSERVER_LOG_INFO,
557+
(std::string("Inter op thread count is set to ") +
558+
std::to_string(at::get_num_interop_threads()) + " for model instance '" +
559+
Name() + "'")
560+
.c_str());
568561
}
569562
}
570563
}

0 commit comments

Comments
 (0)