proteinglm commited on
Commit
c699045
·
verified ·
1 Parent(s): 487d5a5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +144 -3
README.md CHANGED
@@ -1,3 +1,144 @@
1
- ---
2
- license: cc-by-nc-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ tags:
4
+ - biology
5
+ ---
6
+ # ProteinGLM
7
+
8
+ ## Introduction to ProteinGLM Family Models
9
+
10
+ ProteinGLM is the open-source version of the latest protein language models towards protein understanding tasks (Masked Protein Language Models) and protein design (Casual Protein Language Models). The ProteinGLM family models are developed by Tsinghua University. Along with this, we have released the int4 quantization ProteinGLM-100B weights and other small models, which include: 1B, 3B, and 10B models trained with masked language modeling for protein understanding, and 1B, 3B, and 7B causal language models aimed at protein design.
11
+
12
+ ### Out-of-Distribution Perplexity Evaluation
13
+
14
+ We evaluated the ProteinGLM (MLM or CLM) and ProteinGLM-INT4 (100B) models on two OOD test sets, one with sequence identity lower than 0.9 with the training set (<0.9 ID) and the other with sequence identity lower than 0.5 with the training set (<0.5 ID). Each OOD dataset comprises approximately 10,000 protein sequences. The MLM perplexity results, compared against ESM2-3B and ESM2-15B and the CLM perplexity againest ProGen2-xlarge (6.4B), are as follows (lower is better):
15
+
16
+ | Model | ESM2(3B)| ESM2 (15B) | PGLM (1B) | PGLM (3B) | PGLM (10B) | PGLM-INT4 (100B) |
17
+ |:--------------------|:----------:|:----------:|:----------:|:----------:|:--------------------:|:--------------------:|
18
+ | < 0.9 ID | 7.7 | 7.3 | 9.3 | 7.8 | 7.6 | **6.8** |
19
+ | < 0.5 ID | 11.5 | 11.0 | 13.5 | 11.9 | 11.6 | **10.8** |
20
+
21
+
22
+ | Model | ProGen2-xlarge (6.4B) | PGLM (1B) | PGLM (3B) | PGLM (7B) | PGLM-INT4 (100B) |
23
+ |:--------------------|:----------:|:----------:|:----------:|:--------------------:|:--------------------:|
24
+ | < 0.9 ID | 9.7 | 9.8 | 9.3 | 8.9 | **8.9** |
25
+ | < 0.5 ID | 14.3 | 14.0 | 13.7 | 13.5 | **13.5** |
26
+
27
+
28
+ ## Downstream Protein Understanding Tasks Evaluation
29
+ (TODO)
30
+
31
+ ## Get Started
32
+ ### Model List
33
+ You can choose to manually download the necessary weights
34
+
35
+ | Model |Download |
36
+ |------------------|-----------------------------------------------------------------------------------------------------------|
37
+ | ProteinGLM-1B-MLM | [🤗 Huggingface](https://huggingface.co/proteinglm/proteinglm-1b-mlm) |
38
+ | ProteinGLM-3B-MLM | [🤗 Huggingface](https://huggingface.co/proteinglm/proteinglm-3b-mlm) |
39
+ | ProteinGLM-10B-MLM | [🤗 Huggingface](https://huggingface.co/proteinglm/proteinglm-10b-mlm) |
40
+ | ProteinGLM-1B-CLM | [🤗 Huggingface](https://huggingface.co/proteinglm/proteinglm-1b-clm) |
41
+ | ProteinGLM-3B-CLM | [🤗 Huggingface](https://huggingface.co/proteinglm/proteinglm-3b-clm) |
42
+ | ProteinGLM-7B-CLM | [🤗 Huggingface](https://huggingface.co/proteinglm/proteinglm-7b-clm) |
43
+ | ProteinGLM-INT4 (100B) (MLM or CLM) | [🤗 Huggingface](https://huggingface.co/proteinglm/proteinglm-100b-int4)| | |
44
+
45
+ ## How to use
46
+ ### ProteinGLM-MLM: Masked Langeuage Models for Protein Understanding Tasks
47
+ (The ProteinGLM-100B INT4 quantization requires approximately 50 GB of GPU memory. It can be inferred on a single A100/800 GPU with 80 GB of memory or across multiple GPUs totaling 60 GB.)
48
+ ```python
49
+
50
+ # Obtain residue embeddings
51
+ from transformers import AutoModelForMaskedLM, AutoModelForSequenceClassification, AutoModelForTokenClassification, AutoTokenizer, AutoConfig
52
+ import torch
53
+
54
+ tokenizer = AutoTokenizer.from_pretrained("proteinglm/proteinglm-100b-int4", trust_remote_code=True, use_fast=True)
55
+ config = AutoConfig.from_pretrained("proteinglm/proteinglm-100b-int4", trust_remote_code=True, torch_dtype=torch.half)
56
+ config.is_causal=False
57
+ config.post_layer_norm=True # use the final layernorm or not, some tasks set to false would be better.
58
+ model = AutoModelForMaskedLM.from_pretrained("proteinglm/proteinglm-100b-int4", config = config, torch_dtype=torch.half,trust_remote_code=True)
59
+ if torch.cuda.is_available():
60
+ model = model.cuda()
61
+
62
+ # # if you don't have the single gpu with 80G memory, try the dispatch load.
63
+ # from accelerate import load_checkpoint_and_dispatch, init_empty_weights
64
+ # with init_empty_weights():
65
+ # model = AutoModelForMaskedLM.from_config(config, trust_remote_code=True)
66
+ #
67
+ # model = load_checkpoint_and_dispatch(
68
+ # model, "<your model cached dir>", device_map="auto", no_split_module_classes=["xTrimoPGLMBlock"], strict=True, dtype=dtype
69
+ # )
70
+
71
+ model.eval()
72
+
73
+ seq = 'MILMCQHFSGQFSKYFLAVSSDFCHFVFPIILVSHVNFKQMKRKGFALWNDRAVPFTQGIFTTVMILLQYLHGTG'
74
+ output = tokenizer(seq, add_special_tokens=True, return_tensors='pt')
75
+ with torch.inference_mode():
76
+ inputs = {"input_ids": output["input_ids"].cuda(), "attention_mask": output["attention_mask"].cuda()}
77
+ output_embeddings = model(**inputs, output_hidden_states=True, return_last_hidden_state=True).hidden_states[:-1, 0] # get rid of the <eos> token
78
+
79
+
80
+ # model for the sequence-level tasks
81
+ model = AutoModelForSequenceClassification.from_pretrained(config, trust_remote_code=True, torch_dtype=torch.half)
82
+
83
+ # model for the token-level tasks
84
+ model = AutoModelForTokenClassification.from_pretrained(config, trust_remote_code=True, torch_dtype=torch.half)
85
+
86
+ ```
87
+
88
+ ### ProteinGLM-CLM: Casusal Langeuage Models for Protein Design
89
+ ```python
90
+ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
91
+ import torch
92
+
93
+ tokenizer = AutoTokenizer.from_pretrained("proteinglm/proteinglm-100b-int4", trust_remote_code=True, use_fast=True)
94
+ config = AutoConfig.from_pretrained("proteinglm/proteinglm-100b-int4", trust_remote_code=True, torch_dtype=torch.half)
95
+ config.is_causal=True
96
+ model = AutoModelForCausalLM.from_pretrained("proteinglm/proteinglm-100b-int4", config = config, torch_dtype=torch.half,trust_remote_code=True)
97
+ if torch.cuda.is_available():
98
+ model = model.cuda()
99
+
100
+ # # if you don't have the single gpu with 80G memory, try the dispatch load.
101
+ # from accelerate import load_checkpoint_and_dispatch, init_empty_weights
102
+ # with init_empty_weights():
103
+ # model = AutoModelForMaskedLM.from_config(config, trust_remote_code=True)
104
+ #
105
+ # model = load_checkpoint_and_dispatch(
106
+ # model, "<your model cached dir>", device_map="auto", no_split_module_classes=["xTrimoPGLMBlock"], strict=True, dtype=dtype
107
+ # )
108
+ model.eval()
109
+
110
+ gen_kwargs = {'max_length': 256, 'top_p': 0.8, 'temperature':0.9, "num_beams": 1}
111
+ prompt=['', 'MLFVVL', 'LDL', 'VTQA']
112
+
113
+ for idx, each in enumerate(prompt):
114
+ print(f"Begin generating idx: {idx} with prompt {each}")
115
+ output = model.chat(tokenizer, each, **gen_kwargs)
116
+ print(f"\nEnd generation with length: {len(output.split())} - seqs: {output}\n")
117
+ ```
118
+
119
+
120
+ ## LICENSE
121
+
122
+ The model in this repository is open source under the [Creative Commons Attribution-NonCommercial 4.0 International License](./LICENSE).
123
+
124
+ ## Citations
125
+
126
+ If you find our work useful, please consider citing the following paper:
127
+ ```
128
+ @misc{chen2024xtrimopglm,
129
+ title={xTrimoPGLM: unified 100B-scale pre-trained transformer for deciphering the language of protein},
130
+ author={Chen, Bo and Cheng, Xingyi and Li, Pan and Geng, Yangli-ao and Gong, Jing and Li, Shen and Bei, Zhilei and Tan, Xu and Wang, Boyan and Zeng, Xin and others},
131
+ year={2024},
132
+ eprint={2401.06199},
133
+ archivePrefix={arXiv},
134
+ primaryClass={cs.CL},
135
+ note={arXiv preprint arXiv:2401.06199}
136
+ }
137
+
138
+ @misc{cheng2024training,
139
+ title={Training Compute-Optimal Protein Language Models},
140
+ author={Cheng, Xingyi and Chen, Bo and Li, Pan and Gong, Jing and Tang, Jie and Song, Le},
141
+ year={2024},
142
+ note={bioRxiv, Cold Spring Harbor Laboratory, pages 2024--06}
143
+ }
144
+ ```