Update README.md
Browse files
README.md
CHANGED
@@ -1,4 +1,35 @@
|
|
1 |
---
|
2 |
base_model:
|
3 |
- openbmb/MiniCPM-V-2_6
|
4 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
base_model:
|
3 |
- openbmb/MiniCPM-V-2_6
|
4 |
+
---
|
5 |
+
|
6 |
+
## Creation
|
7 |
+
|
8 |
+
```python
|
9 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
10 |
+
|
11 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
12 |
+
from llmcompressor.transformers import oneshot, wrap_hf_model_class
|
13 |
+
|
14 |
+
MODEL_ID = "openbmb/MiniCPM-V-2_6"
|
15 |
+
|
16 |
+
# Load model.
|
17 |
+
model_class = wrap_hf_model_class(AutoModelForCausalLM)
|
18 |
+
model = model_class.from_pretrained(MODEL_ID, torch_dtype="auto", trust_remote_code=True).to("cuda")
|
19 |
+
processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
|
20 |
+
|
21 |
+
# Configure the quantization algorithm and scheme.
|
22 |
+
# In this case, we:
|
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:resampler.*", "re:vpm.*"],
|
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, trust_remote_code_model=True)
|
34 |
+
processor.save_pretrained(SAVE_DIR)
|
35 |
+
```
|