mgoin commited on
Commit
301c3d8
·
verified ·
1 Parent(s): 322edef

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -0
README.md ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ https://github.com/vllm-project/llm-compressor/pull/185
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 = create_sparse_auto_model_class("Qwen2VLForConditionalGeneration")
14
+ model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
15
+ processor = AutoProcessor.from_pretrained(MODEL_ID)
16
+
17
+ # Configure the quantization algorithm and scheme.
18
+ # In this case, we:
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", scheme="FP8_DYNAMIC", ignore=["lm_head"]
23
+ )
24
+
25
+ # Apply quantization.
26
+ oneshot(model=model, recipe=recipe)
27
+
28
+ # Confirm generations of the quantized model look sane.
29
+ print("========== SAMPLE GENERATION ==============")
30
+ input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
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
+ ```