wangjin2000 commited on
Commit
ae5cd29
·
verified ·
1 Parent(s): 871c9c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -125,6 +125,8 @@ def finetune(base_model_path, peptide_length): #, train_dataset, test_dataset)
125
  def compute_pseudo_perplexity(model, tokenizer, protein_seq, binder_seq):
126
  start = time.time()
127
  sequence = protein_seq + binder_seq
 
 
128
  original_input = tokenizer.encode(sequence, return_tensors='pt').to(model.device)
129
  length_of_binder = len(binder_seq)
130
 
@@ -155,8 +157,14 @@ def compute_pseudo_perplexity(model, tokenizer, protein_seq, binder_seq):
155
  def compute_plddt_iptm(protein_seq, binder_seq):
156
  start = time.time()
157
  # always the ESMFold model
158
- model = EsmForProteinFolding.from_pretrained("facebook/esmfold_v1")
159
  tokenizer = AutoTokenizer.from_pretrained("facebook/esmfold_v1")
 
 
 
 
 
 
160
 
161
  sequence = protein_seq + binder_seq
162
  inputs = tokenizer(sequence, return_tensors='pt', add_special_tokens=False)
@@ -195,7 +203,8 @@ def generate_peptide_for_single_sequence(model, tokenizer, protein_seq, peptide_
195
  masked_peptide = '<mask>' * peptide_length
196
  input_sequence = protein_seq + masked_peptide
197
  inputs = tokenizer(input_sequence, return_tensors="pt").to(model.device)
198
-
 
199
  with torch.no_grad():
200
  logits = model(**inputs).logits
201
 
 
125
  def compute_pseudo_perplexity(model, tokenizer, protein_seq, binder_seq):
126
  start = time.time()
127
  sequence = protein_seq + binder_seq
128
+
129
+ print("129:model.device in compute_pseudo_perplexity",model.device)
130
  original_input = tokenizer.encode(sequence, return_tensors='pt').to(model.device)
131
  length_of_binder = len(binder_seq)
132
 
 
157
  def compute_plddt_iptm(protein_seq, binder_seq):
158
  start = time.time()
159
  # always the ESMFold model
160
+ #model = EsmForProteinFolding.from_pretrained("facebook/esmfold_v1")
161
  tokenizer = AutoTokenizer.from_pretrained("facebook/esmfold_v1")
162
+
163
+ # based on https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/protein_folding.ipynb
164
+ model = EsmForProteinFolding.from_pretrained("facebook/esmfold_v1", low_cpu_mem_usage=True)
165
+ model = model.cuda()
166
+ model.esm = model.esm.half() # Uncomment to switch the stem to float16
167
+ torch.backends.cuda.matmul.allow_tf32 = True
168
 
169
  sequence = protein_seq + binder_seq
170
  inputs = tokenizer(sequence, return_tensors='pt', add_special_tokens=False)
 
203
  masked_peptide = '<mask>' * peptide_length
204
  input_sequence = protein_seq + masked_peptide
205
  inputs = tokenizer(input_sequence, return_tensors="pt").to(model.device)
206
+ print("198:model.device in generate_:",model.device)
207
+
208
  with torch.no_grad():
209
  logits = model(**inputs).logits
210