File size: 3,271 Bytes
1ea70b6 37b6c13 299dcaf 37b6c13 c6cc8f2 37b6c13 299dcaf 37b6c13 c6cc8f2 37b6c13 c6cc8f2 37b6c13 299dcaf 37b6c13 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
## Evaluation
```
lm_eval --model vllm-vlm --model_args pretrained=llava-hf/llava-1.5-7b-hf --tasks mmmu_val
| Groups |Version|Filter|n-shot|Metric| |Value | |Stderr|
|--------------------------------|------:|------|------|------|---|-----:|---|-----:|
|mmmu_val | 0|none | |acc |↑ |0.2433|± |0.0141|
| - Art and Design | 0|none | |acc |↑ |0.2250|± |0.0384|
| - Business | 0|none | |acc |↑ |0.2600|± |0.0358|
| - Health and Medicine | 0|none | |acc |↑ |0.3067|± |0.0377|
| - Humanities and Social Science| 0|none | |acc |↑ |0.2667|± |0.0403|
| - Science | 0|none | |acc |↑ |0.1667|± |0.0308|
| - Tech and Engineering | 0|none | |acc |↑ |0.2381|± |0.0284|
lm_eval --model vllm-vlm --model_args pretrained=mgoin/llava-1.5-7b-hf-FP8-Dynamic --tasks mmmu_val
| Groups |Version|Filter|n-shot|Metric| |Value | |Stderr|
|--------------------------------|------:|------|------|------|---|-----:|---|-----:|
|mmmu_val | 0|none | |acc |↑ |0.2433|± |0.0141|
| - Art and Design | 0|none | |acc |↑ |0.2250|± |0.0384|
| - Business | 0|none | |acc |↑ |0.2600|± |0.0358|
| - Health and Medicine | 0|none | |acc |↑ |0.3067|± |0.0377|
| - Humanities and Social Science| 0|none | |acc |↑ |0.2667|± |0.0403|
| - Science | 0|none | |acc |↑ |0.1667|± |0.0308|
| - Tech and Engineering | 0|none | |acc |↑ |0.2381|± |0.0284|
```
## Creation
https://github.com/vllm-project/llm-compressor/pull/185
```python
from transformers import AutoProcessor
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.transformers import oneshot
from llmcompressor.transformers.sparsification import create_sparse_auto_model_class
MODEL_ID = "llava-hf/llava-1.5-7b-hf"
# Load model.
model_class = create_sparse_auto_model_class("LlavaForConditionalGeneration")
model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
processor = AutoProcessor.from_pretrained(MODEL_ID)
# Configure the quantization algorithm and scheme.
# In this case, we:
# * quantize the weights to fp8 with per channel via ptq
# * quantize the activations to fp8 with dynamic per token
recipe = QuantizationModifier(
targets="Linear",
scheme="FP8_DYNAMIC",
ignore=["re:.*lm_head", "re:multi_modal_projector.*", "re:vision_tower.*"],
)
# Apply quantization and save to disk in compressed-tensors format.
SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
oneshot(model=model, recipe=recipe, output_dir=SAVE_DIR)
# Confirm generations of the quantized model look sane.
print("========== SAMPLE GENERATION ==============")
input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
output = model.generate(input_ids, max_new_tokens=20)
print(processor.decode(output[0]))
print("==========================================")
``` |