Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3pretrained_model_name='lamm-mit/GPTProteinPretrained'
4
5tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name, trust_remote_code=True)
6tokenizer.pad_token = tokenizer.eos_token
7
8model_name = pretrained_model_name
9
10model = AutoModelForCausalLM.from_pretrained(
11 model_name,
12 trust_remote_code=True
13).to(device)
14
15model.config.use_cache = False1import torch
2device='cuda'
3prompt = "Sequence<ETAVPKLLQAL"
4generated = torch.tensor(tokenizer.encode(prompt, add_special_tokens = False)) .unsqueeze(0).to(device)
5print(generated.shape, generated)
6
7sample_outputs = model.generate(
8 inputs=generated,
9 eos_token_id =tokenizer.eos_token_id,
10 do_sample=True,
11 top_k=500,
12 max_length = 1024,
13 top_p=0.9,
14 num_return_sequences=1,
15 temperature=1,
16 ).to(device)
17
18for i, sample_output in enumerate(sample_outputs):
19 print("{}: {}\n\n".format(i, tokenizer.decode(sample_output, skip_special_tokens=True)))1torch.Size([1, 57]) tensor([[ 86, 104, 116, 120, 104, 113, 102, 104, 63, 80, 74, 84, 72, 73,
2 89, 81, 84, 87, 90, 89, 81, 72, 73, 76, 79, 79, 74, 79,
3 86, 86, 71, 84, 81, 87, 84, 89, 73, 79, 73, 89, 79, 76,
4 79, 89, 80, 92, 76, 76, 87, 89, 89, 74, 81, 86, 79, 76,
5 79]], device='cuda:0')
60: Sequence<MGQEFVNQTWVNEFILLGLSSDQNTQVFLFVLILVMYIITVVGNSLILLLIRLDSRLHTPMYFFLSNLSFVDLCFSTTTVPQLLANFLSVHKSISFLGCVAQLYIFLTLGGTEFFLLGAMAYDRYVAVCYPLHYTVIMNWRVCTSLAVASWVSGFLNSLVHTVITFRLPFCGPNEIDHFFCEVPALLKLACADTSLNEMAMNACCVLILLIPFSLILISYTRILITILRMPSATGRRKAFSTCASHIIVVILFYGTAISTYIQPSSDPVADQDKLMALFYAILTPMLNPIIYSLRNKDVKGAWQKLLNKLRVTQKRKFMAVTLH>@article{WeiKaplanBuehler_2023,
title = {Generative pretrained autoregressive transformer graph neural network applied to the analysis and discovery of novel proteins},
author = {M.J. Buehler},
journal = {J. Appl. Phys.},
year = {2023},
volume = {},
pages = {},
url = {https://doi.org/10.1063/5.0157367}
}