mgoin commited on
Commit
674147c
1 Parent(s): d08eaf8

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -0
README.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - llava-hf/llava-onevision-qwen2-7b-ov-hf
4
+ ---
5
+
6
+ ## Creation
7
+
8
+ ```python
9
+ from transformers import AutoProcessor, LlavaOnevisionForConditionalGeneration
10
+
11
+ from llmcompressor.modifiers.quantization import QuantizationModifier
12
+ from llmcompressor.transformers import oneshot, wrap_hf_model_class
13
+
14
+ MODEL_ID = "llava-hf/llava-onevision-qwen2-7b-ov-hf"
15
+
16
+ # Load model.
17
+ model_class = wrap_hf_model_class(LlavaOnevisionForConditionalGeneration)
18
+ model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
19
+ processor = AutoProcessor.from_pretrained(MODEL_ID)
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:multi_modal_projector.*", "re:vision_tower.*"],
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)
34
+ processor.save_pretrained(SAVE_DIR)
35
+
36
+ # Confirm generations of the quantized model look sane.
37
+ print("========== SAMPLE GENERATION ==============")
38
+ input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
39
+ output = model.generate(input_ids, max_new_tokens=20)
40
+ print(processor.decode(output[0]))
41
+ print("==========================================")
42
+ ```