knkarthick/dialogsum
Viewer • Updated • 14.5k • 10.1k • 241
How to use shenoy/DialogSumLlama2_qlora with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("TinyPixel/Llama-2-7B-bf16-sharded")
model = PeftModel.from_pretrained(base_model, "shenoy/DialogSumLlama2_qlora")LLama-2 7B is finetuned using SFT to generate summaries from conversations.
from transformers import AutoTokenizer, AutoModelForCausalLM
import transformers
from peft import PeftModel
# Quantization config
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype="float16",
)
model_name = "TinyPixel/Llama-2-7B-bf16-sharded"
# loading the model with quantization config
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=bnb_config,
trust_remote_code=True,
device_map='auto'
)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True , return_token_type_ids=False)
tokenizer.pad_token = tokenizer.eos_token
model = PeftModel.from_pretrained(model,"shenoy/DialogSumLlama2_qlora", device_map="auto")
text = """### Instruction:
Write a concise summary of the below input text.Return your response in bullet points which covers the key points of the text.
### Input:
#Person1#: Ms. Dawson, I need you to take a dictation for me.
#Person2#: Yes, sir...
#Person1#: This should go out as an intra-office memorandum to all employees by this afternoon. Are you ready?
#Person2#: Yes, sir. Go ahead.
#Person1#: Attention all staff... Effective immediately, all office communications are restricted to email correspondence and official memos. The use of Instant Message programs by employees during working hours is strictly prohibited.
#Person2#: Sir, does this apply to intra-office communications only? Or will it also restrict external communications?
#Person1#: It should apply to all communications, not only in this office between employees, but also any outside communications.
#Person2#: But sir, many employees use Instant Messaging to communicate with their clients.
#Person1#: They will just have to change their communication methods. I don't want any - one using Instant Messaging in this office. It wastes too much time! Now, please continue with the memo. Where were we?
#Person2#: This applies to internal and external communications.
#Person1#: Yes. Any employee who persists in using Instant Messaging will first receive a warning and be placed on probation. At second offense, the employee will face termination. Any questions regarding this new policy may be directed to department heads.
#Person2#: Is that all?
#Person1#: Yes. Please get this memo typed up and distributed to all employees before 4 pm.
### Response :"""
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'], max_new_tokens=100 ,repetition_penalty=1.2)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Training Configuration:
per_device_train_batch_size: 4gradient_accumulation_steps: 4optim: "paged_adamw_8bit"learning_rate: 2e-4lr_scheduler_type: "linear"save_strategy: "epoch"logging_steps: 10num_train_epochs: 2max_steps: 50fp16: TrueLORA Configuration:
lora_alpha: 16lora_dropout: 0.05target_modules: ["q_proj", "v_proj"]r: 8bias: "none"task_type: "CAUSAL_LM"The following bitsandbytes quantization config was used during training:
accelerate 0.21.0peft 0.4.0bitsandbytes 0.40.2transformers 4.30.2trl 0.4.7