lhallee commited on
Commit
eaea9f4
·
verified ·
1 Parent(s): 32d7d16

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +115 -10
README.md CHANGED
@@ -1,15 +1,120 @@
1
- ---
2
- {}
3
- ---
4
- Encoder only version of the [ANKH base model](https://huggingface.co/ElnaggarLab/ankh-base) ([paper](https://arxiv.org/abs/2301.06568)). The encoder only version is ideal for protein representation tasks.
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- ## To download
7
  ```python
8
- from transformers import T5EncoderModel, AutoTokenizer
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- model_path = 'Synthyra/ANKH_base'
11
- model = T5EncoderModel.from_pretrained(model_path)
12
- tokenizer = AutoTokenizer.from_pretrained(model_path)
13
  ```
14
 
15
- We are working on implementing a version of T5 based PLMs with [Flex attention](https://pytorch.org/blog/flexattention/) once learned relative position bias is supported (used in T5). Stay tuned.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FastANKH
2
+
3
+ Fast, optimized implementations of ANKH protein language models (T5-based) with multi-backend attention support.
4
+
5
+ **Requires PyTorch 2.11+** for Flash Attention 4 (FA4) backend support via flex attention.
6
+
7
+ ## Models
8
+
9
+ | Model | Params | Layers | Hidden | Heads | Activation | Source |
10
+ |-------|--------|--------|--------|-------|------------|--------|
11
+ | ANKH_base | 453.3M | 48 | 768 | 12 | gelu_new | ElnaggarLab/ankh-base |
12
+ | ANKH_large | 1.15B | 48 | 1536 | 16 | gelu_new | ElnaggarLab/ankh-large |
13
+ | ANKH2_large | 1.15B | 24 | 1536 | 16 | silu | ElnaggarLab/ankh2-ext2 |
14
+ | ANKH3_large | 1.15B | 48 | 1536 | 16 | silu | ElnaggarLab/ankh3-large |
15
+ | ANKH3_xl | 3.49B | 48 | 2560 | 32 | silu | ElnaggarLab/ankh3-xl |
16
+
17
+ ## Usage
18
 
 
19
  ```python
20
+ from transformers import AutoModel, AutoTokenizer
21
+
22
+ model = AutoModel.from_pretrained("Synthyra/ANKH_base", trust_remote_code=True)
23
+ tokenizer = AutoTokenizer.from_pretrained("Synthyra/ANKH_base")
24
+
25
+ # Set attention backend before loading for best performance
26
+ # Options: "sdpa" (default, exact), "flex" (FA4 on Hopper/Blackwell)
27
+ model.config.attn_backend = "flex"
28
+
29
+ sequences = ["MKTLLILAVL", "ACDEFGHIKLMNPQRSTVWY"]
30
+ inputs = tokenizer(sequences, return_tensors="pt", padding=True)
31
+ outputs = model(**inputs)
32
 
33
+ # Per-residue embeddings
34
+ embeddings = outputs.last_hidden_state # (batch, seq_len, hidden_dim)
 
35
  ```
36
 
37
+ ## Batch Embedding
38
+
39
+ ```python
40
+ model = AutoModel.from_pretrained("Synthyra/ANKH_base", trust_remote_code=True).to("cuda")
41
+ embeddings = model.embed_dataset(
42
+ sequences=["MKTLLILAVL", "ACDEFGHIKLMNPQRSTVWY"],
43
+ batch_size=8,
44
+ max_len=512,
45
+ full_embeddings=True,
46
+ )
47
+ ```
48
+
49
+ ## Attention Backends
50
+
51
+ | Backend | Key | Notes |
52
+ |---------|-----|-------|
53
+ | SDPA | `"sdpa"` | Default. Exact attention with position bias as additive mask. |
54
+ | Flex | `"flex"` | Uses FA4 on Hopper/Blackwell GPUs (PyTorch 2.11+). Position bias computed via `score_mod`. Triton fallback on older hardware. |
55
+ | Flash | `"kernels_flash"` | Not supported for ANKH (no arbitrary bias support). Falls back to flex/sdpa. |
56
+
57
+ ## Architecture
58
+
59
+ ANKH models are T5 encoder-only architectures:
60
+ - **No absolute position embeddings**: Uses T5-style relative position bias (log-bucketed, bidirectional)
61
+ - **RMS LayerNorm**: No mean subtraction, no bias term
62
+ - **Gated FFN**: `activation(wi_0(x)) * wi_1(x) -> wo(x)` with gelu_new (v1) or silu (v2/v3)
63
+ - **Pre-layer normalization**: Norm before attention and FFN, residual after
64
+ - **No bias in projections**: All q/k/v/o and FFN linear layers are bias=False
65
+
66
+ The relative position bias is computed once (materialized as a full tensor) and shared across all encoder layers. For the flex backend, the bias is passed as a `score_mod` closure for optimal performance.
67
+
68
+ ## Notes
69
+
70
+ - The `FastAnkhForMaskedLM` variant includes an LM head initialized from the shared embedding weights. The original ANKH models were trained with T5's span corruption objective using an encoder-decoder architecture. This encoder-only MaskedLM head is **not pre-trained for standard MLM** and requires additional fine-tuning.
71
+ - ANKH3 models use a vocabulary of 256 tokens (vs 144 for v1/v2) and were trained with dual objectives ([NLU] for embeddings, [S2S] for generation).
72
+
73
+ ## Citations
74
+
75
+ ```bibtex
76
+ @article{elnaggar2023ankh,
77
+ title={Ankh: Optimized Protein Language Model Unlocks General-Purpose Modelling},
78
+ author={Elnaggar, Ahmed and Essam, Hazem and Salah-Eldin, Wafaa and Moustafa, Walid and Elkerdawy, Mohamed and Rochereau, Charlotte and Rost, Burkhard},
79
+ journal={arXiv preprint arXiv:2301.06568},
80
+ year={2023}
81
+ }
82
+ ```
83
+
84
+ ```bibtex
85
+ @article{alsamkary2025ankh3,
86
+ title={Ankh3: Multi-Task Pretraining with Sequence Denoising and Completion Enhances Protein Representations},
87
+ author={Alsamkary, Hazem and Elshaffei, Mohamed and Elkerdawy, Mohamed and Elnaggar, Ahmed},
88
+ journal={arXiv preprint arXiv:2505.20052},
89
+ year={2025}
90
+ }
91
+ ```
92
+
93
+ ```bibtex
94
+ @misc{FastPLMs,
95
+ author={Hallee, Logan and Bichara, David and Gleghorn, Jason P.},
96
+ title={FastPLMs: Fast, efficient, protein language model inference from Huggingface AutoModel.},
97
+ year={2024},
98
+ url={https://huggingface.co/Synthyra/ESMplusplus_small},
99
+ DOI={10.57967/hf/3726},
100
+ publisher={Hugging Face}
101
+ }
102
+ ```
103
+
104
+ ```bibtex
105
+ @article{dong2024flexattention,
106
+ title={Flex Attention: A Programming Model for Generating Optimized Attention Kernels},
107
+ author={Dong, Juechu and Feng, Boyuan and Guessous, Driss and Liang, Yanbo and He, Horace},
108
+ journal={arXiv preprint arXiv:2412.05496},
109
+ year={2024}
110
+ }
111
+ ```
112
+
113
+ ```bibtex
114
+ @inproceedings{paszke2019pytorch,
115
+ title={PyTorch: An Imperative Style, High-Performance Deep Learning Library},
116
+ author={Paszke, Adam and Gross, Sam and Massa, Francisco and Lerer, Adam and Bradbury, James and Chanan, Gregory and Killeen, Trevor and Lin, Zeming and Gimelshein, Natalia and Antiga, Luca and Desmaison, Alban and K{\"o}pf, Andreas and Yang, Edward and DeVito, Zach and Raison, Martin and Tejani, Alykhan and Chilamkurthy, Sasank and Steiner, Benoit and Fang, Lu and Bai, Junjie and Chintala, Soumith},
117
+ booktitle={Advances in Neural Information Processing Systems 32},
118
+ year={2019}
119
+ }
120
+ ```