MODEL_PATH=${MODEL_PATH:-"/data/models"}
MODEL_NAME=${MODEL_NAME:-"DeepSeek-R1-Distill-Qwen-7B"}
KV_CACHE_DTYPE=${KV_CACHE_DTYPE:-"fp16"}
#The server needs to be bound to physical cores when starting
RUN_NODE=$(ls -d /sys/devices/system/node/node* | wc -l)
BIND_CORENUM=`cat /proc/cpuinfo | grep -E 'processor|core id|physical id' | sed 'N;N;s/\n/ /g' | sort -k 7 -k 11 -u | wc -l`
THREAD_PER_CORE=`lscpu | grep 'Thread(s) per core' | awk '{print $NF}'`
if [ $THREAD_PER_CORE -gt 1 ]; then
if grep ',' /sys/devices/system/cpu/cpu0/topology/core_cpus_list &> /dev/null; then
elif grep '-' /sys/devices/system/cpu/cpu0/topology/core_cpus_list &> /dev/null; then
echo ">>> Get unknown CPU topo: `cat /sys/devices/system/cpu/cpu0/topology/core_cpus_list`, please check" && exit 255
bind_cores=`cat /sys/devices/system/cpu/cpu*/topology/core_cpus_list | awk -F "$BIND_CORE_JOINER" '{print $1}' | sort -n | uniq | head -n ${BIND_CORENUM} | xargs`
for c in $bind_cores; do
if [ -z "$bind_core_set" ]; then
if [ $((last_bind+1)) -eq $c ]; then
if [ $c == `echo $bind_cores | awk '{print $NF}'` ]; then
if [ $bind_core_set == `echo $bind_cores | awk '{print $1}'` ]; then
bind_core_set=`echo $bind_core_set | sed 's/-\+/-/g'`
bind_core_set="0-$((BIND_CORENUM-1))"
IFS=',' read -r -a array <<< "$input"
if [[ $input == *-* ]]; then
IFS='-' read -r start end <<< "$input"
range_size=$(( (end - start + 1) / group_count ))
for ((i = 0; i < group_count; i++)); do
group_start=$(( start + i * range_size ))
group_end=$(( group_start + range_size - 1 ))
if [[ $i -eq $((group_count - 1)) ]]; then
groups[$i]="$group_start-$group_end"
array_length=${#array[@]}
group_size=$(( (array_length + group_count - 1) / group_count ))
for ((i = 0; i < group_count; i++)); do
group_start=$(( i * group_size ))
group_elements=("${array[@]:group_start:group_size}")
if [ ${#group_elements[@]} -gt 0 ]; then
groups[$i]=$(IFS=,; echo "${group_elements[*]}")
for ((i = 0; i < ${#groups[@]}; i++)); do
if [[ $input == *-* ]]; then
output+="'${groups[$i]}'"
if [ $i -ne $(( ${#groups[@]} - 1 )) ]; then
echo "core bind : $output"
RUN_NODE=$(ls -d /sys/devices/system/node/node* | wc -l)
BIND_CORENUM=`cat /proc/cpuinfo | grep -E 'processor|core id|physical id' | sed 'N;N;s/\n/ /g' | sort -k 7 -k 11 -u | wc -l`
physical_core_count=$(($BIND_CORENUM/$RUN_NODE))
#mpirun performances better on multi-numa instance
numa_count=$(ls -d /sys/devices/system/node/node* | wc -l)
export $(python3 -c 'import xfastertransformer as xft; print(xft.get_env())')
export MODEL_PATH_XFT="$MODEL_PATH/${MODEL_NAME}-xft"
export TOKEN_PATH="$MODEL_PATH/$MODEL_NAME"
if [ "$numa_count" -gt 1 ]; then
export LD_PRELOAD=/usr/local/lib/python3.10/dist-packages/xfastertransformer/libiomp5.so && source /usr/local/oneCCL/env/setvars.sh
if [ "$numa_count" -eq 2 ]; then
OMP_NUM_THREADS=$physical_core_count mpirun \
-n 1 numactl --all -C ${groups[0]} 0 -m 0 python3 -m vllm.entrypoints.openai.api_server --model $MODEL_PATH_XFT --tokenizer $TOKEN_PATH --dtype $DTYPE --kv-cache-dtype $KV_CACHE_DTYPE --served-model-name xft --port $PORT --trust-remote-code \
: -n 1 numactl --all -C ${groups[1]} -m 1 python3 -m vllm.entrypoints.slave --dtype $DTYPE --model $MODEL_PATH_XFT --kv-cache-dtype $KV_CACHE_DTYPE
elif [ "$numa_count" -eq 3 ]; then
OMP_NUM_THREADS=$physical_core_count mpirun \
-n 1 numactl --all -C ${groups[0]} -m 0 python3 -m vllm.entrypoints.openai.api_server --model $MODEL_PATH_XFT --tokenizer $TOKEN_PATH --dtype $DTYPE --kv-cache-dtype $KV_CACHE_DTYPE --served-model-name xft --port $PORT --trust-remote-code \
: -n 1 numactl --all -C ${groups[1]} -m 1 python3 -m vllm.entrypoints.slave --dtype $DTYPE --model $MODEL_PATH_XFT --kv-cache-dtype $KV_CACHE_DTYPE \
: -n 1 numactl --all -C ${groups[2]} -m 2 python3 -m vllm.entrypoints.slave --dtype $DTYPE --model $MODEL_PATH_XFT --kv-cache-dtype $KV_CACHE_DTYPE
OMP_NUM_THREADS=$physical_core_count numactl -C ${groups[0]} -m 0 python3 -m vllm.entrypoints.openai.api_server --model $MODEL_PATH_XFT --tokenizer $TOKEN_PATH --dtype $DTYPE --kv-cache-dtype $KV_CACHE_DTYPE --served-model-name xft --port $PORT --trust-remote-code