@@ -46,140 +46,7 @@ SERVER_LOG="${NAME}_server.log"
4646SERVER_TIMEOUT=${SERVER_TIMEOUT:= 120}
4747CLIENT_PY=${BASE_DIR} /orca_http_test.py
4848CLIENT_LOG=" ${NAME} _orca_http_test.log"
49- source ../common/util.sh
50-
51- function clone_tensorrt_llm_backend_repo {
52- rm -rf $TENSORRTLLM_BACKEND_DIR && mkdir $TENSORRTLLM_BACKEND_DIR
53- apt-get update && apt-get install git-lfs -y --no-install-recommends
54- git clone --single-branch --depth=1 -b ${TENSORRTLLM_BACKEND_REPO_TAG} ${TRITON_REPO_ORG} /tensorrtllm_backend.git $TENSORRTLLM_BACKEND_DIR
55- cd $TENSORRTLLM_BACKEND_DIR && git lfs install && git submodule update --init --recursive
56- }
57-
58- function build_gpt2_base_model {
59- # Download weights from HuggingFace Transformers
60- cd ${GPT_DIR} && rm -rf gpt2 && git clone https://huggingface.co/gpt2-medium gpt2 && cd gpt2
61- rm pytorch_model.bin model.safetensors
62- if ! wget -q https://huggingface.co/gpt2-medium/resolve/main/pytorch_model.bin; then
63- echo " Downloading pytorch_model.bin failed."
64- exit 1
65- fi
66- cd ${GPT_DIR}
67-
68- # Convert weights from HF Tranformers to FT format
69- python3 convert_checkpoint.py --model_dir gpt2 --dtype float16 --tp_size ${NUM_GPUS} --output_dir " ./c-model/gpt2/${NUM_GPUS} -gpu/"
70- cd ${BASE_DIR}
71- }
72-
73- function build_gpt2_tensorrt_engine {
74- # Build TensorRT engines
75- cd ${GPT_DIR}
76- trtllm-build --checkpoint_dir " ./c-model/gpt2/${NUM_GPUS} -gpu/" \
77- --gpt_attention_plugin float16 \
78- --remove_input_padding enable \
79- --paged_kv_cache enable \
80- --gemm_plugin float16 \
81- --workers " ${NUM_GPUS} " \
82- --output_dir " ${ENGINES_DIR} "
83-
84- cd ${BASE_DIR}
85- }
86-
87- function replace_config_tags {
88- tag_to_replace=" ${1} "
89- new_value=" ${2} "
90- config_file_path=" ${3} "
91- sed -i " s|${tag_to_replace} |${new_value} |g" ${config_file_path}
92- }
93-
94- function prepare_model_repository {
95- rm -rf ${MODEL_REPOSITORY} && mkdir ${MODEL_REPOSITORY}
96- cp -r ${TENSORRTLLM_BACKEND_DIR} /tensorrt_llm/triton_backend/all_models/inflight_batcher_llm/* ${MODEL_REPOSITORY}
97- rm -rf ${MODEL_REPOSITORY} /tensorrt_llm_bls
98- mv " ${MODEL_REPOSITORY} /ensemble" " ${MODEL_REPOSITORY} /${MODEL_NAME} "
99-
100- replace_config_tags " model_version: -1" " model_version: 1" " ${MODEL_REPOSITORY} /${MODEL_NAME} /config.pbtxt"
101- replace_config_tags ' ${triton_max_batch_size}' " 128" " ${MODEL_REPOSITORY} /${MODEL_NAME} /config.pbtxt"
102- replace_config_tags ' name: "ensemble"' " name: \" $MODEL_NAME \" " " ${MODEL_REPOSITORY} /${MODEL_NAME} /config.pbtxt"
103- replace_config_tags ' ${logits_datatype}' " TYPE_FP32" " ${MODEL_REPOSITORY} /${MODEL_NAME} /config.pbtxt"
104-
105- replace_config_tags ' ${triton_max_batch_size}' " 128" " ${MODEL_REPOSITORY} /preprocessing/config.pbtxt"
106- replace_config_tags ' ${preprocessing_instance_count}' ' 1' " ${MODEL_REPOSITORY} /preprocessing/config.pbtxt"
107- replace_config_tags ' ${tokenizer_dir}' " ${TOKENIZER_DIR} /" " ${MODEL_REPOSITORY} /preprocessing/config.pbtxt"
108- replace_config_tags ' ${logits_datatype}' " TYPE_FP32" " ${MODEL_REPOSITORY} /preprocessing/config.pbtxt"
109- replace_config_tags ' ${max_queue_delay_microseconds}' " 1000000" " ${MODEL_REPOSITORY} /preprocessing/config.pbtxt"
110- replace_config_tags ' ${max_queue_size}' " 0" " ${MODEL_REPOSITORY} /preprocessing/config.pbtxt"
111-
112- replace_config_tags ' ${triton_max_batch_size}' " 128" " ${MODEL_REPOSITORY} /postprocessing/config.pbtxt"
113- replace_config_tags ' ${postprocessing_instance_count}' ' 1' " ${MODEL_REPOSITORY} /postprocessing/config.pbtxt"
114- replace_config_tags ' ${tokenizer_dir}' " ${TOKENIZER_DIR} /" " ${MODEL_REPOSITORY} /postprocessing/config.pbtxt"
115- replace_config_tags ' ${logits_datatype}' " TYPE_FP32" " ${MODEL_REPOSITORY} /postprocessing/config.pbtxt"
116-
117- replace_config_tags ' ${triton_max_batch_size}' " 128" " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
118- replace_config_tags ' ${decoupled_mode}' ' true' " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
119- replace_config_tags ' ${max_queue_delay_microseconds}' " 1000000" " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
120- replace_config_tags ' ${batching_strategy}' ' inflight_fused_batching' " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
121- replace_config_tags ' ${engine_dir}' " ${ENGINES_DIR} " " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
122- replace_config_tags ' ${triton_backend}' " tensorrtllm" " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
123- replace_config_tags ' ${max_queue_size}' " 0" " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
124- replace_config_tags ' ${logits_datatype}' " TYPE_FP32" " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
125- replace_config_tags ' ${encoder_input_features_data_type}' " TYPE_FP32" " ${MODEL_REPOSITORY} /tensorrt_llm/config.pbtxt"
126- }
127-
128- # Wait until server health endpoint shows ready. Sets WAIT_RET to 0 on
129- # success, 1 on failure
130- function wait_for_server_ready() {
131- local wait_time_secs=" ${1:- 30} "
132- shift
133- local spids=(" $@ " )
134-
135- WAIT_RET=0
136-
137- for _ in $( seq " $wait_time_secs " ) ; do
138- for pid in " ${spids[@]} " ; do
139- if ! kill -0 " $pid " > /dev/null 2>&1 ; then
140- echo " === Server not running."
141- WAIT_RET=1
142- return
143- fi
144- done
145-
146- sleep 1
147-
148- if curl -s --fail localhost:8000/v2/health/ready &&
149- curl -s --fail -w " %{http_code}" -o /dev/null -d ' {"log_verbose_level":1}' localhost:8000/v2/logging; then
150- return
151- fi
152- done
153-
154- echo " === Timeout $wait_time_secs secs. Server not ready."
155- WAIT_RET=1
156- }
157-
158- function run_server {
159- python3 ${TENSORRTLLM_BACKEND_DIR} /tensorrt_llm/triton_backend/scripts/launch_triton_server.py --world_size=" ${NUM_GPUS} " --model_repo=" ${MODEL_REPOSITORY} " > ${SERVER_LOG} 2>&1 &
160- sleep 2 # allow time to obtain the pid(s)
161- # Read PIDs into an array, trimming whitespaces
162- readarray -t SERVER_PID < <( pgrep " tritonserver" )
163-
164- wait_for_server_ready ${SERVER_TIMEOUT} " ${SERVER_PID[@]} "
165- if [ " $WAIT_RET " != " 0" ]; then
166- # Cleanup
167- kill " ${SERVER_PID[@]} " > /dev/null 2>&1 || true
168- echo -e " \n***\n*** Failed to start $SERVER \n***"
169- cat $SERVER_LOG
170- exit 1
171- fi
172- }
173-
174- function kill_server {
175- pgrep tritonserver | xargs kill -SIGINT
176- for pid in " ${SERVER_PID[@]} " ; do
177- echo " Waiting for proc ${pid} to terminate..."
178- while kill -0 $pid > /dev/null 2>&1 ; do
179- sleep 1
180- done
181- done
182- }
49+ source ../common/trtllm_util.sh
18350
18451clone_tensorrt_llm_backend_repo
18552build_gpt2_base_model
0 commit comments