Views
No views yet
1
2from peft import AutoPeftModelForCausalLM
3from transformers import GenerationConfig
4from transformers import AutoTokenizer
5import torch
6
7
8dialogue = """
9Alex: Hey, are you free this weekend?
10Sarah: Yeah, what's up?
11Alex: Want to go to that new restaurant downtown?
12Sarah: The Italian one? I heard it's really good!
13Alex: That's the one. How about Saturday around 7?
14Sarah: Perfect! Should I make a reservation?
15Alex: Good idea, I'll call them now.
16"""
17
18test_prompt = f"""
19###Human: Summarize this following dialogue: {dialogue}
20###Assistant: """
21
22tokenizer = AutoTokenizer.from_pretrained("Wothmag07/mistral-finetuned-samsum")
23model = AutoPeftModelForCausalLM.from_pretrained("Wothmag07/mistral-finetuned-samsum",
24 low_cpu_mem_usage=True,
25 return_dict=True,
26 torch_dtype=torch.bfloat16,
27 device_map="cuda")
28
29inputs = tokenizer(test_prompt, return_tensors="pt").to("cuda")
30output = model.generate(**inputs, do_sample=True, top_p=0.9, temperature=0.8, max_new_tokens=150)
31tokenizer.decode(output[0], skip_special_tokens=True)1@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}