Synthyra/ESMplusplus_large
1822k
1---2library_name: transformers3license: "mit"4tags:5 - protein-language-model6 - fastplms7---8 9<!-- Generated from src/fastplms/models.toml. Do not edit. -->10 11# ESM++ Large12 13## Model overview14 15`Synthyra/ESMplusplus_large` packages the `biohub/ESMC-600M` checkpoint with16the FastPLMs runtime for Hugging Face Transformers. It accepts amino-acid17sequences tokenized to residue IDs.18 19The repository uses the standard Transformers loading interface with20`trust_remote_code=True`. See Technical details for each registered class and21whether its weights come from the checkpoint.22 23The sequence- and token-classification classes reuse the pretrained backbone,24but their task heads are newly initialized. Fine-tune those heads before25interpreting their logits as predictions.26 27## Install and platform requirements28 29Install the direct dependencies published with this model:30 31```bash32python -m pip install -r \33 "https://huggingface.co/Synthyra/ESMplusplus_large/resolve/main/requirements.txt"34```35 36The FastPLMs implementation itself is embedded in the model repository.37Transformers loads it through `trust_remote_code=True`.38 39This model requires Python 3.11-3.14, PyTorch 2.13, and Transformers 5.13.40 41The artifact requirements include the FlashAttention loader dependency.42FlashAttention also requires compatible CUDA hardware and BF16 execution.43 44The Hub quick start needs network access for the first download. For an45air-gapped run, build the manifest-pinned local artifact first and use the46offline example.47 48## Quick start49 50```python51from transformers import AutoModel52 53model_id = "Synthyra/ESMplusplus_large"54model = AutoModel.from_pretrained(55 model_id,56 trust_remote_code=True,57 attn_implementation="sdpa",58).eval()59```60 61For offline validation, replace `model_id` with the manifest-built62`dist/hub/ESMplusplus_large` path. Pass `local_files_only=True`.63 64## Attention backends65 66The quick start uses `sdpa`.67 68Available backends are `eager`, `sdpa`, `flex_attention`, `flash_attention_2`,69`flash_attention_3`. Requesting an unavailable backend raises instead of70silently changing implementation.71 72`output_attentions=True` can use the documented one-call eager fallback to73materialize attention tensors. The configured backend does not change.74 75## Tokenization and forward inference76 77Load the tokenizer from the same artifact as the model. The attention mask78shows padding explicitly:79 80```python81import torch82 83from transformers import AutoTokenizer84 85 86model_id = "Synthyra/ESMplusplus_large"87tokenizer = AutoTokenizer.from_pretrained(88 model_id,89 trust_remote_code=True,90)91batch = tokenizer(92 ["MSTNPKPQRKTKRNT", "MKTIIALSYIFCLVFA"],93 padding=True,94 return_tensors="pt",95)96 97with torch.inference_mode():98 output = model(**batch)99 100print(output.last_hidden_state.shape)101```102 103## Dataset embeddings104 105The shared embedding mixin keeps input order and biological-position masking.106It accepts sequences, identified records, mappings, or a FASTA path:107 108```python109pooled = model.embed_dataset(110 ["MSTNPKPQRKTKRNT", "MKTIIALSYIFCLVFA"],111 batch_size=2,112 pooling=("mean", "std"),113)114residues = model.embed_dataset(115 ["MSTNPKPQRKTKRNT"],116 full_embeddings=True,117)118print(pooled[0].tensor.shape) # (2 * d,)119print(residues[0].tensor.shape) # (l, d)120```121 122Set `output` and `format="safetensors"` or `"sqlite"` for transactional,123bounded-memory storage. Resume checks input order, model state, tokenizer124policy, backend, dtype, and pooling configuration before it appends data.125 126## Downstream prediction127 128The sequence and token prediction AutoClasses use the checkpoint backbone and129create a new, untrained `classifier`. Sequence labels have shape `(b,)`.130Residue labels have shape `(b, l)` and use `-100` outside biological positions.131 132```python133import torch134 135from transformers import AutoTokenizer136from transformers import (137 AutoModelForSequenceClassification,138 AutoModelForTokenClassification,139)140 141 142model_id = "Synthyra/ESMplusplus_large"143sequence_model = AutoModelForSequenceClassification.from_pretrained(144 model_id, num_labels=2, trust_remote_code=True145).eval()146token_model = AutoModelForTokenClassification.from_pretrained(147 model_id, num_labels=3, trust_remote_code=True148).eval()149tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)150sequences = ["MSTNPKPQRKTKRNT", "MKTIIALSYIFCLVFA"]151batch = tokenizer(sequences, padding=True, return_tensors="pt")152biological = batch["attention_mask"].bool() # (b, l)153for special_id in tokenizer.all_special_ids:154 biological &= batch["input_ids"].ne(special_id) # (b, l)155 156sequence_labels = torch.zeros(len(sequences), dtype=torch.long) # (b,)157token_labels = torch.full_like(batch["input_ids"], -100) # (b, l)158token_labels[biological] = 0 # selected biological positions; labels stay (b, l)159 160with torch.inference_mode():161 sequence_output = sequence_model(**batch, labels=sequence_labels)162 token_output = token_model(**batch, labels=token_labels)163print(sequence_output.logits.shape) # (b, 2)164print(token_output.logits.shape) # (b, l, 3)165```166 167## PEFT fine-tuning168 169Install the training dependencies. Then attach LoRA to the loaded checkpoint:170 171```bash172python -m pip install "datasets>=4.8,<5" "peft>=0.19,<0.20"173```174 175```python176from peft import LoraConfig, TaskType, get_peft_model177 178 179peft_model = get_peft_model(180 sequence_model,181 LoraConfig(182 task_type=TaskType.SEQ_CLS,183 r=8,184 lora_alpha=16,185 target_modules="all-linear",186 modules_to_save=["classifier"],187 ),188)189```190 191This checkpoint advertises a classification head. Save the separately trained192`classifier` with the adapter.193All FastPLMs checkpoints follow the Transformers `PreTrainedModel` contract and194can use PEFT. The ESM2-specific shipped CLI is an example, not a195support boundary. Record the target modules, base revision, data identity, and196trainable parameter scope.197 198## Test-time training199 200TTT samples masked views of one protein and updates only injected low-rank201adapters. Base checkpoint weights stay frozen:202 203```python204from transformers import AutoModelForMaskedLM205 206 207ttt_model = AutoModelForMaskedLM.from_pretrained(208 "Synthyra/ESMplusplus_large",209 trust_remote_code=True,210)211metrics = ttt_model.ttt(212 seq="MSTNPKPQRKTKRNT",213 ttt_config={"steps": 3, "batch_size": 1, "seed": 7},214)215ttt_model.save_pretrained("adapted", safe_serialization=True)216ttt_model.ttt_reset()217print(metrics)218```219 220Saved adapters retain their deterministic reset state. TTT adds latency and221memory, can worsen an output, and does not show biological function.222 223## ESMC behavior224 225This artifact provides the Biohub ESMC sequence encoder and masked-language-226model head through Transformers. ESMFold2 also uses this language-model family.227SDPA is the default and gives the highest numerical fidelity. Flex Attention and228FlashAttention 3 are supported non-experimental backends. Their BF16 arithmetic229can differ numerically from SDPA. These differences give diagnostic warnings,230not strict-parity failures. Dispatch, masks, finite outputs, shapes, and large231biological disagreements remain hard gates.232 233The current GH200/aarch64 release environment validates eager, SDPA, and Flex.234Flash requests raise because compatible locked kernels are unavailable on this235platform.236 237When `sequence_id` is supplied, it controls ESMC attention groups and padding.238`attention_mask` is ignored. Values greater than or equal to zero are valid239sequence-group IDs. `-1` marks padding. Omit `sequence_id` to use240`attention_mask` for padding.241 242### Hidden-state sparse autoencoders243 244ESM++ supports hidden-state SAEs from the official245[Biohub ESMC SAE collection](https://huggingface.co/collections/biohub/esmc-saes-for-hidden-states-all-layers).246This artifact implements the SAE contract, so no Biohub runtime code is needed.247Select an SAE for this ESMC scale, then load only the layers you need:248 249```python250import torch251 252 253model.load_sae_models("biohub/ESMC-600M-sae-layer27-k64-codebook65536", [27])254 255with torch.inference_mode():256 output = model(**batch, normalize_sae=True)257 258features = output.sae_outputs["layer27"] # (valid_tokens, codebook_dim), sparse COO259print(features.shape, features.layout) # (valid_token_count, codebook_dim), sparse COO260```261 262`load_sae_models` reads the shared `config.json` and one263`layer_{index}.safetensors` shard per requested layer, from a Hub repository264or a local directory, and attaches the layers on the model device in the model265dtype. `add_sae_models` still accepts official Biohub `ESMCSAEModel.layers`266entries.267 268SAEs run after you attach them. Use `compute_sae=False` to skip SAE work.269Outputs are detached sparse tensors with keys such as `layer{N}`. They omit270padding. The model uses `sequence_id`, then `attention_mask`, for padding.271`normalize_sae=True` uses Biohub `(features / max) * idf` normalization. SAE272computation requires `input_ids`. It rejects mask tokens because Biohub trained273the SAEs with unmasked sequences. This interface supports hidden-state SAEs274only, not MLP-output SAEs. FastPLMs does not copy SAE weights or add SAE275checkpoints to its model manifest.276 277FP8 is restricted to ESMC-6B; smaller ESM++ models use BF16.278 279| Backend | Support | Measurement status |280| --- | --- | --- |281| `sdpa` | Recommended fidelity path | Pending release measurement |282| `eager` | Supported | Pending release measurement |283| `flash_attention_2` | Supported | Unavailable on current GH200/aarch64 lock |284| `flex_attention` | Supported, numerically divergent | Pending release measurement |285| `flash_attention_3` | Supported, numerically divergent | Unavailable on current GH200/aarch64 lock |286 287Detailed backend measurements, release guardrails, and the GH200 package288compatibility exception are maintained in the289[attention backend guide](https://github.com/Synthyra/FastPLMs/blob/main/docs/attention_backends.md)290and291[release evidence manifest](https://github.com/Synthyra/FastPLMs/blob/main/docs/generated/capability_evidence.md).292 293 294## Technical details295 296- Inputs: Amino-acid sequences tokenized to residue IDs297- Transformers classes: `AutoConfig`, `AutoModel`, `AutoModelForMaskedLM`, `AutoModelForSequenceClassification`, `AutoModelForTokenClassification`298- Checkpoint weights: `AutoConfig` = `FastPLMs extension`, `AutoModel` = `pretrained`, `AutoModelForMaskedLM` = `pretrained`, `AutoModelForSequenceClassification` = `base weights + untrained task head`, `AutoModelForTokenClassification` = `base weights + untrained task head`299- Attention backends: `eager`, `sdpa`, `flex_attention`, `flash_attention_2`, `flash_attention_3`300- Precision: `default`301- BF16 execution: `static_parameters`302- Generation contract: `not_applicable`303- Dependencies: `core`304- Weight publication allowed: `true`305- Weight license status: `resolved`306- Redistributable: `true`307- Complete weight publication required: `false`308 309## Validation and sources310 311FastPLMs pins the checkpoint, upstream source revisions, state transformation,312and required files in `models.toml`. Built artifacts record exact source313identities and conversion details in `source-record.json`.314 315- FastPLMs checkpoint: `Synthyra/ESMplusplus_large`316- Runtime revision: recorded separately in the built artifact and published commit317- Runtime source identities: recorded in `source-record.json`318- Official checkpoint: `biohub/ESMC-600M`319- Artifact source: `fast`320- State transform: `esmc_to_fastplms_v1`321- Pinned upstreams: `biohub-esm`, `biohub-transformers`322- Release tiers: `check`, `compliance`, `feature`, `artifact`, `benchmark`323- Unresolved required file identities: `0`324 325Release validation includes the `compliance` tier. Its evidence identifies the326checkpoint, backend, dtype, hardware, inputs, and reference revision.327 328Declared tiers compare configuration, tokenizer behavior, state, and329representative inference with the pinned reference. A nonzero unresolved count330blocks release. Metadata alone does not show that a build passed, that a backend331is faster, or that an output is biologically valid.332 333## License334 335Checkpoint terms: MIT. The Hub model-card identifier is336`mit`. The local artifact contains applicable source337licenses, notices, attribution, and conversion records. Review them before use.338 