- app.py +18 -41
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
-
from
|
2 |
-
from
|
|
|
|
|
3 |
import torch
|
4 |
import time
|
5 |
-
import evaluate
|
6 |
import pandas as pd
|
7 |
import numpy as np
|
8 |
-
|
9 |
|
10 |
import streamlit as st
|
11 |
|
@@ -18,41 +19,17 @@ st.set_page_config(
|
|
18 |
login(token='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', add_to_git_credential=True)
|
19 |
|
20 |
st.title("Code Generation")
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
24 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
input = dataset['test'][index]['input']
|
32 |
-
instruction = dataset['test'][index]['instruction']
|
33 |
-
output = dataset['test'][index]['output']
|
34 |
-
|
35 |
-
prompt = f"""
|
36 |
-
Answer the following question.
|
37 |
-
|
38 |
-
{input} {instruction}
|
39 |
-
|
40 |
-
Answer:
|
41 |
-
"""
|
42 |
-
|
43 |
-
inputs = tokenizer(prompt, return_tensors='pt')
|
44 |
-
outputs = tokenizer.decode(
|
45 |
-
original_model.generate(
|
46 |
-
inputs["input_ids"],
|
47 |
-
max_new_tokens=200,
|
48 |
-
)[0],
|
49 |
-
skip_special_tokens=True
|
50 |
-
)
|
51 |
-
|
52 |
-
dash_line = '-'.join('' for x in range(100))
|
53 |
-
st.write(dash_line)
|
54 |
-
st.write(f'INPUT PROMPT:\n{prompt}')
|
55 |
-
st.write(dash_line)
|
56 |
-
st.write(f'BASELINE HUMAN SUMMARY:\n{output}\n')
|
57 |
-
st.write(dash_line)
|
58 |
-
st.write(f'MODEL GENERATION - ZERO SHOT:\n{outputs}')
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TrainingArguments, Trainer, pipeline
|
2 |
+
from peft import PeftModel, PeftConfig
|
3 |
+
from huggingface_hub import login
|
4 |
+
import bitsandbytes as bnb
|
5 |
import torch
|
6 |
import time
|
|
|
7 |
import pandas as pd
|
8 |
import numpy as np
|
9 |
+
|
10 |
|
11 |
import streamlit as st
|
12 |
|
|
|
19 |
login(token='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', add_to_git_credential=True)
|
20 |
|
21 |
st.title("Code Generation")
|
22 |
+
st.write('MODEL: TinyPixel/Llama-2-7B-bf16-sharded')
|
23 |
+
bnb_config = BitsAndBytesConfig(
|
24 |
+
load_in_4bit=True,
|
25 |
+
bnb_4bit_use_double_quant=True,
|
26 |
+
bnb_4bit_quant_type="nf4",
|
27 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
28 |
+
)
|
29 |
+
model_name='TinyPixel/Llama-2-7B-bf16-sharded'
|
30 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
31 |
+
peft_model_base = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=bnb_config)
|
32 |
+
peft_model = PeftModel.from_pretrained(peft_model_base,
|
33 |
+
'red1xe/Llama-2-7B-codeGPT',
|
34 |
+
torch_dtype=torch.bfloat16,
|
35 |
+
is_trainable=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -5,4 +5,5 @@ datasets==2.11.0
|
|
5 |
evaluate==0.4.0
|
6 |
rouge_score==0.1.2
|
7 |
loralib==0.1.1
|
8 |
-
peft==0.3.0
|
|
|
|
5 |
evaluate==0.4.0
|
6 |
rouge_score==0.1.2
|
7 |
loralib==0.1.1
|
8 |
+
peft==0.3.0
|
9 |
+
bitsandbytes>=0.41.1
|