File size: 10,679 Bytes
92d2403
 
 
 
 
 
 
 
 
 
605dff9
92d2403
605dff9
92d2403
605dff9
 
 
92d2403
605dff9
 
 
b0ad7ff
605dff9
 
 
b0ad7ff
92d2403
 
b0ad7ff
92d2403
 
b0ad7ff
 
92d2403
 
402d419
 
b0ad7ff
605dff9
 
 
 
 
 
 
 
92d2403
 
 
 
 
 
 
 
 
 
b0ad7ff
92d2403
 
 
b0ad7ff
402d419
b0ad7ff
605dff9
 
 
 
 
 
92d2403
402d419
 
b0ad7ff
92d2403
 
105ae09
402d419
 
92d2403
402d419
 
 
92d2403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402d419
 
92d2403
 
 
 
 
 
 
 
b0ad7ff
92d2403
 
402d419
 
92d2403
 
 
 
 
105ae09
92d2403
 
 
 
 
 
 
 
 
b0ad7ff
 
 
 
 
 
 
59af8db
b0ad7ff
59af8db
 
 
b0ad7ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402d419
b0ad7ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402d419
 
b0ad7ff
402d419
b0ad7ff
 
 
 
 
 
402d419
b0ad7ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92d2403
 
402d419
 
92d2403
 
 
105ae09
402d419
105ae09
92d2403
 
 
105ae09
92d2403
105ae09
 
 
92d2403
105ae09
92d2403
 
 
 
 
105ae09
92d2403
105ae09
92d2403
 
 
402d419
 
 
92d2403
 
 
 
 
 
 
605dff9
92d2403
605dff9
 
 
 
 
92d2403
 
605dff9
92d2403
 
 
105ae09
92d2403
605dff9
 
 
 
 
92d2403
605dff9
59af8db
 
 
 
105ae09
92d2403
 
 
 
 
 
605dff9
 
92d2403
402d419
605dff9
 
 
92d2403
 
 
 
402d419
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
---
library_name: transformers
license: "cc-by-nc-sa-4.0"
tags:
  - protein-language-model
  - fastplms
---

<!-- Generated from src/fastplms/models.toml. Do not edit. -->

# ANKH-Large

## Model overview

`Synthyra/ANKH_large` packages the `ElnaggarLab/ankh-large` checkpoint with the
FastPLMs runtime for Hugging Face Transformers. It accepts amino-acid sequences
tokenized for encoder or sequence-to-sequence use.

The repository uses the standard Transformers loading interface with
`trust_remote_code=True`. See Technical details for each registered class and
whether its weights come from the checkpoint.

The sequence- and token-classification classes reuse the pretrained backbone,
but their task heads are newly initialized. Fine-tune those heads before
interpreting their logits as predictions.

## Install and platform requirements

Install the direct dependencies published with this model:

```bash
python -m pip install -r \
  "https://huggingface.co/Synthyra/ANKH_large/resolve/main/requirements.txt"
```

The FastPLMs implementation itself is embedded in the model repository.
Transformers loads it through `trust_remote_code=True`.

This model requires Python 3.11-3.14, PyTorch 2.13, and Transformers 5.13.

The CPU gate covers small offline tests. Published checkpoint throughput and
parity require the documented device tier.

The Hub quick start needs network access for the first download. For an
air-gapped run, build the manifest-pinned local artifact first and use the
offline example.

## Quick start

```python
from transformers import AutoModel

model_id = "Synthyra/ANKH_large"
model = AutoModel.from_pretrained(
    model_id,
    trust_remote_code=True,
    attn_implementation="sdpa",
).eval()
```

For offline validation, replace `model_id` with the manifest-built
`dist/hub/ANKH_large` path. Pass `local_files_only=True`.

## Attention backends

The quick start uses `sdpa`.

Available backends are `eager`, `sdpa`. Requesting an unavailable backend
raises instead of silently changing implementation.

`output_attentions=True` can use the documented one-call eager fallback to
materialize attention tensors. The configured backend does not change.

## Tokenization and forward inference

`Synthyra/ANKH_large` contains the complete encoder-decoder checkpoint.
`AutoModel` loads the encoder without the decoder. `AutoModelForSeq2SeqLM`
loads the encoder, decoder, cross-attention, and language-model head.

