-
Notifications
You must be signed in to change notification settings - Fork 195
Add FP8 Support #4
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
Changes from 1 commit
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,38 @@ | ||
import torch | ||
from datasets import load_dataset | ||
from transformers import AutoTokenizer | ||
|
||
from llmcompressor.modifiers.quantization import GPTQModifier | ||
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot | ||
|
||
model_stub = "meta-llama/Meta-Llama-3-8B-Instruct" | ||
output_dir = "Meta-Llama-3-8B-Instruct-FP8-Compressed" | ||
num_calibration_samples = 512 | ||
|
||
tokenizer = AutoTokenizer.from_pretrained(model_stub, use_fast=True) | ||
tokenizer.pad_token = tokenizer.eos_token | ||
|
||
|
||
def preprocess(batch): | ||
text = tokenizer.apply_chat_template(batch["messages"], tokenize=False) | ||
tokenized = tokenizer(text, padding=True, truncation=True, max_length=2048) | ||
return tokenized | ||
|
||
|
||
ds = load_dataset("mgoin/ultrachat_2k", split="train_sft") | ||
examples = ds.map(preprocess, remove_columns=ds.column_names) | ||
|
||
recipe = GPTQModifier(targets=["Linear"], scheme="FP8", ignore=["lm_head"]) | ||
|
||
model = SparseAutoModelForCausalLM.from_pretrained( | ||
model_stub, torch_dtype=torch.bfloat16, device_map="auto" | ||
) | ||
|
||
oneshot( | ||
model=model, | ||
dataset=examples, | ||
recipe=recipe, | ||
output_dir=output_dir, | ||
num_calibration_samples=num_calibration_samples, | ||
save_compressed=True, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cadence: "nightly" | ||
test_type: "regression" | ||
model_stub: "TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T" | ||
new_recipe: "tests/llmcompressor/transformers/compression/recipes/new_quant_fp8.yaml" | ||
ppl_threshold: 20 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cadence: "commit" | ||
test_type: "regression" | ||
model_stub: "Xenova/llama2.c-stories15M" | ||
new_recipe: "tests/llmcompressor/transformers/compression/recipes/new_quant_fp8.yaml" | ||
ppl_threshold: 5000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
quant_stage: | ||
quant_modifiers: | ||
GPTQModifier: | ||
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. nice that gptq works out of the box but note that we shouldnt need this for fp8 so in our examples its should just be quantization modifier perhaps we should have a test that matches the expected user flow for fp8 as well? 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. Can do as follow up 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. Gotcha, I just updated the PR with this change (both in the example and the integration test). However the nice scheme/target UX is only for GPTQModifier so it made the example a bit messier. I'll move the scheme parsing to QM in a follow up PR |
||
sequential_update: false | ||
ignore: ["lm_head"] | ||
config_groups: | ||
group_0: | ||
weights: | ||
num_bits: 8 | ||
type: "float" | ||
symmetric: true | ||
strategy: channel | ||
input_activations: | ||
num_bits: 8 | ||
type: "float" | ||
symmetric: true | ||
dynamic: true | ||
strategy: token | ||
targets: ["Linear"] |
Uh oh!
There was an error while loading. Please reload this page.