Skip to content

Commit 96e1d93

Browse files
authored
Fix Autocomplete To Use CPU When No GPU Found (#118)
* fix autocomplete to use cpu instance when no gpu found * default to kind cpu in autocomplete; took out KIND_AUTO check in autocomplete * simplified logic when setting the instance group kind in autocomplete
1 parent 493d43e commit 96e1d93

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/onnxruntime.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,36 @@ ModelState::AutoCompleteConfig()
682682
OrtAllocator* default_allocator;
683683
std::string model_path;
684684
{
685+
TRITONSERVER_InstanceGroupKind kind = TRITONSERVER_INSTANCEGROUPKIND_CPU;
686+
687+
#ifdef TRITON_ENABLE_GPU
688+
triton::common::TritonJson::Value instance_group;
689+
ModelConfig().Find("instance_group", &instance_group);
690+
691+
// Earlier in the model lifecycle, device checks for the instance group
692+
// have already occurred. If at least one instance group with
693+
// "kind" = "KIND_GPU" then allow model to use GPU else autocomplete to
694+
// "KIND_CPU"
695+
for (size_t i = 0; i < instance_group.ArraySize(); ++i) {
696+
triton::common::TritonJson::Value instance_obj;
697+
instance_group.IndexAsObject(i, &instance_obj);
698+
699+
triton::common::TritonJson::Value instance_group_kind;
700+
instance_obj.Find("kind", &instance_group_kind);
701+
std::string kind_str;
702+
RETURN_IF_ERROR(instance_group_kind.AsString(&kind_str));
703+
704+
if (kind_str == "KIND_GPU") {
705+
kind = TRITONSERVER_INSTANCEGROUPKIND_GPU;
706+
break;
707+
}
708+
}
709+
#endif // TRITON_ENABLE_GPU
710+
685711
OrtSession* sptr = nullptr;
686712
RETURN_IF_ERROR(LoadModel(
687-
artifact_name, TRITONSERVER_INSTANCEGROUPKIND_AUTO, 0, &model_path,
688-
&sptr, &default_allocator, nullptr));
713+
artifact_name, kind, 0, &model_path, &sptr, &default_allocator,
714+
nullptr));
689715
session.reset(sptr);
690716
}
691717
OnnxTensorInfoMap input_tensor_infos;

0 commit comments

Comments
 (0)