From 28ac1727de6a2ab92deae8d29c602f4a56ff6028 Mon Sep 17 00:00:00 2001 From: nsiddharth Date: Fri, 19 Jun 2026 21:38:13 -0700 Subject: [PATCH] fix: Strip trailing separators from --backend-directory path A trailing path separator on --backend-directory (e.g. `--backend-directory=/opt/tritonserver/backends/`) produced `/opt/tritonserver/backends//python`, which failed the equality check against the resolved backend location. runtime_modeldir was then set to the backend path instead of "DEFAULT", so every Python model failed to load with `ModuleNotFoundError: No module named 'model'`. Strip trailing separators from the backend directory before the comparison so the default Python backend is detected regardless of a trailing slash. Fixes triton-inference-server/server#6730 Signed-off-by: nsiddharth --- src/python_be.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/python_be.cc b/src/python_be.cc index 4c9ca49e..ba57a789 100644 --- a/src/python_be.cc +++ b/src/python_be.cc @@ -2419,6 +2419,16 @@ TRITONBACKEND_Initialize(TRITONBACKEND_Backend* backend) #else const std::string stub_executable_name = "triton_python_backend_stub"; #endif + // Remove any trailing path separators from the backend directory. Otherwise a + // value such as `--backend-directory=/opt/tritonserver/backends/` yields + // `/opt/tritonserver/backends//python`, which fails the equality check with + // the resolved backend `location` below and prevents the default Python + // backend from being detected. + // See: https://github.com/triton-inference-server/server/issues/6730 + while (default_backend_dir_string.size() > 1 && + default_backend_dir_string.back() == os_slash) { + default_backend_dir_string.pop_back(); + } // Check if `triton_python_backend_stub` and `triton_python_backend_utils.py` // are located under `location`. std::string default_python_backend_dir =