Use the tokenizer from the loaded model. This keeps tokenizer files, revision,
offline/cache policy, and ANKH's residue-aware pre-tokenizer aligned. Pass raw
protein strings without residue spaces:

```python
import torch

tokenizer = model.tokenizer
batch = tokenizer(
    ["MSTNPKPQRKTKRNT", "MKTIIALSYIFCLVFA"],
    padding=True,
    return_tensors="pt",
)

with torch.inference_mode():
    output = model(**batch)

print(output.last_hidden_state.shape)
```

## Dataset embeddings

Dataset embeddings use the final encoder state by default. Select a native
encoder layer directly:

```python
encoder_result = model.embed_dataset(
    ["MSTNPKPQRKTKRNT"],
    hidden_state_source="encoder",
    hidden_state_index=-1,
    full_embeddings=True,
)
print(encoder_result[0].tensor.shape)  # (l, d)
```

Decoder representations require `AutoModelForSeq2SeqLM` and one aligned decoder
input. ANKH does not create a shifted target:

```python
from transformers import AutoModelForSeq2SeqLM

seq2seq = AutoModelForSeq2SeqLM.from_pretrained(
    "Synthyra/ANKH_large",
    trust_remote_code=True,
).eval()
decoder_result = seq2seq.embed_dataset(
    ["MSTNPKPQRKTKRNT"],
    hidden_state_source="decoder",
    hidden_state_index=-1,
    decoder_inputs=["M<extra_id_0>"],
    full_embeddings=True,
)
print(decoder_result[0].tensor.shape)  # (decoder_length, d)
```

Pooling excludes boundary, padding, sentinel, and other non-biological
positions. Persisted results record the selected stack, layer, inputs, masks,
and alignment policy.

## Downstream prediction

The sequence and token prediction AutoClasses use the checkpoint backbone and
create a new, untrained `classifier`. Sequence labels have shape `(b,)`.
Residue labels have shape `(b, l)` and use `-100` outside biological positions.

```python
import torch
from transformers import AutoTokenizer
from transformers import (
    AutoModelForSequenceClassification,
    AutoModelForTokenClassification,
)

model_id = "Synthyra/ANKH_large"
sequence_model = AutoModelForSequenceClassification.from_pretrained(
    model_id, num_labels=2, trust_remote_code=True
).eval()
token_model = AutoModelForTokenClassification.from_pretrained(
    model_id, num_labels=3, trust_remote_code=True
).eval()
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
sequences = ["MSTNPKPQRKTKRNT", "MKTIIALSYIFCLVFA"]
batch = tokenizer(sequences, padding=True, return_tensors="pt")
biological = batch["attention_mask"].bool()
for special_id in tokenizer.all_special_ids:
    biological &= batch["input_ids"].ne(special_id)

sequence_labels = torch.zeros(len(sequences), dtype=torch.long)
token_labels = torch.full_like(batch["input_ids"], -100)
token_labels[biological] = 0

with torch.inference_mode():
    sequence_output = sequence_model(**batch, labels=sequence_labels)
    token_output = token_model(**batch, labels=token_labels)
print(sequence_output.logits.shape)  # (b, 2)
print(token_output.logits.shape)     # (b, l, 3)
```

## PEFT fine-tuning

Install the training dependencies. Then attach LoRA to the loaded checkpoint:

```bash
python -m pip install "datasets>=4.8,<5" "peft>=0.19,<0.20"
```

```python
from peft import LoraConfig, TaskType, get_peft_model

peft_model = get_peft_model(
    sequence_model,
    LoraConfig(
        task_type=TaskType.SEQ_CLS,
        r=8,
        lora_alpha=16,
        target_modules="all-linear",
        modules_to_save=["classifier"],
    ),
)
```

This checkpoint advertises a classification head. Save the separately trained
`classifier` with the adapter.
All FastPLMs checkpoints follow the Transformers `PreTrainedModel` contract and
can use PEFT. The ESM2-specific shipped CLI is an example, not a
support boundary. Record the target modules, base revision, data identity, and
trainable parameter scope.

## Test-time training

TTT samples masked views of one protein and updates only injected low-rank
adapters. Base checkpoint weights stay frozen:

