Spaces:
Paused
Paused
Commit
·
376d41a
1
Parent(s):
726371d
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
import transformers as t
|
3 |
import torch
|
|
|
4 |
|
5 |
# Load your fine-tuned model and tokenizer
|
6 |
-
model = t.AutoModelForCausalLM.from_pretrained("./weights")
|
7 |
tokenizer = t.AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-hf")
|
|
|
8 |
tokenizer.pad_token_id = 0
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
# Define a prediction function
|
11 |
def generate_article(title):
|
12 |
prompt = f"Below is a title for an article. Write an article that appropriately suits the title: \n\n### Title:\n{title}\n\n### Article:\n"
|
|
|
1 |
import gradio as gr
|
2 |
import transformers as t
|
3 |
import torch
|
4 |
+
import peft
|
5 |
|
6 |
# Load your fine-tuned model and tokenizer
|
|
|
7 |
tokenizer = t.AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-hf")
|
8 |
+
model = t.AutoModelForCausalLM.from_pretrained("NousResearch/Llama-2-7b-hf", load_in_8bit=True, torch_dtype=torch.float16)
|
9 |
tokenizer.pad_token_id = 0
|
10 |
|
11 |
+
config = peft.LoraConfig(r=8, lora_alpha=16, target_modules=["q_proj", "v_proj"], lora_dropout=0.005, bias="none", task_type="CAUSAL_LM")
|
12 |
+
model = peft.get_peft_model(model, config)
|
13 |
+
|
14 |
+
peft.set_peft_model_state_dict(model, torch.load(f"./output/checkpoint-{checkpoint}/adapter_model.bin"))
|
15 |
+
|
16 |
# Define a prediction function
|
17 |
def generate_article(title):
|
18 |
prompt = f"Below is a title for an article. Write an article that appropriately suits the title: \n\n### Title:\n{title}\n\n### Article:\n"
|