Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# Load base model
6base_model = AutoModelForCausalLM.from_pretrained(
7 "meta-llama/Llama-3.1-8B",
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11
12# Load LoRA adapter
13model = PeftModel.from_pretrained(base_model, "anonymousML123/llama3-8b-pku-DPO-NoInstruct-SFT-NoInstruct")
14
15# Load tokenizer
16tokenizer = AutoTokenizer.from_pretrained("anonymousML123/llama3-8b-pku-DPO-NoInstruct-SFT-NoInstruct")
17
18# Generate
19messages = [{"role": "user", "content": "Explain quantum computing"}]
20input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to("cuda")
21
22with torch.no_grad():
23 outputs = model.generate(input_ids, max_new_tokens=128, temperature=0.7)
24
25print(tokenizer.decode(outputs[0], skip_special_tokens=True))1@misc{llama3_8b_pku_DPO_NoInstruct_SFT_NoInstruct_2024,
2 author = {User},
3 title = {llama3-8b-pku-DPO-NoInstruct-SFT-NoInstruct},
4 year = {2024},
5 publisher = {HuggingFace},
6 howpublished = {\url{https://huggingface.co/anonymousML123/llama3-8b-pku-DPO-NoInstruct-SFT-NoInstruct}}
7}