```python
from transformers import AutoModelForMaskedLM

ttt_model = AutoModelForMaskedLM.from_pretrained(
    "Synthyra/ANKH_large",
    trust_remote_code=True,
)
metrics = ttt_model.ttt(
    seq="MSTNPKPQRKTKRNT",
    ttt_config={"steps": 3, "batch_size": 1, "seed": 7},
)
ttt_model.save_pretrained("adapted", safe_serialization=True)
ttt_model.ttt_reset()
print(metrics)
```

Saved adapters retain their deterministic reset state. TTT adds latency and
memory, can worsen an output, and does not show biological function.

## Encoder and sequence-to-sequence use

`Synthyra/ANKH_large` contains the complete ANKH encoder-decoder checkpoint.
Use `AutoModel` for encoder embeddings. Use `AutoModelForSeq2SeqLM` for
task-specific decoding:

```python
import torch
from transformers import AutoModel, AutoModelForSeq2SeqLM, AutoTokenizer

repo_id = "Synthyra/ANKH_large"
tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
encoder = AutoModel.from_pretrained(repo_id, trust_remote_code=True).eval()
seq2seq = AutoModelForSeq2SeqLM.from_pretrained(
    repo_id,
    trust_remote_code=True,
).eval()
batch = tokenizer("MSTNPKPQRKTKRNT", return_tensors="pt")

with torch.inference_mode():
    encoder_hidden = encoder(**batch).last_hidden_state
    generated_ids = seq2seq.generate(**batch, max_new_tokens=16)
print(encoder_hidden.shape)
print(tokenizer.batch_decode(generated_ids, skip_special_tokens=True))
```

ANKH artifacts retain CC BY-NC-SA 4.0 terms. The notes below distinguish official
heads from FastPLMs extensions. The complete checkpoint is larger than the former
encoder-only mirror and preserves encoder-output parity.

## Notes and limitations

ANKH parity covers the official encoder and sequence-to-sequence heads.
AutoModelForMaskedLM exposes the separately named FastPLMs synthesized
masked-LM extension and is not an official ANKH head.

## Technical details

- Inputs: Amino-acid sequences tokenized for encoder or sequence-to-sequence use
- Transformers classes: `AutoConfig`, `AutoModel`, `AutoModelForMaskedLM`, `AutoModelForSeq2SeqLM`, `AutoModelForSequenceClassification`, `AutoModelForTokenClassification`
- Checkpoint weights: `AutoConfig` = `FastPLMs extension`, `AutoModel` = `pretrained`, `AutoModelForMaskedLM` = `FastPLMs extension`, `AutoModelForSeq2SeqLM` = `pretrained`, `AutoModelForSequenceClassification` = `base weights + untrained task head`, `AutoModelForTokenClassification` = `base weights + untrained task head`
- Attention backends: `eager`, `sdpa`
- Precision: `default`
- BF16 execution: `static_parameters`
- Generation contract: `required`
- Dependencies: `core`
- Weight publication allowed: `true`
- Weight license status: `resolved`
- Redistributable: `true`
- Complete weight publication required: `false`

## Validation and provenance

FastPLMs pins the checkpoint, upstream source revisions, state transformation,
and required files in `models.toml`. Built artifacts record exact source
identities and conversion details in `source-record.json`.

- FastPLMs checkpoint: `Synthyra/ANKH_large`
- Runtime revision: recorded separately in the built artifact and published commit
- Runtime source identities: recorded in `source-record.json`
- Canonical transformed state identity: recorded in `source-record.json`
- Conversion equality attestation: recorded in `source-record.json`
- Official checkpoint: `ElnaggarLab/ankh-large`
- Artifact source: `official`
- State transform: `ankh_t5_to_fastplms_v1`
- Pinned upstreams: `ankh`
- Release tiers: `check`, `compliance`, `feature`, `artifact`, `benchmark`
- Unresolved required file identities: `0`

Release validation includes the `compliance` tier. Its evidence identifies the
checkpoint, backend, dtype, hardware, inputs, and reference revision.

Declared tiers compare configuration, tokenizer behavior, state, and
representative inference with the pinned reference. A nonzero unresolved count
blocks release. Metadata alone does not show that a build passed, that a backend
is faster, or that an output is biologically valid.

## License

Checkpoint terms: CC-BY-NC-SA-4.0. The Hub model-card identifier is
`cc-by-nc-sa-4.0`. The local artifact contains applicable source
licenses, notices, attribution, and conversion records. Review them before use.