Skip to main content

ESM2 implemented in Equinox+JAX.

Project description

ESM2quinox

An implementation of [ESM2](https://github.com/facebookresearch/esm) in [Equinox+JAX](https://github.com/patric-kidger/equinox)

Only implements the representation trunk (not the structure-prediction head).

Installation

pip install esm2quinox

Public API

See their docstrings for details:

esm2quinox
    .ESM2
        .__init__(self, num_layers: int, embed_size: int, num_heads: int, token_dropout: bool, key: PRNGKeyArray)
        .__call__(self, tokens: Int[np.ndarray | jax.Array, " length"]) -> esm2quinox.ESM2Result

    .ESM2Result
        .hidden: Float[Array, "length embed_size"]
        .logits: Float[Array, "length alphabet_size"]

    .tokenise(proteins: list[str], length: None | int = None, key: None | PRNGKeyArray = None)

    .from_torch(torch_esm2: esm.ESM2) -> esm2quinox.ESM2

Quick examples

Load an equivalent pretrained model from PyTorch:

import esm  # pip install fair-esm==2.0.0
import esm2quinox

torch_model, _ = esm.pretrained.esm2_t6_8M_UR50D()
model = esm2quinox.from_torch(torch_model)

Create a randomly-initialised model:

import esm2quinox
import jax.random as jr

key = jr.key(1337)
model = esm2quinox.ESM2(num_layers=3, embed_size=32, num_heads=2, token_dropout=False, key=key)

Forward pass (note the model operates on unbatched data):

proteins = esm2quinox.tokenise(["SPIDERMAN", "FOO"])
out = jax.vmap(model)(proteins)
out.hidden  # hidden representation from last layer
out.logits  # logits for masked positions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

esm2quinox-0.1.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

esm2quinox-0.1.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file esm2quinox-0.1.0.tar.gz.

File metadata

  • Download URL: esm2quinox-0.1.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for esm2quinox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 23c28797e634bf510934759c4ddb7bcb367c7337d845901856e85749c661fa7f
MD5 b705898014fa58582267f18f6959e2f0
BLAKE2b-256 066965579ba4d7d8a63b914bee4d260455edc8b1a48b2b264b69c9fca97a849e

See more details on using hashes here.

File details

Details for the file esm2quinox-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: esm2quinox-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for esm2quinox-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9221b156c4b96b9f77eac8eabd8923b06f6931e64d28fdf7279755a29cbead16
MD5 f69c7b54ca011b3d20ba8baee6ec090c
BLAKE2b-256 17e3002ab367c9b903dbaaad031e9e422698a620edae773ba87c822c96a3e648

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page