-
Notifications
You must be signed in to change notification settings - Fork 5
/
run_eval.py
22 lines (14 loc) · 1 KB
/
run_eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
tokenizer = AutoTokenizer.from_pretrained('InstructPLM/MPNN-ProGen2-xlarge-CATH42', trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained('InstructPLM/MPNN-ProGen2-xlarge-CATH42', trust_remote_code=True)
model.cuda().eval()
model.requires_grad_(False)
batch = tokenizer('Fast-PETase.pyd|1MQTNPYARGPNPTAASLEASAGPFTVRSFTVSRPSGYGAGTVYYPTNAGGTVGAIAIVPGYTARQSSIKWWGPRLASHGFVVITIDTNSTLDQPESRSSQQMAALRQVASLNGTSSSPIYGKVDTARMGVMGWSMGGGGSLISAANNPSLKAAAPQAPWHSSTNFSSVTVPTLIFACENDSIAPVNSSALPIYDSMSQNAKQFLEIKGGSHSCANSGNSNQALIGKKGVAWMKRFMDNDTRYSTFACENPNSTAVSDFRTANCS2',return_tensors='pt').to(device=model.device)
labels = batch.input_ids.masked_fill((1-batch.attention_mask).bool(), -100)
labels[:, :tokenizer.n_queries+1] = -100
batch["labels"] = labels
with torch.no_grad():
with torch.cuda.amp.autocast(dtype=torch.float16):
output = model(**batch)
print(f'loss: {output.loss.item()}, perplexity: {torch.exp(output.loss.item())}')