mgoin commited on
Commit
c6cc8f2
1 Parent(s): 5458c45

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -8
README.md CHANGED
@@ -8,22 +8,30 @@ from llmcompressor.transformers import oneshot
8
  from llmcompressor.transformers.sparsification import create_sparse_auto_model_class
9
 
10
  MODEL_ID = "llava-hf/llava-1.5-7b-hf"
 
 
11
  model_class = create_sparse_auto_model_class("LlavaForConditionalGeneration")
12
  model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
13
  processor = AutoProcessor.from_pretrained(MODEL_ID)
14
 
15
- recipe = QuantizationModifier(targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"])
16
- oneshot(model=model, recipe=recipe)
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  # Confirm generations of the quantized model look sane.
19
  print("========== SAMPLE GENERATION ==============")
20
- input_ids = processor("Hello my name is", return_tensors="pt").input_ids.to("cuda")
21
  output = model.generate(input_ids, max_new_tokens=20)
22
  print(processor.decode(output[0]))
23
  print("==========================================")
24
-
25
- # Save to disk in compressed-tensors format.
26
- SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
27
- model.save_pretrained(SAVE_DIR)
28
- processor.save_pretrained(SAVE_DIR)
29
  ```
 
8
  from llmcompressor.transformers.sparsification import create_sparse_auto_model_class
9
 
10
  MODEL_ID = "llava-hf/llava-1.5-7b-hf"
11
+
12
+ # Load model.
13
  model_class = create_sparse_auto_model_class("LlavaForConditionalGeneration")
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",
23
+ scheme="FP8_DYNAMIC",
24
+ ignore=["re:.*lm_head", "re:multi_modal_projector.*", "re:vision_tower.*"],
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
 
31
  # Confirm generations of the quantized model look sane.
32
  print("========== SAMPLE GENERATION ==============")
33
+ input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
34
  output = model.generate(input_ids, max_new_tokens=20)
35
  print(processor.decode(output[0]))
36
  print("==========================================")
 
 
 
 
 
37
  ```