Marcochris commited on
Commit
c9bad8a
·
verified ·
1 Parent(s): e053411

Add files using upload-large-folder tool

Browse files
Files changed (40) hide show
  1. .gitattributes +4 -0
  2. data_raw/amplify/AMPLIFY_120M/.gitattributes +35 -0
  3. data_raw/amplify/AMPLIFY_120M/AMPLIFY_120M_SHA256.tsv +11 -0
  4. data_raw/amplify/AMPLIFY_120M/README.md +117 -0
  5. data_raw/amplify/AMPLIFY_120M/amplify.py +304 -0
  6. data_raw/amplify/AMPLIFY_120M/amplify.py.pre_xformers_fallback_20260809 +282 -0
  7. data_raw/amplify/AMPLIFY_120M/config.json +37 -0
  8. data_raw/amplify/AMPLIFY_120M/model.safetensors +3 -0
  9. data_raw/amplify/AMPLIFY_120M/rmsnorm.py +32 -0
  10. data_raw/amplify/AMPLIFY_120M/rotary.py +80 -0
  11. data_raw/amplify/AMPLIFY_120M/special_tokens_map.json +7 -0
  12. data_raw/amplify/AMPLIFY_120M/tokenizer.json +154 -0
  13. data_raw/amplify/AMPLIFY_120M/tokenizer_config.json +58 -0
  14. data_raw/clinvar/variant_summary.txt.gz +3 -0
  15. data_raw/doid/doid.obo +0 -0
  16. data_raw/mutation_ppi_external/intact/mutations.tsv +3 -0
  17. data_raw/mutation_ppi_external/skempi2/skempi_v2.jsonl +0 -0
  18. data_raw/protein_complex_external/complexportal/9606.tsv +0 -0
  19. data_raw/protein_complex_external/complexportal/COMPLEXPORTAL_UPLOAD_VERIFIED.flag +6 -0
  20. data_raw/protein_complex_external/complexportal/CURATED_COMPLEXPORTAL_CONFIRMED.flag +8 -0
  21. data_raw/protein_complex_external/complexportal/LOCAL_DOWNLOAD_MANIFEST.txt +7 -0
  22. data_raw/protein_complex_external/complexportal/SHA256_9606_LOCAL.txt +2 -0
  23. data_raw/protein_complex_external/complexportal/SHA256_9606_REMOTE.txt +2 -0
  24. data_raw/protein_complex_external/complexportal/SOURCE.txt +9 -0
  25. data_raw/protein_complex_external/complexportal/UPLOAD_VERIFICATION.tsv +2 -0
  26. data_raw/ptmd/Acetylation.zip +3 -0
  27. data_raw/ptmd/Phosphorylation.zip +3 -0
  28. data_raw/ptmd/Ubiquitination.zip +3 -0
  29. data_raw/ptmd/unzipped/PTMD2_Acetylation.csv +0 -0
  30. data_raw/ptmd/unzipped/PTMD2_Phosphorylation.csv +3 -0
  31. data_raw/ptmd/unzipped/PTMD2_Ubiquitination.csv +3 -0
  32. data_raw/ptmint/PTM experimental evidence.csv +0 -0
  33. data_raw/ptmint/SHA256SUMS.txt +1 -0
  34. data_raw/ptmint/SOURCE_URL.txt +4 -0
  35. data_raw/reactome/ReactomePathways.txt +0 -0
  36. data_raw/reactome/ReactomePathwaysRelation.txt +0 -0
  37. data_raw/reactome/UniProt2Reactome_All_Levels.txt +3 -0
  38. data_raw/uniprot/UP000005640_9606.fasta.gz +3 -0
  39. data_raw/uniprot/UP000005640_9606_isoforms.fasta.gz +3 -0
  40. data_raw/uniprot/uniprot_sprot_human.dat.gz +3 -0
.gitattributes CHANGED
@@ -58,3 +58,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
+ data_raw/reactome/UniProt2Reactome_All_Levels.txt filter=lfs diff=lfs merge=lfs -text
62
+ data_raw/mutation_ppi_external/intact/mutations.tsv filter=lfs diff=lfs merge=lfs -text
63
+ data_raw/ptmd/unzipped/PTMD2_Ubiquitination.csv filter=lfs diff=lfs merge=lfs -text
64
+ data_raw/ptmd/unzipped/PTMD2_Phosphorylation.csv filter=lfs diff=lfs merge=lfs -text
data_raw/amplify/AMPLIFY_120M/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
data_raw/amplify/AMPLIFY_120M/AMPLIFY_120M_SHA256.tsv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ relative_path size_bytes sha256 repository revision
2
+ .gitattributes 1519 11ad7efa24975ee4b0c3c3a38ed18737f0658a5f75a0a96787b576a78a023361 chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
3
+ README.md 5579 23d6eb44faa2283b2a7c71cbdd900596ffc5b2b557c33ae3aef233295298bb3f chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
4
+ amplify.py 11950 aaefa417bcc6562cab45d244669c765b8fc0238af6712958e63d1eb52d81b3f2 chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
5
+ config.json 906 b28a52518d6006d5f0ceda4737b8623a30760fc79294f84771eb061b7bb8c5d3 chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
6
+ model.safetensors 473126988 a2375f1f54cbe00bdbe27eedcd039c92d12f165720c0349bc582a6eb42c099ce chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
7
+ rmsnorm.py 1172 3f63bdd73a4c8c35f67622f799e592062066b602c82d6c98569754facdbb382d chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
8
+ rotary.py 3337 ab73337b627e7a104d2c0c7299f929d6da836417d8b8203c47e3a9bc2d3918ab chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
9
+ special_tokens_map.json 125 bd9d67e56bef291e8ef29559a842f0bc62e46799dae42c63490a77a688682275 chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
10
+ tokenizer.json 2619 07043215b16802129fee788489f51e245f8d28e1d05fedb42cdb6900749f54db chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
11
+ tokenizer_config.json 1234 935811b1dcacff5e6763c260a00599244630d63a6280a341c82918c513fa1b12 chandar-lab/AMPLIFY_120M d918a9e8c64dc43f6ec4996022c3deba14d66470
data_raw/amplify/AMPLIFY_120M/README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - chandar-lab/UR100P
5
+ language:
6
+ - en
7
+ tags:
8
+ - biology
9
+ ---
10
+
11
+ ## AMPLIFY
12
+
13
+ AMPLIFY is an efficient, state-of-the-art protein language model pre-trained using masked language modeling on UniRef100, OAS, and SCOP ([UR100P](https://huggingface.co/datasets/chandar-lab/UR100P)). AMPLIFY can generate residue and protein embeddings, suggest mutations, differentiate disordered proteins from non-protein sequences, and much more. AMPLIFY is available in two sizes, 120M and 350M parameters, with the `_base` models not extended beyond 512 residues (Stage 1). The model architecture and pre-training procedure are detailed below. For more details, please refer to the [accompanying paper](https://www.biorxiv.org/content/10.1101/2024.09.23.614603v1).
14
+
15
+ - [`AMPLIFY_350M`](https://huggingface.co/chandar-lab/AMPLIFY_350M)
16
+ - [`AMPLIFY_350M_base`](https://huggingface.co/chandar-lab/AMPLIFY_350M_base)
17
+ - [`AMPLIFY_120M`](https://huggingface.co/chandar-lab/AMPLIFY_120M)
18
+ - [`AMPLIFY_120M_base`](https://huggingface.co/chandar-lab/AMPLIFY_120M_base)
19
+
20
+ ### Model Descritpion
21
+
22
+ | | AMPLIFY 120M | AMPLIFY 350M |
23
+ | :----------------------------- | -----------: | -----------: |
24
+ | `hidden-size` | 640 | 960 |
25
+ | `num-hidden-layers` | 24 | 32 |
26
+ | `num-attention-heads` | 10 | 15 |
27
+ | `intermediate-size` | 2560 | 3840 |
28
+ | `max-position-embeddings` | 2048 | 2048 |
29
+ | `vocab-size` | 27 | 27 |
30
+ | `rope-theta` | 10000 | 10000 |
31
+ | `dropout-prob` | 0 | 0 |
32
+ | `embedding-init-range` | 0.02 | 0.02 |
33
+ | `norm-eps` | 1.0e-05 | 1.0e-05 |
34
+ | `hidden-act` | swiglu | swiglu |
35
+ | `pre-activation-layer-norm` | true | true |
36
+ | `layer-norm-after-embedding` | false | false |
37
+ | `layer-norm-before-last-layer` | true | true |
38
+ | `rms-norm` | true | true |
39
+ | `ffn-bias` | false | false |
40
+ | `attn-bias` | false | false |
41
+
42
+ ### Training Descritpion
43
+
44
+ | | Stage 1 | Stage 2 |
45
+ | :------------------ | ----------: | ---------------------------: |
46
+ | `dataset` | UR100P | UR100P |
47
+ | `max-steps` | 1000000 | 25000 (120M) or 50000 (350M) |
48
+ | `max-length` | 512 | 2048 |
49
+ | `optimizer` | adamw | adamw |
50
+ | `lr` | 0.001 | 0.0001 |
51
+ | `betas` | (0.9, 0.95) | (0.9, 0.95) |
52
+ | `eps` | 1.0e-08 | 1.0e-08 |
53
+ | `weight-decay` | 0.01 | 0.01 |
54
+ | `scheduler` | cosinedecay | none |
55
+ | `warmup-steps` | 1,000 | none |
56
+ | `final-step` | 900,000 | none |
57
+ | `warmup-steps` | 1,000 | none |
58
+ | `gradient-clipping` | 1.0 | 1.0 |
59
+ | `tf32` | true | true |
60
+ | `mixed-precision` | bf16 | bf16 |
61
+ | `padding` | max-length | max-length |
62
+ | `random-truncate` | true | true |
63
+ | `mask-probability` | 0.15 | 0.15 |
64
+ | `total-batch-size` | 4096 | 4096 |
65
+ | `deepspeed` | true | true |
66
+ | `zero-stage` | 3 | 3 |
67
+
68
+ ## Get Started
69
+
70
+ ```python
71
+ from transformers import AutoModel
72
+ from transformers import AutoTokenizer
73
+ from datasets import load_dataset
74
+
75
+ # Load AMPLIFY and tokenizer
76
+ model = AutoModel.from_pretrained("chandar-lab/AMPLIFY_350M", trust_remote_code=True)
77
+ tokenizer = AutoTokenizer.from_pretrained("chandar-lab/AMPLIFY_350M", trust_remote_code=True)
78
+
79
+ # Move the model to GPU (required due to Flash Attention)
80
+ model = model.to("cuda")
81
+
82
+ # Load the UniProt validation set
83
+ dataset = load_dataset("chandar-lab/UR100P", data_dir="UniProt", split="test")
84
+
85
+ for sample in dataset:
86
+ # Protein
87
+ print("Sample: ", sample["name"], sample["sequence"])
88
+
89
+ # Tokenize the protein
90
+ input = tokenizer.encode(sample["sequence"], return_tensors="pt")
91
+ print("Input: ", input)
92
+
93
+ # Move to the GPU and make a prediction
94
+ input = input.to("cuda")
95
+ output = model(input)
96
+ print("Output: ", output)
97
+
98
+ break
99
+ ```
100
+
101
+ ## Citations
102
+
103
+ If you find the models useful in your research, we ask that you cite the paper:
104
+
105
+ ```bibtex
106
+ @article{Fournier2024.09.23.614603,
107
+ title = {Protein Language Models: Is Scaling Necessary?},
108
+ author = {Fournier, Quentin and Vernon, Robert M. and van der Sloot, Almer and Schulz, Benjamin and Chandar, Sarath and Langmead, Christopher James},
109
+ year = {2024},
110
+ journal = {bioRxiv},
111
+ publisher = {Cold Spring Harbor Laboratory},
112
+ doi = {10.1101/2024.09.23.614603},
113
+ url = {https://www.biorxiv.org/content/early/2024/09/23/2024.09.23.614603},
114
+ elocation-id = {2024.09.23.614603},
115
+ eprint = {https://www.biorxiv.org/content/early/2024/09/23/2024.09.23.614603.full.pdf}
116
+ }
117
+ ```
data_raw/amplify/AMPLIFY_120M/amplify.py ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # From https://stackoverflow.com/a/23689767
2
+ # From https://github.com/pytorch/pytorch/issues/97899
3
+ # From https://github.com/facebookresearch/llama/blob/main/llama/model.py
4
+
5
+ import torch
6
+ from torch import nn
7
+ from torch.nn.functional import scaled_dot_product_attention
8
+ try:
9
+ from xformers.ops import SwiGLU, memory_efficient_attention
10
+ XFORMERS_AVAILABLE = True
11
+ except Exception:
12
+ XFORMERS_AVAILABLE = False
13
+ class SwiGLU(nn.Module):
14
+ def __init__(self, dim, hidden, out, bias=False):
15
+ super().__init__()
16
+ self.w12 = nn.Linear(dim, hidden * 2, bias=bias)
17
+ self.w3 = nn.Linear(hidden, out, bias=bias)
18
+ def forward(self, x):
19
+ a, b = self.w12(x).chunk(2, dim=-1)
20
+ return self.w3(torch.nn.functional.silu(a) * b)
21
+ def memory_efficient_attention(query, key, value, attn_bias=None, p=0.0):
22
+ q = query.transpose(1, 2); k = key.transpose(1, 2); v = value.transpose(1, 2)
23
+ mask = attn_bias
24
+ if mask is not None:
25
+ mask = mask.to(q.dtype)
26
+ if mask is not None and mask.ndim == 2:
27
+ mask = mask[:, None, None, :]
28
+ return torch.nn.functional.scaled_dot_product_attention(
29
+ q, k, v, attn_mask=mask, dropout_p=p
30
+ ).transpose(1, 2)
31
+
32
+ from .rmsnorm import RMSNorm
33
+ from .rotary import precompute_freqs_cis, apply_rotary_emb
34
+
35
+ from transformers import PreTrainedModel, PretrainedConfig
36
+ from transformers.modeling_outputs import MaskedLMOutput
37
+
38
+
39
+ class DotDict(dict):
40
+ """Dictionary that supports the dot notation to access attributes (similarly to HuggingFace)."""
41
+
42
+ __getattr__ = dict.get
43
+ __setattr__ = dict.__setitem__
44
+ __delattr__ = dict.__delitem__
45
+
46
+
47
+ class AMPLIFYConfig(PretrainedConfig):
48
+ model_type = "AMPLIFY"
49
+
50
+ # All config parameters must have a default value.
51
+ def __init__(
52
+ self,
53
+ hidden_size: int = 960,
54
+ num_hidden_layers: int = 32,
55
+ num_attention_heads: int = 15,
56
+ intermediate_size: int = 3840,
57
+ dropout_prob: float = 0,
58
+ embedding_init_range: float = 0.02,
59
+ decoder_init_range: float = 0.02,
60
+ rms_norm: bool = True,
61
+ norm_eps: float = 1e-05,
62
+ hidden_act: str = "SwiGLU",
63
+ layer_norm_after_embedding: bool = False,
64
+ layer_norm_before_last_layer: bool = True,
65
+ vocab_size: int = 27,
66
+ ffn_bias: bool = False,
67
+ att_bias: bool = False,
68
+ pad_token_id: int = 0,
69
+ max_length: int = 2048,
70
+ **kwargs,
71
+ ):
72
+ super().__init__(**kwargs)
73
+
74
+ self.hidden_size = hidden_size
75
+ self.num_hidden_layers = num_hidden_layers
76
+ self.num_attention_heads = num_attention_heads
77
+ self.intermediate_size = intermediate_size
78
+ self.dropout_prob = dropout_prob
79
+ self.embedding_init_range = embedding_init_range
80
+ self.decoder_init_range = decoder_init_range
81
+ self.rms_norm = rms_norm
82
+ self.norm_eps = norm_eps
83
+ self.hidden_act = hidden_act
84
+ self.layer_norm_after_embedding = layer_norm_after_embedding
85
+ self.layer_norm_before_last_layer = layer_norm_before_last_layer
86
+ self.vocab_size = vocab_size
87
+ self.ffn_bias = ffn_bias
88
+ self.att_bias = att_bias
89
+ self.pad_token_id = pad_token_id
90
+ self.max_length = max_length
91
+
92
+
93
+ class EncoderBlock(nn.Module):
94
+ """Transformer encoder block."""
95
+
96
+ def __init__(self, config: AMPLIFYConfig):
97
+ """Initialize a EncoderBlock.
98
+
99
+ Args:
100
+ hidden_size (int): _description_
101
+ num_attention_heads (int): _description_
102
+ intermediate_size (int, optional): _description_. Defaults to 2048.
103
+ dropout_prob (float, optional): _description_. Defaults to 0.1.
104
+ activation (str, optional): _description_. Defaults to "relu".
105
+ rms_norm (bool, optional): _description_. Defaults to True.
106
+ norm_eps (float, optional): _description_. Defaults to 1e-5.
107
+ pad_token_id (int, optional): _description_. Defaults to 0.
108
+ max_length (int, optional): _description_. Defaults to 2048.
109
+ ffn_bias (bool, optional): _description_. Defaults to False.
110
+ att_bias (bool, optional): _description_. Defaults to False.
111
+ """
112
+ super().__init__()
113
+
114
+ self.config = config
115
+ self.d_head = config.hidden_size // config.num_attention_heads
116
+
117
+ # Attention
118
+ self.q = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=config.att_bias)
119
+ self.k = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=config.att_bias)
120
+ self.v = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=config.att_bias)
121
+ self.wo = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=config.att_bias)
122
+ self.resid_dropout = nn.Dropout(config.dropout_prob)
123
+
124
+ # Feedforward network
125
+ match config.hidden_act.lower():
126
+ case "swiglu":
127
+ # To keep the number of parameters and the amount of computation constant, we reduce the number of
128
+ # hidden units by a factor of 2/3 (https://arxiv.org/pdf/2002.05202.pdf) and make it a multiple of 8 to
129
+ # avoid RuntimeError due to misaligned operand
130
+ multiple_of = 8
131
+ intermediate_size = int(2 * config.intermediate_size / 3)
132
+ intermediate_size = multiple_of * ((intermediate_size + multiple_of - 1) // multiple_of)
133
+ self.ffn = SwiGLU(config.hidden_size, intermediate_size, config.hidden_size, bias=config.ffn_bias)
134
+ case "relu":
135
+ self.ffn = nn.Sequential(
136
+ nn.Linear(config.hidden_size, config.intermediate_size, bias=config.ffn_bias),
137
+ nn.ReLU(),
138
+ nn.Linear(config.intermediate_size, config.hidden_size, bias=config.ffn_bias),
139
+ )
140
+ case "gelu":
141
+ self.ffn = nn.Sequential(
142
+ nn.Linear(config.hidden_size, config.intermediate_size, bias=config.ffn_bias),
143
+ nn.GELU(),
144
+ nn.Linear(config.intermediate_size, config.hidden_size, bias=config.ffn_bias),
145
+ )
146
+
147
+ self.attention_norm = (
148
+ RMSNorm(config.hidden_size, config.norm_eps)
149
+ if config.rms_norm
150
+ else nn.LayerNorm(config.hidden_size, config.norm_eps)
151
+ )
152
+ self.ffn_norm = (
153
+ RMSNorm(config.hidden_size, config.norm_eps)
154
+ if config.rms_norm
155
+ else nn.LayerNorm(config.hidden_size, config.norm_eps)
156
+ )
157
+
158
+ self.ffn_dropout = nn.Dropout(config.dropout_prob)
159
+
160
+ def forward(self, x: torch.Tensor, attention_mask: torch.Tensor, freqs_cis: torch.Tensor, output_attentions: bool):
161
+ attn, contact = self._att_block(self.attention_norm(x), attention_mask, freqs_cis, output_attentions)
162
+ x = x + attn
163
+ x = x + self._ff_block(self.ffn_norm(x))
164
+ return x, contact
165
+
166
+ def _att_block(
167
+ self, x: torch.Tensor, attention_mask: torch.Tensor, freqs_cis: torch.Tensor, output_attentions: bool
168
+ ):
169
+ batch_size, seq_len, _ = x.shape
170
+ xq, xk, xv = self.q(x), self.k(x), self.v(x)
171
+
172
+ # Reshape for rotary embeddings
173
+ xq = xq.view(batch_size, seq_len, self.config.num_attention_heads, self.d_head)
174
+ xk = xk.view(batch_size, seq_len, self.config.num_attention_heads, self.d_head)
175
+ xv = xv.view(batch_size, seq_len, self.config.num_attention_heads, self.d_head)
176
+ xq, xk = apply_rotary_emb(xq, xk, freqs_cis)
177
+
178
+ # Compute the attention weight
179
+ attn_weights = None
180
+ if output_attentions:
181
+ attn_weights = xq.permute(0, 2, 1, 3) @ xk.permute(0, 2, 3, 1) / (xq.size(-1) ** 0.5)
182
+ if attention_mask is not None:
183
+ attn_weights = attn_weights + attention_mask
184
+ attn_weights = attn_weights.softmax(-1)
185
+
186
+ # Compute the attention using xformers if the tensors are on GPU
187
+ if x.is_cuda:
188
+ # Input and output are of dimension (B, M, H, K) where B is the batch size, M the sequence length,
189
+ # H the number of heads, and K the embeding size per head
190
+ attn = memory_efficient_attention(
191
+ query=xq,
192
+ key=xk,
193
+ value=xv,
194
+ attn_bias=attention_mask,
195
+ p=self.config.dropout_prob if self.training else 0,
196
+ )
197
+ else:
198
+ # Input and output are of dimension (B, H, M, K)
199
+ attn = scaled_dot_product_attention(
200
+ query=xq.transpose(1, 2),
201
+ key=xk.transpose(1, 2),
202
+ value=xv.transpose(1, 2),
203
+ attn_mask=attention_mask,
204
+ dropout_p=self.config.dropout_prob if self.training else 0,
205
+ ).transpose(1, 2)
206
+
207
+ attn_scores = self.wo(attn.view(batch_size, seq_len, self.config.num_attention_heads * self.d_head))
208
+ return (self.resid_dropout(attn_scores), attn_weights)
209
+
210
+ def _ff_block(self, x: torch.Tensor):
211
+ return self.ffn_dropout(self.ffn(x))
212
+
213
+
214
+ class AMPLIFYPreTrainedModel(PreTrainedModel):
215
+ config_class = AMPLIFYConfig
216
+
217
+ def _init_weights(self, module):
218
+ if isinstance(module, nn.Linear):
219
+ module.weight.data.uniform_(-self.config.decoder_init_range, self.config.decoder_init_range)
220
+ if module.bias is not None:
221
+ module.bias.data.zero_()
222
+ elif isinstance(module, nn.Embedding):
223
+ module.weight.data.uniform_(-self.config.embedding_init_range, self.config.embedding_init_range)
224
+
225
+
226
+ class AMPLIFY(AMPLIFYPreTrainedModel):
227
+ """The main model class.
228
+
229
+ Args:
230
+ config (amplify.model.amplify.AMPLIFYConfig): model configuration, usually defined from the Hydra configuration.
231
+ """
232
+
233
+ def __init__(self, config: AMPLIFYConfig, **kwargs):
234
+ super().__init__(config)
235
+
236
+ self.config = config
237
+
238
+ self.encoder = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id)
239
+
240
+ if config.layer_norm_after_embedding:
241
+ self.layer_norm_1 = (
242
+ RMSNorm(config.hidden_size, config.norm_eps)
243
+ if config.rms_norm
244
+ else nn.LayerNorm(config.hidden_size, config.norm_eps)
245
+ )
246
+
247
+ self.transformer_encoder = nn.ModuleList()
248
+ for _ in range(config.num_hidden_layers):
249
+ self.transformer_encoder.append(EncoderBlock(config))
250
+
251
+ if config.layer_norm_before_last_layer:
252
+ self.layer_norm_2 = (
253
+ RMSNorm(config.hidden_size, config.norm_eps)
254
+ if config.rms_norm
255
+ else nn.LayerNorm(config.hidden_size, config.norm_eps)
256
+ )
257
+
258
+ self.decoder = nn.Linear(config.hidden_size, config.vocab_size)
259
+
260
+ self.freqs_cis = precompute_freqs_cis(config.hidden_size // config.num_attention_heads, config.max_length)
261
+
262
+ # Initialize weights and apply final processing
263
+ self.post_init()
264
+
265
+ def forward(self, input_ids, attention_mask=None, output_hidden_states=False, output_attentions=False, **kwargs):
266
+ # Initialize
267
+ hidden_states, attentions = [], []
268
+
269
+ # Expand and repeat: (Batch, Length) -> (Batch, Heads, Length, Length)
270
+ if attention_mask is not None and not torch.all(attention_mask == 0):
271
+ assert attention_mask.dtype != torch.bool and 1.0 not in attention_mask, (
272
+ "AMPLIFY expects an additive attention_mask.\n"
273
+ "Modify the output of the tokenizer with attention_mask = torch.where(attention_mask, float(0.0), float('-inf'))"
274
+ )
275
+ attention_mask = (
276
+ attention_mask.unsqueeze(1)
277
+ .unsqueeze(1)
278
+ .repeat(1, self.config.num_attention_heads, attention_mask.size(-1), 1)
279
+ )
280
+ else:
281
+ attention_mask = None
282
+
283
+ # RoPE
284
+ self.freqs_cis = self.freqs_cis.to(input_ids.device, non_blocking=True)
285
+ freqs_cis = self.freqs_cis[: input_ids.shape[1]]
286
+
287
+ # Embedding
288
+ x = self.encoder(input_ids)
289
+ if self.config.layer_norm_after_embedding:
290
+ x = self.layer_norm_1(x)
291
+
292
+ # Transformer encoder
293
+ for layer in self.transformer_encoder:
294
+ x, attn = layer(x, attention_mask, freqs_cis, output_attentions)
295
+ if output_hidden_states:
296
+ hidden_states.append(x)
297
+ if output_attentions:
298
+ attentions.append(attn)
299
+
300
+ # Classification head with layer norm
301
+ logits = self.decoder(self.layer_norm_2(x) if self.config.layer_norm_before_last_layer else x)
302
+
303
+ # Return logits or the output of the last hidden layer
304
+ return MaskedLMOutput(logits=logits, hidden_states=hidden_states, attentions=attentions)
data_raw/amplify/AMPLIFY_120M/amplify.py.pre_xformers_fallback_20260809 ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # From https://stackoverflow.com/a/23689767
2
+ # From https://github.com/pytorch/pytorch/issues/97899
3
+ # From https://github.com/facebookresearch/llama/blob/main/llama/model.py
4
+
5
+ import torch
6
+ from torch import nn
7
+ from torch.nn.functional import scaled_dot_product_attention
8
+ from xformers.ops import SwiGLU, memory_efficient_attention
9
+
10
+ from .rmsnorm import RMSNorm
11
+ from .rotary import precompute_freqs_cis, apply_rotary_emb
12
+
13
+ from transformers import PreTrainedModel, PretrainedConfig
14
+ from transformers.modeling_outputs import MaskedLMOutput
15
+
16
+
17
+ class DotDict(dict):
18
+ """Dictionary that supports the dot notation to access attributes (similarly to HuggingFace)."""
19
+
20
+ __getattr__ = dict.get
21
+ __setattr__ = dict.__setitem__
22
+ __delattr__ = dict.__delitem__
23
+
24
+
25
+ class AMPLIFYConfig(PretrainedConfig):
26
+ model_type = "AMPLIFY"
27
+
28
+ # All config parameters must have a default value.
29
+ def __init__(
30
+ self,
31
+ hidden_size: int = 960,
32
+ num_hidden_layers: int = 32,
33
+ num_attention_heads: int = 15,
34
+ intermediate_size: int = 3840,
35
+ dropout_prob: float = 0,
36
+ embedding_init_range: float = 0.02,
37
+ decoder_init_range: float = 0.02,
38
+ rms_norm: bool = True,
39
+ norm_eps: float = 1e-05,
40
+ hidden_act: str = "SwiGLU",
41
+ layer_norm_after_embedding: bool = False,
42
+ layer_norm_before_last_layer: bool = True,
43
+ vocab_size: int = 27,
44
+ ffn_bias: bool = False,
45
+ att_bias: bool = False,
46
+ pad_token_id: int = 0,
47
+ max_length: int = 2048,
48
+ **kwargs,
49
+ ):
50
+ super().__init__(**kwargs)
51
+
52
+ self.hidden_size = hidden_size
53
+ self.num_hidden_layers = num_hidden_layers
54
+ self.num_attention_heads = num_attention_heads
55
+ self.intermediate_size = intermediate_size
56
+ self.dropout_prob = dropout_prob
57
+ self.embedding_init_range = embedding_init_range
58
+ self.decoder_init_range = decoder_init_range
59
+ self.rms_norm = rms_norm
60
+ self.norm_eps = norm_eps
61
+ self.hidden_act = hidden_act
62
+ self.layer_norm_after_embedding = layer_norm_after_embedding
63
+ self.layer_norm_before_last_layer = layer_norm_before_last_layer
64
+ self.vocab_size = vocab_size
65
+ self.ffn_bias = ffn_bias
66
+ self.att_bias = att_bias
67
+ self.pad_token_id = pad_token_id
68
+ self.max_length = max_length
69
+
70
+
71
+ class EncoderBlock(nn.Module):
72
+ """Transformer encoder block."""
73
+
74
+ def __init__(self, config: AMPLIFYConfig):
75
+ """Initialize a EncoderBlock.
76
+
77
+ Args:
78
+ hidden_size (int): _description_
79
+ num_attention_heads (int): _description_
80
+ intermediate_size (int, optional): _description_. Defaults to 2048.
81
+ dropout_prob (float, optional): _description_. Defaults to 0.1.
82
+ activation (str, optional): _description_. Defaults to "relu".
83
+ rms_norm (bool, optional): _description_. Defaults to True.
84
+ norm_eps (float, optional): _description_. Defaults to 1e-5.
85
+ pad_token_id (int, optional): _description_. Defaults to 0.
86
+ max_length (int, optional): _description_. Defaults to 2048.
87
+ ffn_bias (bool, optional): _description_. Defaults to False.
88
+ att_bias (bool, optional): _description_. Defaults to False.
89
+ """
90
+ super().__init__()
91
+
92
+ self.config = config
93
+ self.d_head = config.hidden_size // config.num_attention_heads
94
+
95
+ # Attention
96
+ self.q = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=config.att_bias)
97
+ self.k = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=config.att_bias)
98
+ self.v = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=config.att_bias)
99
+ self.wo = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=config.att_bias)
100
+ self.resid_dropout = nn.Dropout(config.dropout_prob)
101
+
102
+ # Feedforward network
103
+ match config.hidden_act.lower():
104
+ case "swiglu":
105
+ # To keep the number of parameters and the amount of computation constant, we reduce the number of
106
+ # hidden units by a factor of 2/3 (https://arxiv.org/pdf/2002.05202.pdf) and make it a multiple of 8 to
107
+ # avoid RuntimeError due to misaligned operand
108
+ multiple_of = 8
109
+ intermediate_size = int(2 * config.intermediate_size / 3)
110
+ intermediate_size = multiple_of * ((intermediate_size + multiple_of - 1) // multiple_of)
111
+ self.ffn = SwiGLU(config.hidden_size, intermediate_size, config.hidden_size, bias=config.ffn_bias)
112
+ case "relu":
113
+ self.ffn = nn.Sequential(
114
+ nn.Linear(config.hidden_size, config.intermediate_size, bias=config.ffn_bias),
115
+ nn.ReLU(),
116
+ nn.Linear(config.intermediate_size, config.hidden_size, bias=config.ffn_bias),
117
+ )
118
+ case "gelu":
119
+ self.ffn = nn.Sequential(
120
+ nn.Linear(config.hidden_size, config.intermediate_size, bias=config.ffn_bias),
121
+ nn.GELU(),
122
+ nn.Linear(config.intermediate_size, config.hidden_size, bias=config.ffn_bias),
123
+ )
124
+
125
+ self.attention_norm = (
126
+ RMSNorm(config.hidden_size, config.norm_eps)
127
+ if config.rms_norm
128
+ else nn.LayerNorm(config.hidden_size, config.norm_eps)
129
+ )
130
+ self.ffn_norm = (
131
+ RMSNorm(config.hidden_size, config.norm_eps)
132
+ if config.rms_norm
133
+ else nn.LayerNorm(config.hidden_size, config.norm_eps)
134
+ )
135
+
136
+ self.ffn_dropout = nn.Dropout(config.dropout_prob)
137
+
138
+ def forward(self, x: torch.Tensor, attention_mask: torch.Tensor, freqs_cis: torch.Tensor, output_attentions: bool):
139
+ attn, contact = self._att_block(self.attention_norm(x), attention_mask, freqs_cis, output_attentions)
140
+ x = x + attn
141
+ x = x + self._ff_block(self.ffn_norm(x))
142
+ return x, contact
143
+
144
+ def _att_block(
145
+ self, x: torch.Tensor, attention_mask: torch.Tensor, freqs_cis: torch.Tensor, output_attentions: bool
146
+ ):
147
+ batch_size, seq_len, _ = x.shape
148
+ xq, xk, xv = self.q(x), self.k(x), self.v(x)
149
+
150
+ # Reshape for rotary embeddings
151
+ xq = xq.view(batch_size, seq_len, self.config.num_attention_heads, self.d_head)
152
+ xk = xk.view(batch_size, seq_len, self.config.num_attention_heads, self.d_head)
153
+ xv = xv.view(batch_size, seq_len, self.config.num_attention_heads, self.d_head)
154
+ xq, xk = apply_rotary_emb(xq, xk, freqs_cis)
155
+
156
+ # Compute the attention weight
157
+ attn_weights = None
158
+ if output_attentions:
159
+ attn_weights = xq.permute(0, 2, 1, 3) @ xk.permute(0, 2, 3, 1) / (xq.size(-1) ** 0.5)
160
+ if attention_mask is not None:
161
+ attn_weights = attn_weights + attention_mask
162
+ attn_weights = attn_weights.softmax(-1)
163
+
164
+ # Compute the attention using xformers if the tensors are on GPU
165
+ if x.is_cuda:
166
+ # Input and output are of dimension (B, M, H, K) where B is the batch size, M the sequence length,
167
+ # H the number of heads, and K the embeding size per head
168
+ attn = memory_efficient_attention(
169
+ query=xq,
170
+ key=xk,
171
+ value=xv,
172
+ attn_bias=attention_mask,
173
+ p=self.config.dropout_prob if self.training else 0,
174
+ )
175
+ else:
176
+ # Input and output are of dimension (B, H, M, K)
177
+ attn = scaled_dot_product_attention(
178
+ query=xq.transpose(1, 2),
179
+ key=xk.transpose(1, 2),
180
+ value=xv.transpose(1, 2),
181
+ attn_mask=attention_mask,
182
+ dropout_p=self.config.dropout_prob if self.training else 0,
183
+ ).transpose(1, 2)
184
+
185
+ attn_scores = self.wo(attn.view(batch_size, seq_len, self.config.num_attention_heads * self.d_head))
186
+ return (self.resid_dropout(attn_scores), attn_weights)
187
+
188
+ def _ff_block(self, x: torch.Tensor):
189
+ return self.ffn_dropout(self.ffn(x))
190
+
191
+
192
+ class AMPLIFYPreTrainedModel(PreTrainedModel):
193
+ config_class = AMPLIFYConfig
194
+
195
+ def _init_weights(self, module):
196
+ if isinstance(module, nn.Linear):
197
+ module.weight.data.uniform_(-self.config.decoder_init_range, self.config.decoder_init_range)
198
+ if module.bias is not None:
199
+ module.bias.data.zero_()
200
+ elif isinstance(module, nn.Embedding):
201
+ module.weight.data.uniform_(-self.config.embedding_init_range, self.config.embedding_init_range)
202
+
203
+
204
+ class AMPLIFY(AMPLIFYPreTrainedModel):
205
+ """The main model class.
206
+
207
+ Args:
208
+ config (amplify.model.amplify.AMPLIFYConfig): model configuration, usually defined from the Hydra configuration.
209
+ """
210
+
211
+ def __init__(self, config: AMPLIFYConfig, **kwargs):
212
+ super().__init__(config)
213
+
214
+ self.config = config
215
+
216
+ self.encoder = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id)
217
+
218
+ if config.layer_norm_after_embedding:
219
+ self.layer_norm_1 = (
220
+ RMSNorm(config.hidden_size, config.norm_eps)
221
+ if config.rms_norm
222
+ else nn.LayerNorm(config.hidden_size, config.norm_eps)
223
+ )
224
+
225
+ self.transformer_encoder = nn.ModuleList()
226
+ for _ in range(config.num_hidden_layers):
227
+ self.transformer_encoder.append(EncoderBlock(config))
228
+
229
+ if config.layer_norm_before_last_layer:
230
+ self.layer_norm_2 = (
231
+ RMSNorm(config.hidden_size, config.norm_eps)
232
+ if config.rms_norm
233
+ else nn.LayerNorm(config.hidden_size, config.norm_eps)
234
+ )
235
+
236
+ self.decoder = nn.Linear(config.hidden_size, config.vocab_size)
237
+
238
+ self.freqs_cis = precompute_freqs_cis(config.hidden_size // config.num_attention_heads, config.max_length)
239
+
240
+ # Initialize weights and apply final processing
241
+ self.post_init()
242
+
243
+ def forward(self, input_ids, attention_mask=None, output_hidden_states=False, output_attentions=False, **kwargs):
244
+ # Initialize
245
+ hidden_states, attentions = [], []
246
+
247
+ # Expand and repeat: (Batch, Length) -> (Batch, Heads, Length, Length)
248
+ if attention_mask is not None and not torch.all(attention_mask == 0):
249
+ assert attention_mask.dtype != torch.bool and 1.0 not in attention_mask, (
250
+ "AMPLIFY expects an additive attention_mask.\n"
251
+ "Modify the output of the tokenizer with attention_mask = torch.where(attention_mask, float(0.0), float('-inf'))"
252
+ )
253
+ attention_mask = (
254
+ attention_mask.unsqueeze(1)
255
+ .unsqueeze(1)
256
+ .repeat(1, self.config.num_attention_heads, attention_mask.size(-1), 1)
257
+ )
258
+ else:
259
+ attention_mask = None
260
+
261
+ # RoPE
262
+ self.freqs_cis = self.freqs_cis.to(input_ids.device, non_blocking=True)
263
+ freqs_cis = self.freqs_cis[: input_ids.shape[1]]
264
+
265
+ # Embedding
266
+ x = self.encoder(input_ids)
267
+ if self.config.layer_norm_after_embedding:
268
+ x = self.layer_norm_1(x)
269
+
270
+ # Transformer encoder
271
+ for layer in self.transformer_encoder:
272
+ x, attn = layer(x, attention_mask, freqs_cis, output_attentions)
273
+ if output_hidden_states:
274
+ hidden_states.append(x)
275
+ if output_attentions:
276
+ attentions.append(attn)
277
+
278
+ # Classification head with layer norm
279
+ logits = self.decoder(self.layer_norm_2(x) if self.config.layer_norm_before_last_layer else x)
280
+
281
+ # Return logits or the output of the last hidden layer
282
+ return MaskedLMOutput(logits=logits, hidden_states=hidden_states, attentions=attentions)
data_raw/amplify/AMPLIFY_120M/config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_": "AMPLIFY",
3
+ "architectures": [
4
+ "AMPLIFY"
5
+ ],
6
+ "att_bias": false,
7
+ "auto_map": {
8
+ "AutoConfig": "amplify.AMPLIFYConfig",
9
+ "AutoModel": "amplify.AMPLIFY"
10
+ },
11
+ "bos_token_id": 3,
12
+ "decoder_init_range": 0.02,
13
+ "dropout_prob": 0,
14
+ "embedding_init_range": 0.02,
15
+ "eos_token_id": 4,
16
+ "ffn_bias": false,
17
+ "hidden_act": "SwiGLU",
18
+ "hidden_size": 640,
19
+ "intermediate_size": 2560,
20
+ "layer_norm_after_embedding": false,
21
+ "layer_norm_before_last_layer": true,
22
+ "mask_token_id": 2,
23
+ "max_length": 2048,
24
+ "model_type": "AMPLIFY",
25
+ "norm_eps": 1e-05,
26
+ "num_attention_heads": 10,
27
+ "num_hidden_layers": 24,
28
+ "other_special_token_ids": null,
29
+ "pad_token_id": 0,
30
+ "pre_activation_layer_norm": true,
31
+ "rms_norm": true,
32
+ "torch_dtype": "float32",
33
+ "transformers_version": "4.38.2",
34
+ "unk_token_id": 1,
35
+ "vocab_path": "conf/tokenizer/amplify_vocab.txt",
36
+ "vocab_size": 27
37
+ }
data_raw/amplify/AMPLIFY_120M/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a2375f1f54cbe00bdbe27eedcd039c92d12f165720c0349bc582a6eb42c099ce
3
+ size 473126988
data_raw/amplify/AMPLIFY_120M/rmsnorm.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import nn
3
+
4
+
5
+ class RMSNorm(nn.Module):
6
+ def __init__(self, dim: int, eps: float = 1e-6):
7
+ """
8
+ Initialize the RMSNorm normalization layer.
9
+ Args:
10
+ dim (int): The dimension of the input tensor.
11
+ eps (float, optional): A small value added to the denominator for numerical stability. Default is 1e-6.
12
+ Attributes:
13
+ eps (float): A small value added to the denominator for numerical stability.
14
+ weight (nn.Parameter): Learnable scaling parameter.
15
+ """
16
+ super().__init__()
17
+ self.eps = eps
18
+ self.weight = nn.Parameter(torch.ones(dim))
19
+
20
+ def _norm(self, x):
21
+ return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
22
+
23
+ def forward(self, x):
24
+ """
25
+ Forward pass through the RMSNorm layer.
26
+ Args:
27
+ x (torch.Tensor): The input tensor.
28
+ Returns:
29
+ torch.Tensor: The output tensor after applying RMSNorm.
30
+ """
31
+ output = self._norm(x.float()).type_as(x) # Avoids mixed precision issues as in https://github.com/chandar-lab/AMPLIFY/issues/19
32
+ return output * self.weight
data_raw/amplify/AMPLIFY_120M/rotary.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from typing import Tuple
3
+
4
+
5
+ def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0):
6
+ """
7
+ Precompute the frequency tensor for complex exponentials (cis) with given dimensions.
8
+
9
+ This function calculates a frequency tensor with complex exponentials using the given dimension 'dim'
10
+ and the end index 'end'. The 'theta' parameter scales the frequencies.
11
+ The returned tensor contains complex values in complex64 data type.
12
+
13
+ Args:
14
+ dim (int): Dimension of the frequency tensor.
15
+ end (int): End index for precomputing frequencies.
16
+ theta (float, optional): Scaling factor for frequency computation. Defaults to 10000.0.
17
+
18
+ Returns:
19
+ torch.Tensor: Precomputed frequency tensor with complex exponentials.
20
+ """
21
+
22
+ freqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim))
23
+ t = torch.arange(end, device=freqs.device) # type: ignore
24
+ freqs = torch.outer(t, freqs).float() # type: ignore
25
+ return torch.polar(torch.ones_like(freqs), freqs) # complex64
26
+
27
+
28
+ def reshape_for_broadcast(freqs_cis: torch.Tensor, x: torch.Tensor):
29
+ """
30
+ Reshape frequency tensor for broadcasting it with another tensor.
31
+
32
+ This function reshapes the frequency tensor to have the same shape as the target tensor 'x'
33
+ for the purpose of broadcasting the frequency tensor during element-wise operations.
34
+
35
+ Args:
36
+ freqs_cis (torch.Tensor): Frequency tensor to be reshaped.
37
+ x (torch.Tensor): Target tensor for broadcasting compatibility.
38
+
39
+ Returns:
40
+ torch.Tensor: Reshaped frequency tensor.
41
+
42
+ Raises:
43
+ AssertionError: If the frequency tensor doesn't match the expected shape.
44
+ AssertionError: If the target tensor 'x' doesn't have the expected number of dimensions.
45
+ """
46
+
47
+ ndim = x.ndim
48
+ assert 0 <= 1 < ndim
49
+ assert freqs_cis.shape == (x.shape[1], x.shape[-1])
50
+ shape = [d if i == 1 or i == ndim - 1 else 1 for i, d in enumerate(x.shape)]
51
+ return freqs_cis.view(*shape)
52
+
53
+
54
+ def apply_rotary_emb(
55
+ xq: torch.Tensor,
56
+ xk: torch.Tensor,
57
+ freqs_cis: torch.Tensor,
58
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
59
+ """
60
+ Apply rotary embeddings to input tensors using the given frequency tensor.
61
+
62
+ This function applies rotary embeddings to the given query 'xq' and key 'xk' tensors using the provided
63
+ frequency tensor 'freqs_cis'. The input tensors are reshaped as complex numbers, and the frequency tensor
64
+ is reshaped for broadcasting compatibility. The resulting tensors contain rotary embeddings and are
65
+ returned as real tensors.
66
+
67
+ Args:
68
+ xq (torch.Tensor): Query tensor to apply rotary embeddings.
69
+ xk (torch.Tensor): Key tensor to apply rotary embeddings.
70
+ freqs_cis (torch.Tensor): Precomputed frequency tensor for complex exponentials.
71
+
72
+ Returns:
73
+ Tuple[torch.Tensor, torch.Tensor]: Tuple of modified query tensor and key tensor with rotary embeddings.
74
+ """
75
+ xq_ = torch.view_as_complex(xq.float().reshape(*xq.shape[:-1], -1, 2))
76
+ xk_ = torch.view_as_complex(xk.float().reshape(*xk.shape[:-1], -1, 2))
77
+ freqs_cis = reshape_for_broadcast(freqs_cis, xq_)
78
+ xq_out = torch.view_as_real(xq_ * freqs_cis).flatten(3)
79
+ xk_out = torch.view_as_real(xk_ * freqs_cis).flatten(3)
80
+ return xq_out.type_as(xq), xk_out.type_as(xk)
data_raw/amplify/AMPLIFY_120M/special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<bos>",
3
+ "eos_token": "<eos>",
4
+ "mask_token": "<mask>",
5
+ "pad_token": "<pad>",
6
+ "unk_token": "<unk>"
7
+ }
data_raw/amplify/AMPLIFY_120M/tokenizer.json ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "1.0",
3
+ "truncation": null,
4
+ "padding": null,
5
+ "added_tokens": [
6
+ {
7
+ "id": 0,
8
+ "content": "<pad>",
9
+ "single_word": false,
10
+ "lstrip": false,
11
+ "rstrip": false,
12
+ "normalized": false,
13
+ "special": true
14
+ },
15
+ {
16
+ "id": 1,
17
+ "content": "<unk>",
18
+ "single_word": false,
19
+ "lstrip": false,
20
+ "rstrip": false,
21
+ "normalized": false,
22
+ "special": true
23
+ },
24
+ {
25
+ "id": 2,
26
+ "content": "<mask>",
27
+ "single_word": false,
28
+ "lstrip": false,
29
+ "rstrip": false,
30
+ "normalized": false,
31
+ "special": true
32
+ },
33
+ {
34
+ "id": 3,
35
+ "content": "<bos>",
36
+ "single_word": false,
37
+ "lstrip": false,
38
+ "rstrip": false,
39
+ "normalized": false,
40
+ "special": true
41
+ },
42
+ {
43
+ "id": 4,
44
+ "content": "<eos>",
45
+ "single_word": false,
46
+ "lstrip": false,
47
+ "rstrip": false,
48
+ "normalized": false,
49
+ "special": true
50
+ }
51
+ ],
52
+ "normalizer": null,
53
+ "pre_tokenizer": {
54
+ "type": "Split",
55
+ "pattern": {
56
+ "String": ""
57
+ },
58
+ "behavior": "Removed",
59
+ "invert": false
60
+ },
61
+ "post_processor": {
62
+ "type": "TemplateProcessing",
63
+ "single": [
64
+ {
65
+ "SpecialToken": {
66
+ "id": "<bos>",
67
+ "type_id": 0
68
+ }
69
+ },
70
+ {
71
+ "Sequence": {
72
+ "id": "A",
73
+ "type_id": 0
74
+ }
75
+ },
76
+ {
77
+ "SpecialToken": {
78
+ "id": "<eos>",
79
+ "type_id": 0
80
+ }
81
+ }
82
+ ],
83
+ "pair": [
84
+ {
85
+ "Sequence": {
86
+ "id": "A",
87
+ "type_id": 0
88
+ }
89
+ },
90
+ {
91
+ "Sequence": {
92
+ "id": "B",
93
+ "type_id": 1
94
+ }
95
+ }
96
+ ],
97
+ "special_tokens": {
98
+ "<bos>": {
99
+ "id": "<bos>",
100
+ "ids": [
101
+ 3
102
+ ],
103
+ "tokens": [
104
+ "<bos>"
105
+ ]
106
+ },
107
+ "<eos>": {
108
+ "id": "<eos>",
109
+ "ids": [
110
+ 4
111
+ ],
112
+ "tokens": [
113
+ "<eos>"
114
+ ]
115
+ }
116
+ }
117
+ },
118
+ "decoder": null,
119
+ "model": {
120
+ "type": "WordPiece",
121
+ "unk_token": "<unk>",
122
+ "continuing_subword_prefix": "##",
123
+ "max_input_chars_per_word": 100,
124
+ "vocab": {
125
+ "<pad>": 0,
126
+ "<unk>": 1,
127
+ "<mask>": 2,
128
+ "<bos>": 3,
129
+ "<eos>": 4,
130
+ "|": 5,
131
+ "L": 6,
132
+ "A": 7,
133
+ "G": 8,
134
+ "V": 9,
135
+ "S": 10,
136
+ "E": 11,
137
+ "R": 12,
138
+ "T": 13,
139
+ "I": 14,
140
+ "D": 15,
141
+ "P": 16,
142
+ "K": 17,
143
+ "Q": 18,
144
+ "N": 19,
145
+ "F": 20,
146
+ "Y": 21,
147
+ "M": 22,
148
+ "H": 23,
149
+ "W": 24,
150
+ "C": 25,
151
+ "B": 26
152
+ }
153
+ }
154
+ }
data_raw/amplify/AMPLIFY_120M/tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<pad>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<unk>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "<mask>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<bos>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "4": {
36
+ "content": "<eos>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "<bos>",
45
+ "clean_up_tokenization_spaces": true,
46
+ "eos_token": "<eos>",
47
+ "mask_token": "<mask>",
48
+ "model_input_names": [
49
+ "input_ids",
50
+ "attention_mask"
51
+ ],
52
+ "model_max_length": 2048,
53
+ "pad_token": "<pad>",
54
+ "padding_side": "right",
55
+ "tokenizer_class": "PreTrainedTokenizerFast",
56
+ "truncation_side": "right",
57
+ "unk_token": "<unk>"
58
+ }
data_raw/clinvar/variant_summary.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5fe4fe10783391d01dc414dc5583a3e63487b67f8cd3c8429d59227cd5f4f37f
3
+ size 439962524
data_raw/doid/doid.obo ADDED
The diff for this file is too large to render. See raw diff
 
