Skip to content

Commit 138bdaa

Browse files
authored
[Smoothquant] Phi3 Vision Mappings (#1089)
## Purpose ## * Provide phi3 vision smoothquant mappings so that users who use the phi3 vision model from the multimodal blog post don't run into an issue ## Changes ## * Add `PHI3_VISION_SMOOTHQUANT_MAPPINGS` * Add smoothquant to phi3 vision example ## Testing ## * Ran `examples/multimodal_vision/phi3_vision_example.py` to completion Signed-off-by: Kyle Sayers <[email protected]>
1 parent b105c55 commit 138bdaa

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

examples/multimodal_vision/phi3_vision_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from transformers import AutoModelForCausalLM, AutoProcessor
33

44
from llmcompressor.modifiers.quantization import GPTQModifier
5+
from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
56
from llmcompressor.transformers import oneshot
67
from llmcompressor.transformers.utils.data_collator import phi3_vision_data_collator
78

@@ -61,6 +62,7 @@ def tokenize(sample):
6162

6263
# Recipe
6364
recipe = [
65+
SmoothQuantModifier(smoothing_strength=0.8),
6466
GPTQModifier(
6567
targets="Linear",
6668
scheme="W4A16",

src/llmcompressor/modifiers/smoothquant/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
smooth_layers="re:.*post_attention_layernorm",
4444
),
4545
]
46+
PHI3_VISION_SMOOTHQUANT_MAPPINGS: List[LayerMap] = [
47+
LayerMap(
48+
balance_layers=["re:.*qkv_proj"],
49+
smooth_layers="re:.*input_layernorm",
50+
),
51+
LayerMap(
52+
balance_layers=["re:.*gate_up_proj"],
53+
smooth_layers="re:.*post_attention_layernorm",
54+
),
55+
]
4656

4757

4858
# Registry of layer mappings for different architectures
@@ -54,6 +64,7 @@
5464
"Qwen2ForCausalLM": DEFAULT_SMOOTHQUANT_MAPPINGS,
5565
"BloomForCausalLM": BLOOM_SMOOTHQUANT_MAPPINGS,
5666
"ChatGLMForConditionalGeneration": BLOOM_SMOOTHQUANT_MAPPINGS,
67+
"Phi3VForCausalLM": PHI3_VISION_SMOOTHQUANT_MAPPINGS,
5768
}
5869

5970

0 commit comments

Comments
 (0)