Skip to main content

FoldGemma: Protein folding language models

Project description

FoldGemma

Python 3.10+ License: MIT PyTorch Hugging Face Status

FoldGemma is an ultra-fast structural representation model based on the Gemma transformer architecture. It bridges the gap between protein language models and structural bioinformatics by rapidly translating raw amino acid sequences into structural 3Di tokens (Foldseek's structural alphabet). FoldGemma provides a pure PyTorch native pipeline for ultra-fast, high-throughput structural mapping.

Background

Protein structure prediction is a computationally intensive task. While tools like AlphaFold offer extreme accuracy, they are too slow for large-scale metagenomic sweeps. FoldGemma takes a different approach: rather than predicting 3D coordinates, it translates 1D amino acid sequences into a 1D sequence of 3Di tokens—the structural alphabet powering Foldseek.

By formulating structure prediction as a Sequence-to-Sequence (Seq2Seq) problem and running inference on an ultra-fast PyTorch architecture, FoldGemma can "fold" millions of proteins in a fraction of the time, allowing you to instantly search metagenomes using Foldseek.

Architecture: FoldGemma vs FoldGemmaT5

FoldGemma provides two distinct architectural variants, optimized for different use cases:

  1. FoldGemma (Encoder-Only Classification)

    • How it works: A pure bidirectional encoder network (based on Gemma's transformer blocks) that reads the amino acid sequence and applies a dense classification head. It simultaneously predicts the 3Di token for every residue in a single forward pass.
    • Best for: Ultra-fast, high-throughput structural mapping. Because it operates in O(1) time without autoregressive decoding, it is blisteringly fast and perfect for massive database sweeps.
  2. FoldGemmaT5 (Encoder-Decoder Generative)

    • How it works: A full sequence-to-sequence T5-style architecture. It uses the same Gemma encoder blocks to read the amino acid sequence, but couples it with causal decoder blocks and cross-attention mechanisms.
    • Best for: Complex generative tasks, probabilistic sampling, and autoregressive generation. While slower than the encoder-only variant, the causal decoder provides the architectural capacity for advanced language modeling and sequence generation.

Installation

You can install FoldGemma directly from PyPI using uv or pip:

uv pip install foldgemma

If you plan to train FoldGemma from scratch (e.g. using the massive AFDB dataset), install the optional training dependencies:

uv pip install foldgemma[train]

CLI Usage

FoldGemma provides a robust CLI for inferencing, training, deploying, and data preparation.

Inference

Convert a standard amino acid .fasta file into a 3Di .fasta file:

foldgemma infer -i proteins.fasta -o structures_3di.fasta --model-type foldgemma --weights ./model.safetensors

Data Preparation (AFDB)

FoldGemma includes a native PyTorch IterableDataset pipeline that can stream and parse Foldcomp FCZ databases into TFRecords via background workers to maximize I/O throughput.

foldgemma prep --tsv ./afdb241_ss.tsv --fcz ./afdb241_fcz --out-dir ./tfrecords --num-workers 16

Training

Start training on your generated TFRecords:

foldgemma train --data-dir ./tfrecords --epochs 10 --model-type foldgemma

Deployment

Deploy a trained model straight to the Hugging Face Hub:

foldgemma deploy --repo-id <username>/foldgemma --model-path ./model.safetensors

API Examples

FoldGemma exposes native PyTorch models (FoldGemma for fast classification mappings, and FoldGemmaT5 for full generative decoder tasks).

Basic Inference Example

import torch
from foldgemma import FoldGemma
from foldgemma.config import FoldGemmaConfig, ModelType
from foldgemma.data.vocabulary import Protein3diVocabulary

# 1. Initialize configuration and model
config = FoldGemmaConfig(model_type=ModelType.FOLDGEMMA)
model = FoldGemma(config)

# (Optional) Load trained weights
# from safetensors.torch import load_file
# model.load_state_dict(load_file("model.safetensors"))

model.eval()

# 2. Your raw amino acid sequence as a byte-string
seq = b"MVLTIY"

# 3. Encode the byte-string using the vocabulary
vocab = Protein3diVocabulary()
input_ids = vocab.encode_bytes(seq)

# 4. Convert to a PyTorch tensor and add the batch dimension
input_tensor = torch.tensor([input_ids], dtype=torch.long)

# 5. Run the forward pass!
with torch.inference_mode():
    logits = model(input_tensor)
    
# 6. Extract the predicted 3Di tokens
out_ids = logits.argmax(dim=-1)[0].cpu().tolist()
predicted_3di = vocab.decode_bytes(out_ids)

print(predicted_3di)

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

foldgemma-0.0.1.tar.gz (216.5 kB view details)

Uploaded Source

Built Distribution

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

foldgemma-0.0.1-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file foldgemma-0.0.1.tar.gz.

File metadata

  • Download URL: foldgemma-0.0.1.tar.gz
  • Upload date:
  • Size: 216.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for foldgemma-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ff4fdf70375a22ef97523713df8a30a909bea96b80fd6c922dbe79d1e84195dc
MD5 7162cb3202c296a179226ac087ce4dc7
BLAKE2b-256 2264389047cb6dcd7bb6ee6158f5d59d811c4f58eaa616a0d2f0c95b85d73364

See more details on using hashes here.

File details

Details for the file foldgemma-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: foldgemma-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for foldgemma-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f72ed8db2bfbb113f544fa50ba7349c1800f604fc3d149bcb7b8c7529ebd264b
MD5 003ad0df58e280cd4b4100165080cf30
BLAKE2b-256 72fb12d4b2e8e883deaf5c276507f11fad7537d2ffac4b152b4c6a0515be1c46

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