Skip to content
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

How to speedup the process of quantization which takes almost 20 hours to quantize llama3-70B with w8a8 #968

Open
moonlightian opened this issue Dec 11, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@moonlightian
Copy link

llmcompressor==0.2.0
compressed-tensors==0.7.1
4 NVIDIA A100 80GB PCIe

from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL_ID = "/llama3_1_70B"
model = SparseAutoModelForCausalLM.from_pretrained(
MODEL_ID, device_map="auto", torch_dtype="auto",
)
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
NUM_CALIBRATION_SAMPLES = 512
MAX_SEQUENCE_LENGTH = 2048
ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))

def preprocess(example):
    return {"text": tokenizer.apply_chat_template(example["text"], tokenize=False)}
ds = ds.map(preprocess)

def tokenize(sample):
    return tokenizer("\n\n".join(sample['text']), return_tensors='pt')
ds = ds.map(tokenize, remove_columns=ds.column_names)

from llmcompressor.transformers import oneshot
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor.modifiers.smoothquant import SmoothQuantModifier

# Configure the quantization algorithms
recipe = [
    SmoothQuantModifier(smoothing_strength=0.8),
    GPTQModifier(targets="Linear", dampening_frac=0.1, scheme="W8A8", ignore=["lm_head"]),
]

# Apply quantization
oneshot(
    model=model,
    dataset=ds,
    recipe=recipe,
    max_seq_length=MAX_SEQUENCE_LENGTH,
    num_calibration_samples=NUM_CALIBRATION_SAMPLES,
)
@moonlightian moonlightian added the enhancement New feature or request label Dec 11, 2024
@dsikka dsikka self-assigned this Dec 12, 2024
@dsikka
Copy link
Collaborator

dsikka commented Dec 14, 2024

Hi @moonlightian:

  1. Can you confirm you ran the above with 4 x A100s?
  2. Can you also confirm the stub of the model that was used and the dataset name? I had some trouble processing the dataset listed with the preprocess functions provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants