Skip to content

Switch backend to use llm-compressor - #33

Open
mgoin wants to merge 9 commits into
mainfrom
use-llm-compressor
Open

Switch backend to use llm-compressor#33
mgoin wants to merge 9 commits into
mainfrom
use-llm-compressor

Conversation

@mgoin

@mgoin mgoin commented Jul 18, 2024

Copy link
Copy Markdown
Member

Currently only works for static quantization.

from datasets import load_dataset
from transformers import AutoTokenizer

from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig

pretrained_model_dir = "facebook/opt-125m"
quantized_model_dir = "opt-125m-FP8"

tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True)
tokenizer.pad_token = tokenizer.eos_token

ds = load_dataset("mgoin/ultrachat_2k", split="train_sft").select(range(512))
def preprocess(example):
    example = tokenizer.apply_chat_template(example["messages"], tokenize=False)
    return tokenizer(example, max_length=2048, truncation=True, add_special_tokens=False)
ds = ds.map(preprocess, remove_columns=ds.column_names)

quantize_config = BaseQuantizeConfig(quant_method="fp8", activation_scheme="static")

model = AutoFP8ForCausalLM.from_pretrained(pretrained_model_dir, quantize_config)
model.quantize(ds)
model.save_quantized(quantized_model_dir)

@mgoin
mgoin changed the base branch from support-kv-cache-scales to main July 18, 2024 21:05
@mgoin
mgoin force-pushed the use-llm-compressor branch 2 times, most recently from c15e352 to b428604 Compare July 18, 2024 21:10
@mgoin
mgoin force-pushed the use-llm-compressor branch from b428604 to e286fa9 Compare July 18, 2024 21:11
@kylesayrs

Copy link
Copy Markdown

Relevant: vllm-project/llm-compressor#1971

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants