Skip to content

Commit 2d177d5

Browse files
authored
Use already defined constant for Python related names (#281)
1 parent 0b5a9a1 commit 2d177d5

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/backend_manager.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ TritonBackendManager::CreateBackend(
342342
{
343343
std::lock_guard<std::mutex> lock(mu_);
344344

345-
const auto python_based_backend_path = dir + "/model.py";
345+
const auto python_based_backend_path = JoinPath({dir, kPythonFilename});
346346
std::vector<std::string> paths = {libpath, python_based_backend_path};
347347
for (const auto& path : paths) {
348348
const auto& itr = backend_map_.find(path);
@@ -386,7 +386,7 @@ TritonBackendManager::BackendState(
386386
for (const auto& backend_pair : backend_map_) {
387387
auto& libpath = backend_pair.first;
388388
auto backend = backend_pair.second;
389-
if (backend->Name() == "python") {
389+
if (backend->Name() == kPythonBackend) {
390390
has_python_backend = true;
391391
}
392392
const char* backend_config;
@@ -401,7 +401,7 @@ TritonBackendManager::BackendState(
401401
}
402402

403403
if (!has_python_backend && !python_backend_config.empty()) {
404-
backend_state_map->insert({"python", python_backend_config});
404+
backend_state_map->insert({kPythonBackend, python_backend_config});
405405
}
406406

407407
*backend_state = std::move(backend_state_map);

src/backend_model.cc

+9-8
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ TritonModel::Create(
131131
return Status(
132132
Status::Code::INVALID_ARG,
133133
"unable to find '" + backend_libname + "' or '" +
134-
specialized_backend_name + "/model.py' for model '" +
134+
specialized_backend_name + "/" + kPythonFilename + "' for model '" +
135135
model_config.name() + "', searched: " + version_path + ", " +
136136
model_path + ", " + global_path);
137137
}
@@ -146,8 +146,8 @@ TritonModel::Create(
146146
is_python_based_backend = true;
147147
// Python backend based backends use configs, specified for python backend
148148
// in cmdline.
149-
RETURN_IF_ERROR(
150-
ResolveBackendConfigs(backend_cmdline_config_map, "python", config));
149+
RETURN_IF_ERROR(ResolveBackendConfigs(
150+
backend_cmdline_config_map, kPythonBackend, config));
151151
} else {
152152
RETURN_IF_ERROR(ResolveBackendConfigs(
153153
backend_cmdline_config_map, backend_name, config));
@@ -356,7 +356,8 @@ TritonModel::ResolveBackendPaths(
356356
// If not found, then we are processing a python-based backend.
357357
// We look for libtriton_python.so in python backend directory
358358
// and model.py in provided custom backend's directory
359-
std::string python_backend_dir = JoinPath({global_backend_dir, "python"});
359+
std::string python_backend_dir =
360+
JoinPath({global_backend_dir, kPythonBackend});
360361
bool is_dir;
361362
RETURN_IF_ERROR(IsDirectory(python_backend_dir, &is_dir));
362363
if (!is_dir) {
@@ -367,21 +368,21 @@ TritonModel::ResolveBackendPaths(
367368
}
368369
search_paths.emplace_back(python_backend_dir);
369370
std::string runtime_model_path =
370-
JoinPath({global_backend_dir, backend_name, "model.py"});
371+
JoinPath({global_backend_dir, backend_name, kPythonFilename});
371372
bool exists;
372373
RETURN_IF_ERROR(FileExists(runtime_model_path, &exists));
373374
if (!exists) {
374375
return Status(
375376
Status::Code::INVALID_ARG,
376-
"unable to find '" + backend_libname + "' or '" + backend_name +
377-
"/model.py' for model '" + model_name + "', in " +
377+
"unable to find '" + backend_libname + "' or '" + backend_name + "/" +
378+
kPythonFilename + "' for model '" + model_name + "', in " +
378379
JoinPath({global_backend_dir, backend_name}));
379380
}
380381

381382
*python_runtime_modeldir = JoinPath({global_backend_dir, backend_name});
382383
std::string python_backend_libname;
383384
RETURN_IF_ERROR(BackendConfigurationBackendLibraryName(
384-
"python", &python_backend_libname));
385+
kPythonBackend, &python_backend_libname));
385386

386387
RETURN_IF_ERROR(LocateBackendLibrary(
387388
search_paths, python_backend_libname, backend_libdir, backend_libpath));

src/model_config_utils.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ LocalizePythonBackendExecutionEnvironmentPath(
883883
const std::string& model_path, inference::ModelConfig* config,
884884
std::shared_ptr<LocalizedPath>* localized_model_dir)
885885
{
886-
if (config->backend() == "python") {
886+
if (config->backend() == kPythonBackend) {
887887
if (config->parameters().contains("EXECUTION_ENV_PATH")) {
888888
// Read EXECUTION_ENV_PATH
889889
std::string exec_env_path =

0 commit comments

Comments
 (0)