amyxlu / cpcprot Goto Github PK
View Code? Open in Web Editor NEWParameter-efficient embeddings for proteins, pretrained using a contrastive loss.
Parameter-efficient embeddings for proteins, pretrained using a contrastive loss.
When running the "API for Embedding Protein Sequences" example from the readme, sequences shorter than 11 residues fail.
E.g. seq = "SEQWENCEILV"
works, while seq = "SEQWENCEIL"
fails:
c_mean = embedder.get_c_mean(input) # (1, 512)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/CPCProt/model/heads.py", line 124, in get_c_mean
c, mask = self.get_c(data, return_mask = True)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/CPCProt/model/heads.py", line 105, in get_c
c = self.cpc.get_c(z)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/CPCProt/model/cpcprot.py", line 102, in get_c
c = self.autoregressor(z[:,:max_L,:]).to(self.device)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/CPCProt/model/autoregressor.py", line 27, in forward
output, regress_hidden_state = self.gru(input_seq, regress_hidden_state)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/torch/nn/modules/rnn.py", line 726, in forward
result = _VF.gru(input, hx, self._flat_weights, self.bias, self.num_layers,
RuntimeError: stack expects a non-empty TensorList
A sequence with 9 residues or less fails with a different error:
z_mean = embedder.get_z_mean(input) # (1, 512)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/CPCProt/model/heads.py", line 113, in get_z_mean
z, mask = self.get_z(data, return_mask=True)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/CPCProt/model/heads.py", line 91, in get_z
z = self.cpc(x, return_early='z')
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/CPCProt/model/cpcprot.py", line 115, in forward
z = self.get_z(x)
File "/home/konsti/bio_embeddings/.venv/lib/python3.8/site-packages/CPCProt/model/cpcprot.py", line 81, in get_z
patch_ends = torch.arange(self.cfg.patch_len, x.shape[1]+1, self.cfg.patch_len, device=self.device)
RuntimeError: upper bound and larger bound inconsistent with step sign
Calling the .get_c() method from the embedder instance created in the example
embedder = CPCProtEmbedding(model)
ends up throwing a CUDA out of memory error, because it is tracking the gradients
def get_c(self, data, return_mask = False):
z, mask = self.get_z(data, return_mask=True)
if self.parallel:
# workaround for accessing model attributes when DataParallel
c = self.cpc(data, return_early='c')
else:
c = self.cpc.get_c(z)
wrapping the forward pass in a "with torch.no_grad():" worked for me
def get_c(self, data, return_mask = False):
z, mask = self.get_z(data, return_mask=True)
with torch.no_grad():
if self.parallel:
# workaround for accessing model attributes when DataParallel
c = self.cpc(data, return_early='c')
else:
c = self.cpc.get_c(z)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.