Skip to content

Commit bc62a24

Browse files
committed
qwen quantize and hf export support in examples
1 parent d6d2e75 commit bc62a24

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

examples/llm_ptq/hf_ptq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ def output_decode(generated_ids, input_shape):
742742
)
743743
parser.add_argument(
744744
"--verbose",
745-
help="Print verbose output (e.g. quantization summary). Disable by --no_verbose.",
745+
help="Print verbose output (e.g. quantization summary). Disable by --no-verbose.",
746746
default=True,
747747
action=argparse.BooleanOptionalAction,
748748
)

examples/vlm_ptq/scripts/huggingface_example.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ for i in $(env | grep ^PMI_ | cut -d"=" -f 1); do unset -v $i; done
3030
for i in $(env | grep ^PMIX_ | cut -d"=" -f 1); do unset -v $i; done
3131

3232
case $MODEL_TYPE in
33-
llava|phi|vila|mllama)
33+
llava|phi|vila|mllama|qwen)
3434
;;
3535
*)
36-
echo "Unsupported type argument: Expected one of: [llava, phi, vila, mllama]" >&2
36+
echo "Unsupported type argument: Expected one of: [llava, phi, vila, mllama, qwen]" >&2
3737
exit 1
3838
esac
3939

@@ -91,7 +91,7 @@ fi
9191

9292
BUILD_MAX_OUTPUT_LEN=512
9393

94-
if [ "$MODEL_TYPE" = "llava" ] || [ "$MODEL_TYPE" = "vila" ]; then
94+
if [ "$MODEL_TYPE" = "llava" ] || [ "$MODEL_TYPE" = "vila" ] || [ "$MODEL_TYPE" = "qwen" ]; then
9595
BUILD_MAX_BATCH_SIZE=20
9696
else
9797
BUILD_MAX_BATCH_SIZE=4
@@ -149,6 +149,10 @@ case "${MODEL_TYPE}" in
149149
PTQ_ARGS+=" --kv_cache_qformat none "
150150
VLM_ARGS=" --max_encoder_input_len=6404 --skip_run"
151151
;;
152+
"qwen")
153+
PTQ_ARGS+=" --kv_cache_qformat none "
154+
EXPORT_FORMAT="hf"
155+
;;
152156
esac
153157

154158
if [ "${MODEL_TYPE}" = "vila" ]; then
@@ -177,6 +181,7 @@ if [[ $TASKS =~ "build" ]] || [[ ! -d "$ENGINE_DIR" ]] || [[ ! $(ls -A $ENGINE_D
177181
--inference_tensor_parallel=$TP \
178182
--inference_pipeline_parallel=$PP \
179183
--export_fmt=$EXPORT_FORMAT \
184+
--no-verbose \
180185
$PTQ_ARGS
181186
else
182187
echo "Quantized model config $MODEL_CONFIG exists, skipping the quantization stage"
@@ -213,6 +218,10 @@ case "${MODEL_TYPE}" in
213218
"phi")
214219
VISUAL_MODEL_TYPE="phi-3-vision"
215220
;;
221+
"qwen")
222+
# Map generic type to TRT-LLM multimodal model type
223+
VISUAL_MODEL_TYPE="qwen2_vl"
224+
;;
216225
esac
217226

218227

modelopt/torch/export/model_config_export.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ def torch_to_tensorrt_llm_checkpoint(
362362
"glm",
363363
"llama",
364364
"mllama",
365+
"qwen",
365366
], f"lm_head not available for decoder {decoder_type}"
366367
config.share_embedding_table = True
367368

modelopt/torch/export/plugins/hf_spec_export.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ def rename_and_prune_if_spec_decoding(model: nn.Module, post_state_dict: dict):
8282

8383
def set_config_if_spec_decoding(model: nn.Module, config_data: dict):
8484
"""Return the config of draft model in official format."""
85-
if len(model._modelopt_state) != 1 or model._modelopt_state[0][0] != "eagle":
85+
opt_modes = getattr(model, "_modelopt_state", None)
86+
if (
87+
not isinstance(opt_modes, (list, tuple))
88+
or len(opt_modes) != 1
89+
or opt_modes[0][0] != "eagle"
90+
):
8691
# return as is
8792
return config_data
8893

0 commit comments

Comments
 (0)