Update README.md
Browse files
README.md
CHANGED
@@ -1,16 +1,20 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
```python
|
4 |
-
from transformers import AutoProcessor
|
5 |
|
6 |
from llmcompressor.modifiers.quantization import QuantizationModifier
|
7 |
-
from llmcompressor.transformers import oneshot
|
8 |
-
from llmcompressor.transformers.sparsification import create_sparse_auto_model_class
|
9 |
|
10 |
MODEL_ID = "Qwen/Qwen2-VL-7B-Instruct"
|
11 |
|
12 |
# Load model.
|
13 |
-
model_class =
|
14 |
model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
|
15 |
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
16 |
|
@@ -19,11 +23,15 @@ processor = AutoProcessor.from_pretrained(MODEL_ID)
|
|
19 |
# * quantize the weights to fp8 with per channel via ptq
|
20 |
# * quantize the activations to fp8 with dynamic per token
|
21 |
recipe = QuantizationModifier(
|
22 |
-
targets="Linear",
|
|
|
|
|
23 |
)
|
24 |
|
25 |
-
# Apply quantization.
|
26 |
-
|
|
|
|
|
27 |
|
28 |
# Confirm generations of the quantized model look sane.
|
29 |
print("========== SAMPLE GENERATION ==============")
|
@@ -31,9 +39,4 @@ input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to
|
|
31 |
output = model.generate(input_ids, max_new_tokens=20)
|
32 |
print(processor.decode(output[0]))
|
33 |
print("==========================================")
|
34 |
-
|
35 |
-
# Save to disk in compressed-tensors format.
|
36 |
-
SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
|
37 |
-
model.save_pretrained(SAVE_DIR)
|
38 |
-
processor.save_pretrained(SAVE_DIR)
|
39 |
```
|
|
|
1 |
+
---
|
2 |
+
base_model:
|
3 |
+
- Qwen/Qwen2-VL-7B-Instruct
|
4 |
+
---
|
5 |
+
|
6 |
+
## Creation
|
7 |
|
8 |
```python
|
9 |
+
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
|
10 |
|
11 |
from llmcompressor.modifiers.quantization import QuantizationModifier
|
12 |
+
from llmcompressor.transformers import oneshot, wrap_hf_model_class
|
|
|
13 |
|
14 |
MODEL_ID = "Qwen/Qwen2-VL-7B-Instruct"
|
15 |
|
16 |
# Load model.
|
17 |
+
model_class = wrap_hf_model_class(Qwen2VLForConditionalGeneration)
|
18 |
model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
|
19 |
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
20 |
|
|
|
23 |
# * quantize the weights to fp8 with per channel via ptq
|
24 |
# * quantize the activations to fp8 with dynamic per token
|
25 |
recipe = QuantizationModifier(
|
26 |
+
targets="Linear",
|
27 |
+
scheme="FP8_DYNAMIC",
|
28 |
+
ignore=["re:.*lm_head", "re:visual.*"],
|
29 |
)
|
30 |
|
31 |
+
# Apply quantization and save to disk in compressed-tensors format.
|
32 |
+
SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-dynamic"
|
33 |
+
oneshot(model=model, recipe=recipe, output_dir=SAVE_DIR)
|
34 |
+
processor.save_pretrained(SAVE_DIR)
|
35 |
|
36 |
# Confirm generations of the quantized model look sane.
|
37 |
print("========== SAMPLE GENERATION ==============")
|
|
|
39 |
output = model.generate(input_ids, max_new_tokens=20)
|
40 |
print(processor.decode(output[0]))
|
41 |
print("==========================================")
|
|
|
|
|
|
|
|
|
|
|
42 |
```
|