-
Notifications
You must be signed in to change notification settings - Fork 625
[lut-b] data-free round-to-nearest example #3018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from compressed_tensors.offload import dispatch_model | ||
| from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
|
||
| from llmcompressor import oneshot | ||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||
|
|
||
| MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct" | ||
|
|
||
| # Load model. | ||
| model = AutoModelForCausalLM.from_pretrained(MODEL_ID) | ||
| tokenizer = AutoTokenizer.from_pretrained(MODEL_ID) | ||
|
|
||
| # Configure the quantization algorithm and scheme. | ||
| # In this case, we: | ||
| # * quantize only the mlp layer weights | ||
| recipe = QuantizationModifier( | ||
| targets="re:.*layers.*mlp.*_proj$", scheme="LUTB", ignore=["lm_head"] | ||
| ) | ||
|
|
||
| # Apply quantization. | ||
| oneshot(model=model, recipe=recipe) | ||
|
|
||
| print("\n\n") | ||
| print("========== SAMPLE GENERATION ==============") | ||
| dispatch_model(model) | ||
| input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to( | ||
| model.device | ||
| ) | ||
| output = model.generate(input_ids, max_new_tokens=100) | ||
| print(tokenizer.decode(output[0])) | ||
| print("==========================================\n\n") | ||
|
|
||
|
|
||
| # Save to disk in compressed-tensors format. | ||
| SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-LUTB" | ||
| model.save_pretrained(SAVE_DIR, save_compressed=True) | ||
| tokenizer.save_pretrained(SAVE_DIR) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -77,7 +77,7 @@ def initialize_observer( | |||||
| log_once=True, | ||||||
| ) | ||||||
|
|
||||||
| if args is not None and args.dynamic is not True: | ||||||
| if args is not None and args.dynamic is not True and observer is not None: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check Additionally, note that if
Suggested change
|
||||||
| observer = Observer.load_from_registry(observer, base_name=base_name, args=args) | ||||||
| module.register_module(f"{base_name}_observer", observer) | ||||||
| observer.attach(module) | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.