Skip to content

Commit bbc0b54

Browse files
authored
ci: Support user-defined is_ready() in Python backend readiness checks (#8661)
1 parent 6b0539b commit bbc0b54

6 files changed

Lines changed: 771 additions & 13 deletions

File tree

qa/L0_backend_python/model_readiness/test.sh

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# Copyright 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -47,7 +47,7 @@ cp ../../python_models/$MODEL_NAME/config.pbtxt ./models/$MODEL_NAME/config.pbtx
4747
for SIGNAL in 11 9; do
4848
echo -e "\n***\n*** Testing model_readiness with Signal $SIGNAL\n***"
4949
SERVER_LOG="./model_readiness_signal_${SIGNAL}_server.log"
50-
CLIENT_LOG="./model_readiness_${SIGNAL}_client.log"
50+
CLIENT_LOG="./model_readiness_signal_${SIGNAL}_client.log"
5151

5252
run_server
5353
if [ "$SERVER_PID" == "0" ]; then
@@ -107,10 +107,87 @@ for SIGNAL in 11 9; do
107107
kill_server
108108
done
109109

110+
#
111+
# Test User-Defined Model Readiness Function
112+
#
113+
echo -e "\n***\n*** Testing User-Defined is_ready() Function\n***"
114+
115+
# Helper function to set up test models with different readiness behaviors based on config parameters
116+
setup_readiness_test_model() {
117+
local model_name=$1
118+
local return_value=$2
119+
local delay_secs=$3
120+
121+
mkdir -p ./models/$model_name/1/
122+
if [ "$model_name" == "is_ready_fn_coroutine_returns_true" ]; then
123+
cp ./test_models/readiness_coroutine_model.py ./models/$model_name/1/model.py
124+
else
125+
cp ./test_models/readiness_model.py ./models/$model_name/1/model.py
126+
fi
127+
cp ./models/identity_fp32/config.pbtxt ./models/$model_name/config.pbtxt
128+
sed -i "s/^name:.*/name: \"$model_name\"/" ./models/$model_name/config.pbtxt
129+
cat >> ./models/$model_name/config.pbtxt << EOF
130+
parameters: {
131+
key: "READINESS_FN_RETURN_VALUE"
132+
value: { string_value: "$return_value" }
133+
}
134+
parameters: {
135+
key: "READINESS_FN_DELAY_SECS"
136+
value: { string_value: "$delay_secs" }
137+
}
138+
EOF
139+
}
140+
141+
# Create readiness test models using shared model.py + config parameters
142+
setup_readiness_test_model "is_ready_fn_returns_true" "true" "0.1"
143+
setup_readiness_test_model "is_ready_fn_returns_false" "false" "0.1"
144+
setup_readiness_test_model "is_ready_fn_raises_error" "exception" "0.1"
145+
setup_readiness_test_model "is_ready_fn_returns_non_boolean" "non_boolean" "0.1"
146+
setup_readiness_test_model "is_ready_fn_timeout" "true" "8"
147+
setup_readiness_test_model "is_ready_fn_coroutine_returns_true" "coroutine" "0.1"
148+
149+
# Decoupled model has a unique execute() and its own config
150+
mkdir -p ./models/is_ready_fn_returns_true_decoupled/1/
151+
cp ./test_models/is_ready_fn_returns_true_decoupled/model.py \
152+
./models/is_ready_fn_returns_true_decoupled/1/model.py
153+
cp ./test_models/is_ready_fn_returns_true_decoupled/config.pbtxt \
154+
./models/is_ready_fn_returns_true_decoupled/config.pbtxt
155+
156+
# Start server with all models
157+
SERVER_ARGS="--model-repository=$(pwd)/models --backend-directory=${BACKEND_DIR} --log-verbose=1"
158+
SERVER_LOG="./test_user_defined_model_readiness_function_server.log"
159+
CLIENT_LOG="./test_user_defined_model_readiness_function_client.log"
160+
161+
run_server
162+
if [ "$SERVER_PID" == "0" ]; then
163+
cat $SERVER_LOG
164+
echo -e "\n***\n*** Failed to start $SERVER\n***"
165+
exit 1
166+
fi
167+
168+
set +e
169+
170+
echo "Running TestUserDefinedModelReadinessFunction..."
171+
python3 -m unittest test_model_readiness.TestUserDefinedModelReadinessFunction -v >> ${CLIENT_LOG} 2>&1
172+
TEST_EXIT_CODE=$?
173+
174+
if [ $TEST_EXIT_CODE -ne 0 ]; then
175+
echo -e "\n***\n*** TestUserDefinedModelReadinessFunction FAILED\n***"
176+
cat ${CLIENT_LOG}
177+
RET=1
178+
else
179+
echo -e "\n***\n*** TestUserDefinedModelReadinessFunction PASSED\n***"
180+
fi
181+
182+
set -e
183+
kill_server
184+
185+
186+
# Final result
110187
if [ $RET -eq 0 ]; then
111-
echo -e "\n***\n*** Test Passed\n***"
188+
echo -e "\n***\n*** All Model Readiness Tests Passed\n***"
112189
else
113-
echo -e "\n***\n*** Test FAILED\n***"
190+
echo -e "\n***\n*** Model Readiness Tests FAILED\n***"
114191
fi
115192

116193
exit $RET

0 commit comments

Comments
 (0)