Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
## Evaluation
|
3 |
+
|
4 |
+
```
|
5 |
+
TBD
|
6 |
+
```
|
7 |
+
|
8 |
+
## Creation
|
9 |
+
https://github.com/vllm-project/llm-compressor/pull/185
|
10 |
+
|
11 |
+
```python
|
12 |
+
from transformers import AutoProcessor
|
13 |
+
|
14 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
15 |
+
from llmcompressor.transformers import oneshot
|
16 |
+
from llmcompressor.transformers.sparsification import create_sparse_auto_model_class
|
17 |
+
|
18 |
+
MODEL_ID = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
19 |
+
|
20 |
+
# Load model.
|
21 |
+
model_class = create_sparse_auto_model_class("MllamaForConditionalGeneration")
|
22 |
+
model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
|
23 |
+
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
24 |
+
|
25 |
+
# Configure the quantization algorithm and scheme.
|
26 |
+
# In this case, we:
|
27 |
+
# * quantize the weights to fp8 with per channel via ptq
|
28 |
+
# * quantize the activations to fp8 with dynamic per token
|
29 |
+
recipe = QuantizationModifier(
|
30 |
+
targets="Linear",
|
31 |
+
scheme="FP8_DYNAMIC",
|
32 |
+
ignore=["re:.*lm_head", "re:multi_modal_projector.*", "re:vision_model.*"],
|
33 |
+
)
|
34 |
+
|
35 |
+
# Apply quantization and save to disk in compressed-tensors format.
|
36 |
+
SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
|
37 |
+
oneshot(model=model, recipe=recipe, output_dir=SAVE_DIR)
|
38 |
+
|
39 |
+
# Confirm generations of the quantized model look sane.
|
40 |
+
print("========== SAMPLE GENERATION ==============")
|
41 |
+
input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
|
42 |
+
output = model.generate(input_ids, max_new_tokens=20)
|
43 |
+
print(processor.decode(output[0]))
|
44 |
+
print("==========================================")
|
45 |
+
```
|