Skip to content

Commit c0d1661

Browse files
committed
make vlm detection more robust in ptq workflow
Signed-off-by: Zhiyu Cheng <[email protected]>
1 parent 29b4cf2 commit c0d1661

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

examples/llm_ptq/hf_ptq.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
from accelerate.hooks import remove_hook_from_module
2626
from example_utils import apply_kv_cache_quant, get_model, get_processor, get_tokenizer, is_enc_dec
2727
from transformers import (
28+
AutoConfig,
2829
AutoModelForCausalLM,
30+
AutoProcessor,
2931
PreTrainedTokenizer,
3032
PreTrainedTokenizerFast,
3133
WhisperProcessor,
@@ -567,9 +569,18 @@ def output_decode(generated_ids, input_shape):
567569

568570
export_path = args.export_path
569571

570-
if hasattr(full_model, "language_model"):
572+
# Check for VLMs by looking for vision_config in model config or language_model attribute
573+
is_vlm = False
574+
try:
575+
is_vlm = hasattr(full_model.config, "vision_config") or hasattr(
576+
full_model, "language_model"
577+
)
578+
except Exception:
579+
# Fallback to the original check if config access fails
580+
is_vlm = hasattr(full_model, "language_model")
581+
582+
if is_vlm:
571583
# Save original model config and the preprocessor config to the export path for VLMs.
572-
from transformers import AutoConfig, AutoProcessor
573584

574585
print(f"Saving original model and processor configs to {export_path}")
575586

0 commit comments

Comments
 (0)