Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5# 1. Load the base model and tokenizer
6model_id = "LGAI-EXAONE/EXAONE-3.5-7.8B-Instruct"
7adapter_id = "radishtiger/EXAONE-3.5-7.8B-Instruct_convfinqa_lora_r64_DR1.0"
8
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10model = AutoModelForCausalLM.from_pretrained(
11 model_id,
12 torch_dtype=torch.bfloat16,
13 device_map="auto",
14 trust_remote_code=True
15)
16
17# 2. Load the LoRA adapter
18model = PeftModel.from_pretrained(model, adapter_id)
19
20# 3. Prepare an example input (Financial question for ConvFinQA)
21messages = [
22 {"role": "user", "content": "In the consolidated balance sheet, what was the total current assets for the year ended December 31, 2022?"}
23]
24input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
25inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
26
27# 4. Generate response
28outputs = model.generate(**inputs, max_new_tokens=128)
29print(tokenizer.decode(outputs[0], skip_special_tokens=True))1@software{vonwerra2020trl,
2 title = {{TRL: Transformers Reinforcement Learning}},
3 author = {von Werra, Leandro and Belkada, Younes and Tunstall, Lewis and Beeching, Edward and Thrush, Tristan and Lambert, Nathan and Huang, Shengyi and Rasul, Kashif and Gallouédec, Quentin},
4 license = {Apache-2.0},
5 url = {https://github.com/huggingface/trl},
6 year = {2020}
7}