-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_script.py
More file actions
60 lines (51 loc) · 2.03 KB
/
Copy pathgenerate_script.py
File metadata and controls
60 lines (51 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from transformers import AutoTokenizer
from omegaconf import OmegaConf
from models import DiffusionProteinLanguageModel
import torch
import pandas as pd
import os
model_paths = [
"training_results/second_attempt_big_increment_training/second_attempt_big_increment_training_weights.pth",
"training_results/second_attempt_big_two_stage_training/second_attempt_big_two_stage_training_weights.pth",
"/home/jtso3/ghassan/ProMDLM/training_results/fulldiff_weights.pth",
]
save_names = ["increment", "two_stage", "fulldiff"]
output_dir = "generated_sequences_215aa_long
os.makedirs(output_dir, exist_ok=True)
device = torch.device("cuda")
# PARAMETERS
max_iter = 500
generation_length = 150
nb_generated_sequences = 10
resample_ratio = 0.2
for model_path, save_name in zip(model_paths, save_names):
dict_list = []
model = torch.load(model_path, weights_only=False)
model = model.to(device)
tokenizer = AutoTokenizer.from_pretrained("facebook/esm2_t30_150M_UR50D")
for temperature in [0.5, 1, 1.5]:
print(
f"Generating sequences with temperature {temperature} for model {save_name}"
)
input_string = "cls " + "L " * generation_length + "eos"
input_id_one_seq = tokenizer.encode(input_string)
input_ids = torch.tensor([input_id_one_seq] * nb_generated_sequences)
input_ids = input_ids.to(device)
batch = {
"input_ids": input_ids,
}
output = model.generate(
batch,
max_iter=max_iter,
temperature=temperature,
resample_ratio=resample_ratio,
sampling_strategy="vanilla",
)
for i in range(nb_generated_sequences):
decode = tokenizer.decode(output[0][i], skip_special_tokens=True)
decode = decode.replace(" ", "")
dict_list.append(
{"model": save_name, "temperature": temperature, "sequence": decode}
)
df = pd.DataFrame(dict_list)
df.to_csv(f"{output_dir}/generated_sequences_{save_name}.csv", index=False)