Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- w4a16
|
4 |
+
- int4
|
5 |
+
- vllm
|
6 |
+
- vision
|
7 |
+
license: apache-2.0
|
8 |
+
license_link: https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md
|
9 |
+
language:
|
10 |
+
- en
|
11 |
+
base_model: meta-llama/Llama-3.2-11B-Vision-Instruct
|
12 |
+
library_name: transformers
|
13 |
+
---
|
14 |
+
|
15 |
+
#
|
16 |
+
Llama-3.2-11B-Vision-Instruct-quantized.w4a16
|
17 |
+
|
18 |
+
## Model Overview
|
19 |
+
- **Model Architecture:** Llama-3.2-11B-Vision-Instruct
|
20 |
+
- **Input:** Vision-Text
|
21 |
+
- **Output:** Text
|
22 |
+
- **Model Optimizations:**
|
23 |
+
- **Weight quantization:** INT4
|
24 |
+
- **Activation quantization:** FP16
|
25 |
+
- **Release Date:** 1/31/2025
|
26 |
+
- **Version:** 1.0
|
27 |
+
- **Model Developers:** Neural Magic
|
28 |
+
|
29 |
+
Quantized version of [meta-llama/Llama-3.2-11B-Vision-Instruct](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct).
|
30 |
+
|
31 |
+
### Model Optimizations
|
32 |
+
|
33 |
+
This model was obtained by quantizing the weights of [meta-llama/Llama-3.2-11B-Vision-Instruct](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct) to INT4 data type, ready for inference with vLLM >= 0.5.2.
|
34 |
+
|
35 |
+
## Deployment
|
36 |
+
|
37 |
+
### Use with vLLM
|
38 |
+
|
39 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
40 |
+
|
41 |
+
```python
|
42 |
+
from transformers import AutoProcessor
|
43 |
+
from vllm.assets.image import ImageAsset
|
44 |
+
from vllm import LLM, SamplingParams
|
45 |
+
|
46 |
+
# prepare model
|
47 |
+
model_id = "neuralmagic/Llama-3.2-11B-Vision-Instruct-W4A16-G128"
|
48 |
+
llm = LLM(
|
49 |
+
model=model_id,
|
50 |
+
max_model_len=4096,
|
51 |
+
max_num_seqs=16,
|
52 |
+
limit_mm_per_prompt={"image": 1},
|
53 |
+
)
|
54 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
55 |
+
|
56 |
+
|
57 |
+
# prepare inputs
|
58 |
+
question = "What is the content of this image?"
|
59 |
+
messages = [
|
60 |
+
{
|
61 |
+
"role": "user",
|
62 |
+
"content": [
|
63 |
+
{"type": "image"},
|
64 |
+
{"type": "text", "text": f"{question}"},
|
65 |
+
],
|
66 |
+
},
|
67 |
+
]
|
68 |
+
prompt = processor.apply_chat_template(
|
69 |
+
messages, add_generation_prompt=True,tokenize=False
|
70 |
+
)
|
71 |
+
image = ImageAsset("cherry_blossom").pil_image.convert("RGB")
|
72 |
+
inputs = {
|
73 |
+
"prompt": prompt,
|
74 |
+
"multi_modal_data": {
|
75 |
+
"image": image
|
76 |
+
},
|
77 |
+
}
|
78 |
+
|
79 |
+
# generate response
|
80 |
+
print("========== SAMPLE GENERATION ==============")
|
81 |
+
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
|
82 |
+
print(f"PROMPT : {outputs[0].prompt}")
|
83 |
+
print(f"RESPONSE: {outputs[0].outputs[0].text}")
|
84 |
+
print("==========================================")
|
85 |
+
```
|
86 |
+
|
87 |
+
vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
88 |
+
|
89 |
+
## Creation
|
90 |
+
|
91 |
+
This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below as part a multimodal announcement blog.
|
92 |
+
|
93 |
+
```python
|
94 |
+
import requests
|
95 |
+
import torch
|
96 |
+
from PIL import Image
|
97 |
+
from transformers import AutoProcessor
|
98 |
+
|
99 |
+
from llmcompressor.modifiers.quantization import GPTQModifier
|
100 |
+
from llmcompressor.transformers import oneshot
|
101 |
+
from llmcompressor.transformers.tracing import TraceableMllamaForConditionalGeneration
|
102 |
+
|
103 |
+
# Load model.
|
104 |
+
model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
105 |
+
model = TraceableMllamaForConditionalGeneration.from_pretrained(
|
106 |
+
model_id, device_map="auto", torch_dtype="auto"
|
107 |
+
)
|
108 |
+
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
109 |
+
|
110 |
+
# Oneshot arguments
|
111 |
+
DATASET_ID = "flickr30k"
|
112 |
+
DATASET_SPLIT = {"calibration": "test[:512]"}
|
113 |
+
NUM_CALIBRATION_SAMPLES = 512
|
114 |
+
MAX_SEQUENCE_LENGTH = 2048
|
115 |
+
|
116 |
+
|
117 |
+
# Define a oneshot data collator for multimodal inputs.
|
118 |
+
def data_collator(batch):
|
119 |
+
assert len(batch) == 1
|
120 |
+
return {key: torch.tensor(value) for key, value in batch[0].items()}
|
121 |
+
|
122 |
+
|
123 |
+
# Recipe
|
124 |
+
recipe = [
|
125 |
+
GPTQModifier(
|
126 |
+
targets="Linear",
|
127 |
+
scheme="W4A16",
|
128 |
+
ignore=["re:.*lm_head", "re:multi_modal_projector.*", "re:vision_model.*"],
|
129 |
+
),
|
130 |
+
]
|
131 |
+
|
132 |
+
# Perform oneshot
|
133 |
+
oneshot(
|
134 |
+
model=model,
|
135 |
+
tokenizer=model_id,
|
136 |
+
dataset=DATASET_ID,
|
137 |
+
splits=DATASET_SPLIT,
|
138 |
+
recipe=recipe,
|
139 |
+
max_seq_length=MAX_SEQUENCE_LENGTH,
|
140 |
+
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
|
141 |
+
trust_remote_code_model=True,
|
142 |
+
data_collator=data_collator,
|
143 |
+
)
|
144 |
+
```
|
145 |
+
|
146 |
+
## License
|
147 |
+
|
148 |
+
License: Use of Llama 3.2 is governed by the [Llama 3.2 Community License](https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/LICENSE) (a custom, commercial license agreement).
|