forked from dusty-nv/jetson-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,69 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
set -ex | ||
|
||
MODEL_NAME=${1:-"Llama-2-7b-hf"} | ||
MODEL_PATH=${2:-"https://nvidia.box.com/shared/static/i3jtp8jdmdlsq4qkjof8v4muth8ar7fo.gz"} | ||
MODEL_ROOT="/data/models/mlc/dist" | ||
MLC_USE_CACHE=${MLC_USE_CACHE:-1} | ||
|
||
test_model() | ||
QUANTIZATION=${QUANTIZATION:-"q4f16_ft"} | ||
QUANTIZATION_PATH="${MODEL_ROOT}/${MODEL_NAME}-${QUANTIZATION}" | ||
SKIP_QUANTIZATION=${SKIP_QUANTIZATION:-"no"} | ||
|
||
USE_CACHE=${USE_CACHE:-1} | ||
CONV_TEMPLATE=${CONV_TEMPLATE:-"llama-2"} | ||
MAX_CONTEXT_LEN=${MAX_CONTEXT_LEN:-4096} | ||
|
||
|
||
quantize() # mlc_llm >= 0.1.1 | ||
{ | ||
local MODEL_NAME=$1 | ||
local MODEL_URL=$2 | ||
local MODEL_TAR="$MODEL_NAME.tar.gz" | ||
local QUANTIZATION=${3:-q4f16_ft} | ||
QUANTIZATION_LIB="$QUANTIZATION_PATH/$MODEL_NAME-$QUANTIZATION-cuda.so" | ||
|
||
if [ ! -d "$MODEL_ROOT/models/$MODEL_NAME" ]; then | ||
if [ $SKIP_QUANTIZATION != "yes" ]; then | ||
mlc_llm convert_weight $MODEL_PATH --quantization $QUANTIZATION --output $QUANTIZATION_PATH | ||
mlc_llm gen_config $MODEL_PATH --quantization $QUANTIZATION --conv-template $CONV_TEMPLATE --context-window-size $MAX_CONTEXT_LEN --max-batch-size 1 --output $QUANTIZATION_PATH | ||
mlc_llm compile $QUANTIZATION_PATH --device cuda --opt O3 --output $QUANTIZATION_LIB | ||
fi | ||
|
||
QUANTIZATION_LIB="--model-lib-path $QUANTIZATION_LIB" | ||
} | ||
|
||
quantize_legacy() # mlc_llm == 0.1.0 | ||
{ | ||
if [ $SKIP_QUANTIZATION != "yes" ]; then | ||
python3 -m mlc_llm.build \ | ||
--model $MODEL_NAME \ | ||
--target cuda \ | ||
--use-cuda-graph \ | ||
--use-flash-attn-mqa \ | ||
--use-cache $USE_CACHE \ | ||
--quantization $QUANTIZATION \ | ||
--artifact-path $MODEL_ROOT \ | ||
--max-seq-len 4096 | ||
|
||
if [ $? != 0 ]; then | ||
return 1 | ||
fi | ||
fi | ||
|
||
QUANTIZATION_PATH="$QUANTIZATION_PATH/params" | ||
} | ||
|
||
if [[ $MODEL_PATH == http* ]]; then | ||
MODEL_EXTRACTED="$MODEL_ROOT/models/$MODEL_NAME" | ||
if [ ! -d "$MODEL_EXTRACTED" ]; then | ||
cd $MODEL_ROOT/models | ||
wget --quiet --show-progress --progress=bar:force:noscroll --no-check-certificate $MODEL_URL -O $MODEL_TAR | ||
MODEL_TAR="$MODEL_NAME.tar.gz" | ||
wget --quiet --show-progress --progress=bar:force:noscroll --no-check-certificate $MODEL_PATH -O $MODEL_TAR | ||
tar -xzvf $MODEL_TAR | ||
#rm $MODEL_TAR | ||
fi | ||
MODEL_PATH=$MODEL_EXTRACTED | ||
fi | ||
|
||
cd $MODEL_ROOT | ||
|
||
python3 -m mlc_llm.build \ | ||
--model $MODEL_NAME \ | ||
--target cuda \ | ||
--use-cuda-graph \ | ||
--use-flash-attn-mqa \ | ||
--use-cache $MLC_USE_CACHE \ | ||
--quantization $QUANTIZATION \ | ||
--artifact-path $MODEL_ROOT \ | ||
--max-seq-len 4096 | ||
|
||
python3 /opt/mlc-llm/benchmark.py \ | ||
--model ${MODEL_ROOT}/${MODEL_NAME}-${QUANTIZATION}/params \ | ||
--max-new-tokens 128 \ | ||
--max-num-prompts 4 \ | ||
--prompt /data/prompts/completion.json | ||
} | ||
quantize_legacy || quantize | ||
|
||
test_model "Llama-2-7b-hf" "https://nvidia.box.com/shared/static/i3jtp8jdmdlsq4qkjof8v4muth8ar7fo.gz" | ||
python3 benchmark.py \ | ||
--model $QUANTIZATION_PATH $QUANTIZATION_LIB \ | ||
--max-new-tokens 128 \ | ||
--max-num-prompts 4 \ | ||
--prompt /data/prompts/completion.json |