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

FIX: Add safe guards for static cache + llama on transformers latest #401

Merged
merged 2 commits into from
Apr 6, 2024

Conversation

younesbelkada
Copy link
Collaborator

Fixes: huggingface/transformers#28470

This PR makes autoawq + transformers compatible with recent changes on Llama architecture. In transformers llama the causal mask is pre-allocated with the size bsz, 1, max_seq_len, max_seq_len, thus needing to slice the attention mask here in the fused attention module.

Also fixes an issue where running this script fails:

Script to repro:

from transformers import AutoModelForCausalLM, AwqConfig, AutoTokenizer

awq_config = AwqConfig(do_fuse=True, fuse_max_seq_len=512)
model = AutoModelForCausalLM.from_pretrained(
    "casperhansen/tinyllama-1b-awq",
    quantization_config=awq_config,
).to("cuda")

tokenizer = AutoTokenizer.from_pretrained("casperhansen/tinyllama-1b-awq")
input_ids = tokenizer("Hello, my dog is cute", return_tensors="pt").input_ids.to("cuda")

model.forward(input_ids, use_cache=False)
model.generate(input_ids, max_new_tokens=100)

We defer to not using the caching logic if use_cache=False

cc @casper-hansen

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.

Running a forward pass before generate with AWQ fused modules breaks it
2 participants