Skip to content

Commit

Permalink
added eval code
Browse files Browse the repository at this point in the history
  • Loading branch information
bstadt committed Mar 28, 2023
1 parent 4e8e7e7 commit 6d98aef
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 1 deletion.
17 changes: 17 additions & 0 deletions configs/eval/generate_baseline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# model/tokenizer
model_name: "zpn/llama-7b"
tokenizer_name: "zpn/llama-7b"
lora: true
lora_path: "tloen/alpaca-lora-7b"



max_new_tokens: 512
temperature: 0.001
prompt: |
#this code prints a string reversed
my_string = "hello how are you"
print(len(my_string))
My code above does not work. Can you help me?
14 changes: 14 additions & 0 deletions configs/eval/generate_full.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# model/tokenizer
model_name: "nomic-ai/vicuna-full-multi-turn_epoch_0"
tokenizer_name: "zpn/llama-7b"
lora_path: "no-lora"

max_new_tokens: 512
temperature: 0.001
prompt: |
#this code prints a string reversed
my_string = "hello how are you"
print(len(my_string))
My code above does not work. Can you help me?
15 changes: 15 additions & 0 deletions configs/eval/generate_large_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# model/tokenizer
model_name: "zpn/llama-7b"
tokenizer_name: "zpn/llama-7b"
lora: true
lora_path: "nomic-ai/vicuna-lora-multi-turn_epoch_2"

max_new_tokens: 512
temperature: 0.001
prompt: |
#this code prints a string reversed
my_string = "hello how are you"
print(len(my_string))
My code above does not work. Can you help me?
15 changes: 15 additions & 0 deletions configs/eval/generate_large_3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# model/tokenizer
model_name: "zpn/llama-7b"
tokenizer_name: "zpn/llama-7b"
lora: true
lora_path: "nomic-ai/vicuna-lora-multi-turn_epoch_3"

max_new_tokens: 512
temperature: 0.001
prompt: |
#this code prints a string reversed
my_string = "hello how are you"
print(len(my_string))
My code above does not work. Can you help me?
22 changes: 22 additions & 0 deletions eval_figures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import glob
import pickle
import numpy as np
from matplotlib import pyplot as plt

plt.figure()
for fpath in glob.glob('./eval_data/*multi*.pkl'):
parts = fpath.split('__')
model_name = parts[1].replace('model-', '').replace('.pkl', '')
lora_name = parts[2].replace('lora-', '').replace('.pkl', '')
with open(fpath, 'rb') as f:
data = pickle.load(f)
perplexities = data['perplexities']
perplexities = np.nan_to_num(perplexities, 100)
perplexities = np.clip(perplexities, 0, 100)
plt.hist(perplexities, label='{}-{}'.format(model_name, lora_name), alpha=.5)

plt.xlabel('Perplexity')
plt.ylabel('Frequency')
plt.legend()
plt.savefig('figs/perplexity_hist.png')

7 changes: 6 additions & 1 deletion eval_self_instruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from peft import PeftModelForCausalLM
from transformers import AutoModelForCausalLM, AutoTokenizer

'''
Evaluates perplexity on the outputs of:
https://github.com/yizhongw/self-instruct/blob/main/human_eval/user_oriented_instructions.jsonl
'''

def read_jsonl_file(file_path):
data = []
with open(file_path, 'r', encoding='utf-8') as file:
Expand Down Expand Up @@ -47,7 +52,7 @@ def eval_example(model, tokenizer, example, config):
continuations = []
tokenized_continuations = []
trajectories = []
for i in range(3):
for i in range(1):
with torch.no_grad():
outputs = model.generate(input_ids=input['input_ids'],
max_new_tokens=config["max_new_tokens"],
Expand Down

0 comments on commit 6d98aef

Please sign in to comment.