data_raw/mutation_ppi_external/intact/mutations.tsv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fb9438fe5686c2099afde0349b4e167c5ff5a6a8c1e861c5b95f4c041b963bd
3
+ size 33615072
data_raw/mutation_ppi_external/skempi2/skempi_v2.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data_raw/protein_complex_external/complexportal/9606.tsv ADDED
The diff for this file is too large to render. See raw diff
 
data_raw/protein_complex_external/complexportal/COMPLEXPORTAL_UPLOAD_VERIFIED.flag ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ COMPLEXPORTAL_UPLOAD_VERIFIED=true
2
+ file=9606.tsv
3
+ sha256=29d3aeec7ede35e8686de3cf73620b5871c3e68d7ca069385153a9b28e80012a
4
+ size_bytes=5292514
5
+ rows=2499
6
+ parseable=true
data_raw/protein_complex_external/complexportal/CURATED_COMPLEXPORTAL_CONFIRMED.flag ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ CURATED_COMPLEXPORTAL_CONFIRMED=true
2
+ source=EMBL-EBI Complex Portal
3
+ species=Homo sapiens
4
+ taxonomy=9606
5
+ format=ComplexTAB
6
+ dataset=curated
7
+ file=9606.tsv
8
+ predicted_file_used=false
data_raw/protein_complex_external/complexportal/LOCAL_DOWNLOAD_MANIFEST.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ Working directory: /Users/zhangchris/Desktop/bio/protein_complex_ground_truth_tmp/complexportal
2
+ File: 9606.tsv
3
+ Size bytes: 5292514
4
+ Rows: 2499
5
+ SHA256: 29d3aeec7ede35e8686de3cf73620b5871c3e68d7ca069385153a9b28e80012
6
+ Source SHA256: 4c2b1c3e0a7ac2d8635d17e8c77dc786504dfaa81d94a8618f3131dee2a4155b
7
+ Downloaded: 2026-08-09 10:18:22 +0800
data_raw/protein_complex_external/complexportal/SHA256_9606_LOCAL.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ 29d3aeec7ede35e8686de3cf73620b5871c3e68d7ca069385153a9b28e80012 9606.tsv
2
+ 4c2b1c3e0a7ac2d8635d17e8c77dc786504dfaa81d94a8618f3131dee2a4155b SOURCE.txt
data_raw/protein_complex_external/complexportal/SHA256_9606_REMOTE.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ 29d3aeec7ede35e8686de3cf73620b5871c3e68d7ca069385153a9b28e80012a 9606.tsv
2
+ 4c2b1c3e0a7ac2d8635d17e8c77dc786504dfaa81d94a8618f3131dee2a4155b SOURCE.txt
data_raw/protein_complex_external/complexportal/SOURCE.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ Source: EMBL-EBI Complex Portal
2
+ Species: Homo sapiens
3
+ NCBI Taxonomy ID: 9606
4
+ Format: ComplexTAB
5
+ Dataset type: curated protein complexes
6
+ File: 9606.tsv
7
+ Official URL: https://ftp.ebi.ac.uk/pub/databases/intact/complex/current/complextab/9606.tsv
8
+ Download date: 2026-08-09
9
+ Purpose: independent curated human protein-complex ground truth for AMPLIFY Protein Complex Discovery
data_raw/protein_complex_external/complexportal/UPLOAD_VERIFICATION.tsv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ file local_sha256 remote_sha256 sha_match local_size remote_size size_match remote_rows parseable status
2
+ 9606.tsv 29d3aeec7ede35e8686de3cf73620b5871c3e68d7ca069385153a9b28e80012a 29d3aeec7ede35e8686de3cf73620b5871c3e68d7ca069385153a9b28e80012a true 5292514 5292514 true 2499 true PASS
data_raw/ptmd/Acetylation.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a9d9b38109a67c2b973518aa908ed0c208170b5fceda4a6f9610a220470f450e
3
+ size 289805
data_raw/ptmd/Phosphorylation.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45b4ee60010b200fe43e858da58bd11dc835b88792d3c473d2b4ca03a4cd1702
3
+ size 2902073
data_raw/ptmd/Ubiquitination.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:27abd012c5f95c4cf903b706c50ca5a844bd53636f033fb0ec2d9a900174141d
3
+ size 1391723
data_raw/ptmd/unzipped/PTMD2_Acetylation.csv ADDED
The diff for this file is too large to render. See raw diff
 
