GithubHelp home page GithubHelp logo

Comments (3)

tomsercu avatar tomsercu commented on July 26, 2024 1

Hi - thanks for your question!
You can look at extract.py which does embeddings on gpu in batch, specifically look for this kind of logic around transfering to device: https://github.com/facebookresearch/esm/blob/master/extract.py#L62-L64
You can also look at pytorch introductory tutorials to learn how to work with devices in pytorch.
Cheers,
Tom

from esm.

joshim5 avatar joshim5 commented on July 26, 2024 1

In case it helps, here's a quick colab notebook with a concrete example. It's as easy as calling .cuda() on the model and on the data.

import torch

model, alphabet = torch.hub.load("facebookresearch/esm", "esm1_t34_670M_UR50S")
batch_converter = alphabet.get_batch_converter()

# Prepare data (two protein sequences)
data = [("protein1", "MYLYQKIKN"), ("protein2", "MNAKYD")]
batch_labels, batch_strs, batch_tokens = batch_converter(data)

# Extract per-residue embeddings (on GPU)
model = model.cuda()
with torch.no_grad():
    results = model(batch_tokens.cuda(), repr_layers=[34])
token_embeddings = results["representations"][34]

from esm.

AZaitzeff avatar AZaitzeff commented on July 26, 2024

@joshim5 Thank you! That helps a lot.

from esm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.