Skip to content

fix: Strip trailing separators from --backend-directory path#443

Open
nsiddharth wants to merge 1 commit into
triton-inference-server:mainfrom
nsiddharth:fix/6730-backend-directory-trailing-slash
Open

fix: Strip trailing separators from --backend-directory path#443
nsiddharth wants to merge 1 commit into
triton-inference-server:mainfrom
nsiddharth:fix/6730-backend-directory-trailing-slash

Conversation

@nsiddharth

Copy link
Copy Markdown

What

A trailing path separator on --backend-directory (e.g. --backend-directory=/opt/tritonserver/backends/) causes every Python-backend model to fail to load with:

Internal: ModuleNotFoundError: No module named 'model'

Why

In TRITONBACKEND_Initialize (src/python_be.cc), the backend directory is concatenated as default_backend_dir_string + os_slash + "python". With a trailing slash this yields /opt/tritonserver/backends//python, which is then compared for equality against the resolved backend location (/opt/tritonserver/backends/python). The // vs / mismatch makes the check fail, so runtime_modeldir is set to the backend path instead of "" (DEFAULT). The stub is then launched as if a custom Python-based backend runtime lives there and tries to import a module named model, which does not exist.

Fix

Strip any trailing path separators from default_backend_dir_string before the comparison, so the default Python backend is detected regardless of a trailing slash.

Verification

Reproduced and verified in a CPU-only nvcr.io/nvidia/tritonserver:25.02-py3 container (arm64), rebuilding libtriton_python.so from this branch and loading a minimal Python model:

--backend-directory before fix after fix
/opt/tritonserver/backends/ (trailing slash) model UNAVAILABLEModuleNotFoundError: No module named 'model'; stub runtime_modeldir = /opt/tritonserver/backends/python model READY; runtime_modeldir = DEFAULT
/opt/tritonserver/backends (no slash) READY READY (no regression)

Fixes triton-inference-server/server#6730

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 <n.siddharth@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Python backend doesn't load model.py in the model directory properly when trailing slashes(/) present in --backend-directory option

1 participant