data_raw/ptmd/unzipped/PTMD2_Phosphorylation.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:742f88903eeec1bc777735363740b9a1262d7fae9a5f4dacbb2c8ff5a5f24597
3
+ size 24376657
data_raw/ptmd/unzipped/PTMD2_Ubiquitination.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:073072b0950dd4971b65c463ba48cb6b0be4c397c64d1e5269e4bcbe6f68d55e
3
+ size 11268104
data_raw/ptmint/PTM experimental evidence.csv ADDED
The diff for this file is too large to render. See raw diff
 
data_raw/ptmint/SHA256SUMS.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ 4cd357c9558c015ec87c2c1c186329ae4d4f3c0b8892b0d5808cf07114f1e0c4 PTM experimental evidence.csv
data_raw/ptmint/SOURCE_URL.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ Official database: https://ptmint.sjtu.edu.cn/
2
+ Official download page: https://ptmint.sjtu.edu.cn/Download
3
+ Direct file URL: https://ptmint.sjtu.edu.cn/data/PTM%20experimental%20evidence.csv
4
+ Downloaded: 2026-08-01 Asia/Shanghai
data_raw/reactome/ReactomePathways.txt ADDED
The diff for this file is too large to render. See raw diff
 
data_raw/reactome/ReactomePathwaysRelation.txt ADDED
The diff for this file is too large to render. See raw diff
 
data_raw/reactome/UniProt2Reactome_All_Levels.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d2347cb04d1432f170ee0319283bd6314282909341488e9c33dc85aef663c68a
3
+ size 117823518
data_raw/uniprot/UP000005640_9606.fasta.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf49a88c4812dabbd934cb3e2e00b449e70375816e4d47cda7cc5b77b0754024
3
+ size 7752225
data_raw/uniprot/UP000005640_9606_isoforms.fasta.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99c554687a490cca08d97bc2a9d17e1528b446531a19ad6be97d4deaa883cae2
3
+ size 43831972
data_raw/uniprot/uniprot_sprot_human.dat.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a909f65ba620f9ca477671e1c681a605f82658f75567bcf6707cb92b765cf242
3
+ size 119315692