Transformers
Inference Endpoints
exnx commited on
Commit
df86581
1 Parent(s): 53438f2

adding weights and config

Browse files
Files changed (4) hide show
  1. .DS_Store +0 -0
  2. README.md +162 -1
  3. config.json +25 -0
  4. loss.ckpt +3 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
README.md CHANGED
@@ -1,3 +1,164 @@
1
  ---
2
- license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: bsd-3-clause
3
  ---
4
+
5
+ # HyenaDNA
6
+
7
+ Welcome! HyenaDNA is a long-range genomic foundation model pretrained on context lengths of up to **1 million tokens** at **single nucleotide resolution**.
8
+
9
+ See below for an [overview](#model) of the model and training. Better yet, check out these resources.
10
+
11
+ **Resources:**
12
+
13
+ - [arxiv](https://arxiv.org/abs/2306.15794)
14
+ - [blog](https://hazyresearch.stanford.edu/blog/2023-06-29-hyena-dna)
15
+ - [colab](https://colab.research.google.com/drive/1wyVEQd4R3HYLTUOXEEQmp_I8aNC_aLhL?usp=sharing)
16
+ - [github](https://github.com/HazyResearch/hyena-dna)
17
+
18
+
19
+ **Links to all HuggingFace models:**
20
+
21
+ - [tiny-1k](https://huggingface.co/LongSafari/hyenadna-tiny-1k-seqlen/tree/main)
22
+ - [tiny-1k-d256](https://huggingface.co/LongSafari/hyenadna-tiny-1k-seqlen-d256/tree/main)
23
+ - [small-32k](https://huggingface.co/LongSafari/hyenadna-small-32k-seqlen/tree/main)
24
+ - [medium-160k](https://huggingface.co/LongSafari/hyenadna-medium-160k-seqlen/tree/main)
25
+ - [medium-450k](https://huggingface.co/LongSafari/hyenadna-medium-450k-seqlen/tree/main)
26
+ - [large-1m](https://huggingface.co/LongSafari/hyenadna-large-1m-seqlen/tree/main)
27
+
28
+ See [GPU requirements](#hardware) for each model.
29
+
30
+ ### Sample snippet
31
+
32
+
33
+ This code example lets you select which pretrained model to load from HuggingFace, perform inference and get embeddings.
34
+
35
+ See the [colab](https://colab.research.google.com/drive/1wyVEQd4R3HYLTUOXEEQmp_I8aNC_aLhL?usp=sharing) for these classes, or the ['huggingface.py'](https://github.com/HazyResearch/hyena-dna/blob/main/huggingface.py) script in the main [github](https://github.com/HazyResearch/hyena-dna).
36
+
37
+
38
+ ```python
39
+
40
+ # instantiate pretrained model
41
+ pretrained_model_name = 'hyenadna-medium-450k-seqlen'
42
+ max_length = 450_000
43
+
44
+ model = HyenaDNAPreTrainedModel.from_pretrained(
45
+ './checkpoints',
46
+ pretrained_model_name,
47
+ )
48
+
49
+ # create tokenizer, no training involved :)
50
+ tokenizer = CharacterTokenizer(
51
+ characters=['A', 'C', 'G', 'T', 'N'], # add DNA characters
52
+ model_max_length=max_length,
53
+ )
54
+
55
+ # create a sample
56
+ sequence = 'ACTG' * int(max_length/4)
57
+ tok_seq = tokenizer(sequence)["input_ids"]
58
+
59
+ # place on device, convert to tensor
60
+ tok_seq = torch.LongTensor(tok_seq).unsqueeze(0).to(device) # unsqueeze for batch dim
61
+
62
+ # prep model and forward
63
+ model.to(device)
64
+ model.eval() # deterministic
65
+
66
+ with torch.inference_mode():
67
+ embeddings = model(tok_seq)
68
+
69
+ print(embeddings.shape) # embeddings here!
70
+
71
+
72
+ ```
73
+
74
+ ### How to use pretrained weights
75
+
76
+ - [colab](https://colab.research.google.com/drive/1wyVEQd4R3HYLTUOXEEQmp_I8aNC_aLhL?usp=sharing)
77
+
78
+ The colab is the easiest entry point, you can finetune a small model, and do inference on DNA sequences up to 450k on the free tier (T4 GPU), and up to 1 million on the paid tier (A100). It handles all the HuggingFace integration for you, so it's helpful to see this example first.
79
+
80
+ - [github](https://github.com/HazyResearch/hyena-dna)
81
+
82
+ Otherwise, checkout of the main HyenaDNA repo for how to load weights into Pytorch Lightning. We use Pytorch Lightning for pretraining and fine-tuning all of our models. If you want to use our actual pretraining code, you can clone this HuggingFace repo to download the actual weights.ckpt, and then pass it to Pytorch Lightning via command line or config. See the [github](https://github.com/HazyResearch/hyena-dna) README for how to do all that.
83
+
84
+
85
+ If you want a standalone version that's easy to port into your own code (and not tied to our repo or Pytorch Lightning), we have that and a HuggingFace example in ['huggingface.py'](https://github.com/HazyResearch/hyena-dna/blob/main/huggingface.py) too.
86
+
87
+
88
+ ### GPU requirements (suggested)
89
+ <a name="hardware"></a>
90
+
91
+ Here are suggestions on the hardware (preferred minimum) we think you can use for each model.
92
+
93
+ GPU during: Pretrain, fine-tune, inference
94
+
95
+ - [tiny-1k](https://huggingface.co/LongSafari/hyenadna-tiny-1k-seqlen/tree/main): (T4, T4, T4)
96
+ - [small-32k](https://huggingface.co/LongSafari/hyenadna-small-32k-seqlen/tree/main): (A100-40, T4, T4)
97
+ - [medium-160k](https://huggingface.co/LongSafari/hyenadna-medium-160k-seqlen/tree/main): (A100-40, A100-40, T4)
98
+ - [medium-450k](https://huggingface.co/LongSafari/hyenadna-medium-450k-seqlen/tree/main): (A100-40, A100-40, T4)
99
+ - [large-1m](https://huggingface.co/LongSafari/hyenadna-large-1m-seqlen/tree/main): (A100-80, A100-80, A100-40)
100
+
101
+
102
+ T4: 16GB
103
+ A100-40: 40GB
104
+ A100-80: 80GB
105
+
106
+
107
+ ## Model & Training Overview
108
+ <a name="model"></a>
109
+
110
+ HyenaDNA uses a simple stack of [Hyena](https://arxiv.org/abs/2302.10866) operators, which are a subquadratic drop-in replacement for attention in Transformers. The Hyena operator is able to match quality in language modeling by using modified input projections, implicit convolutions and gating, all subquadratic operations.
111
+
112
+ This enables HyenaDNA to reach context lengths of up to 500x longer than previous genomic Transformer models using dense attention, and train 160x faster at sequence length 1M (compared to Flash Attention).
113
+
114
+ We use a single character tokenizer with a primary vocab of 4 nucleotides (plus special tokens), enabling the single nucleotide resolution, a first in genomic foundation models. In addition, the implicit long convolution enables a **global receptive field** at each layer.
115
+
116
+ We pretrain using next token (nucleotide) prediction on the human reference genome (HG38).
117
+
118
+ HyenaDNA sets new SotA on 23 downstream tasks including predicting regulatory elements, chromatin profiles, and species classification. We also explore what new capabilities open up with long context in genomics, including the first use of in-context learning with soft prompt tuneable tokens and instruction fine-tuning.
119
+
120
+
121
+ Check out our [blog](https://hazyresearch.stanford.edu/blog/2023-06-29-hyena-dna) for more details on HyenaDNA!
122
+
123
+ ### Authors
124
+
125
+ Eric Nguyen*, Michael Poli*, Marjan Faizi*, Armin Thomas, Callum Birch-Sykes, Michael Wornow, Aman Patel, Clayton Rabideau, Stefano Massaroli, Yoshua Bengio, Stefano Ermon, Stephen Baccus, Chris Re.
126
+
127
+ **Contact**
128
+
129
+ Eric Nguyen, etnguyen@stanford.edu
130
+ Michael Poli, poli@stanford.edu
131
+ Marjan Faizi, Marjan_Faizi@hms.harvard.edu
132
+
133
+
134
+ ## Citation
135
+
136
+
137
+ Feel free to cite us :)
138
+
139
+ ```
140
+ @article{nguyen2023hyenadna,
141
+ title={HyenaDNA: Long-Range Genomic Sequence Modeling at Single Nucleotide Resolution},
142
+ author={Eric Nguyen and Michael Poli and Marjan Faizi and Armin Thomas and Callum Birch-Sykes and Michael Wornow and Aman Patel and Clayton Rabideau and Stefano Massaroli and Yoshua Bengio and Stefano Ermon and Stephen A. Baccus and Chris Ré},
143
+ year={2023},
144
+ eprint={2306.15794},
145
+ archivePrefix={arXiv},
146
+ primaryClass={cs.LG}
147
+ }
148
+
149
+ ```
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "d_model": 128,
3
+ "n_layer": 2,
4
+ "d_inner": 512,
5
+ "vocab_size": 12,
6
+ "resid_dropout": 0.0,
7
+ "embed_dropout": 0.1,
8
+ "fused_mlp": false,
9
+ "fused_dropout_add_ln": true,
10
+ "residual_in_fp32": true,
11
+ "pad_vocab_size_multiple": 8,
12
+ "return_hidden_state": true,
13
+ "layer": {
14
+ "_name_": "hyena",
15
+ "emb_dim": 5,
16
+ "filter_order": 64,
17
+ "local_order": 3,
18
+ "l_max": 16386,
19
+ "modulate": true,
20
+ "w": 10,
21
+ "lr": 6e-4,
22
+ "wd": 0.0,
23
+ "lr_pos_emb": 0.0
24
+ }
25
+ }
loss.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:93012a18db942d86f73bbede8cf77ee39c727f76d50f24b1a0c2dc84090f0a59
3
+ size 6114981