mgoin commited on
Commit
2333598
1 Parent(s): 1fefd7b

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +38 -0
README.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Creation
3
+
4
+ ```python
5
+ from transformers import AutoProcessor, AutoModelForCausalLM
6
+
7
+ from llmcompressor.modifiers.quantization import QuantizationModifier
8
+ from llmcompressor.transformers import oneshot, wrap_hf_model_class
9
+
10
+ MODEL_ID = "microsoft/Phi-3.5-vision-instruct"
11
+
12
+ # Load model.
13
+ model_class = wrap_hf_model_class(AutoModelForCausalLM)
14
+ model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto", trust_remote_code=True, _attn_implementation="eager")
15
+ processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
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",
23
+ scheme="FP8_DYNAMIC",
24
+ ignore=["re:.*lm_head", "re:model.vision_embed_tokens.*"],
25
+ )
26
+
27
+ # Apply quantization and save to disk in compressed-tensors format.
28
+ SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
29
+ oneshot(model=model, recipe=recipe, output_dir=SAVE_DIR)
30
+ processor.save_pretrained(SAVE_DIR)
31
+
32
+ # Confirm generations of the quantized model look sane.
33
+ print("========== SAMPLE GENERATION ==============")
34
+ input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
35
+ output = model.generate(input_ids, max_new_tokens=20)
36
+ print(processor.decode(output[0]))
37
+ print("==========================================")
38
+ ```