fmilletari-czi commited on
Commit
0c9625d
·
verified ·
1 Parent(s): a59b831

Upload folder using huggingface_hub

Browse files
config.json CHANGED
@@ -1,17 +1,38 @@
1
  {
2
  "architectures": [
3
- "ESMCForMaskedLM"
4
  ],
 
 
 
 
 
 
 
 
 
 
5
  "classifier_dropout": 0.1,
6
- "d_model": 960,
7
  "dtype": "float32",
 
 
 
 
8
  "initializer_range": 0.02,
 
9
  "mask_token_id": 32,
 
 
10
  "model_type": "esmc",
11
- "n_heads": 15,
12
- "n_layers": 30,
 
13
  "pad_token_id": 1,
 
 
 
 
14
  "tie_word_embeddings": false,
15
- "transformers_version": "4.57.6",
16
  "vocab_size": 64
17
  }
 
1
  {
2
  "architectures": [
3
+ "EsmcForMaskedLM"
4
  ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "modeling_esmc_remote.EsmcRemoteConfig",
9
+ "AutoModel": "modeling_esmc_remote.EsmcRemoteModel",
10
+ "AutoModelForMaskedLM": "modeling_esmc_remote.EsmcRemoteForMaskedLM",
11
+ "AutoModelForSequenceClassification": "modeling_esmc_remote.EsmcRemoteForSequenceClassification",
12
+ "AutoModelForTokenClassification": "modeling_esmc_remote.EsmcRemoteForTokenClassification"
13
+ },
14
+ "bos_token_id": 0,
15
  "classifier_dropout": 0.1,
 
16
  "dtype": "float32",
17
+ "eos_token_id": 2,
18
+ "head_dim": 64,
19
+ "hidden_act": "silu",
20
+ "hidden_size": 960,
21
  "initializer_range": 0.02,
22
+ "intermediate_size": 2560,
23
  "mask_token_id": 32,
24
+ "max_position_embeddings": 2048,
25
+ "mlp_bias": false,
26
  "model_type": "esmc",
27
+ "num_attention_heads": 15,
28
+ "num_hidden_layers": 30,
29
+ "num_key_value_heads": 15,
30
  "pad_token_id": 1,
31
+ "rope_parameters": {
32
+ "rope_theta": 10000.0,
33
+ "rope_type": "default"
34
+ },
35
  "tie_word_embeddings": false,
36
+ "transformers_version": "5.16.0.dev0",
37
  "vocab_size": 64
38
  }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0772d8fe64bb25e14fe6f23b80e3c9a7d215d0da3c6cba5bd356d7c0e0bb22cc
3
- size 1332036392
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b06a03aa359c29a889151da4a07a517f2c307c1fcc61c8b767ec5360dd40cb49
3
+ size 1332032536
modeling_esmc_remote.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Load this checkpoint with the ``esm`` package instead of the transformers port.
2
+
3
+ Shipped inside each ``biohub/ESMC-*`` repo and named by its ``config.json``
4
+ ``auto_map``, so ``AutoModel.from_pretrained(repo, trust_remote_code=True)``
5
+ returns an ``esm.models.esmc`` model. Without the flag transformers keeps using
6
+ its own port, which it has shipped since 5.x.
7
+
8
+ One shim class per Auto class transformers maps for ``esmc``. Dropping any of
9
+ them would break that Auto class on this repo: ``AutoConfig`` resolves to
10
+ :class:`EsmcRemoteConfig`, which is in none of transformers' own mappings.
11
+
12
+ Runs from the Hub module cache in the user's environment, so it imports nothing
13
+ but ``transformers``, ``packaging`` and ``esm``. The ESMFold2 loader is a
14
+ separate file for the same reason -- each repo downloads one module, so there is
15
+ nowhere to share code from.
16
+ """
17
+
18
+ from typing import Any
19
+
20
+ from packaging.version import Version
21
+ from transformers.configuration_utils import PretrainedConfig
22
+ from transformers.modeling_utils import PreTrainedModel
23
+
24
+ #: Inclusive floor. 3.4.0 reads the published layout but takes no config
25
+ #: overrides, so it would silently ignore a ``num_labels`` on a head load.
26
+ MIN_ESM_VERSION = "3.4.1"
27
+
28
+ #: The keyword arguments esm's ESMC ``from_pretrained`` declares.
29
+ _ESM_KWARGS = frozenset(
30
+ {
31
+ "device",
32
+ "dtype",
33
+ "attn_implementation",
34
+ "revision",
35
+ "cache_dir",
36
+ "token",
37
+ "local_files_only",
38
+ "force_download",
39
+ }
40
+ )
41
+
42
+
43
+ def esmc_class(name: str) -> Any:
44
+ """Return a class from ``esm.models.esmc``, or raise ``ImportError``.
45
+
46
+ The message names the pip command; a bare ImportError out of the Hub module
47
+ loader would not.
48
+ """
49
+ try:
50
+ import esm
51
+ from esm.models import esmc
52
+ except ImportError as exc:
53
+ raise ImportError(
54
+ f"trust_remote_code=True runs the esm package, which failed to "
55
+ f"import ({exc}). Install it with:\n\n"
56
+ f" pip install 'esm>={MIN_ESM_VERSION}'\n\n"
57
+ "Or drop the flag to use the ESMC port in transformers."
58
+ ) from exc
59
+ if Version(esm.__version__) < Version(MIN_ESM_VERSION):
60
+ raise ImportError(
61
+ f"esm {esm.__version__} is installed, but this checkpoint needs "
62
+ f"{MIN_ESM_VERSION} or newer. Upgrade with:\n\n"
63
+ f" pip install --upgrade 'esm>={MIN_ESM_VERSION}'"
64
+ )
65
+ return getattr(esmc, name)
66
+
67
+
68
+ class EsmcRemoteConfig(PretrainedConfig):
69
+ """Holds config.json verbatim. esm re-reads the file and builds its own config."""
70
+
71
+ model_type = "esmc"
72
+
73
+
74
+ class _EsmcRemoteLoader(PreTrainedModel):
75
+ """Loader shim; ``from_pretrained`` returns an esm model, not one of these.
76
+
77
+ A ``PreTrainedModel`` subclass only because the Auto classes call
78
+ ``register_for_auto_class`` on what they load and check its ``config_class``.
79
+ """
80
+
81
+ config_class = EsmcRemoteConfig
82
+
83
+ #: The ``esm.models.esmc`` class this shim loads.
84
+ esm_class_name = "EsmcModel"
85
+
86
+ #: esm keyword -> config attribute. transformers absorbs these into
87
+ #: ``config`` before the model sees them, so
88
+ #: ``AutoModel(..., attn_implementation="flash_attention_2")`` never
89
+ #: reaches us as a keyword. Read back off that config instead of dropped.
90
+ esm_config_fields: dict[str, str] = {"attn_implementation": "_attn_implementation"}
91
+
92
+ @classmethod
93
+ def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs): # type: ignore[override]
94
+ # esm's signature is fixed, so transformers' trust_remote_code /
95
+ # _from_auto / config would TypeError.
96
+ forwarded = {k: v for k, v in kwargs.items() if k in _ESM_KWARGS}
97
+ config = kwargs.get("config")
98
+ for keyword, attribute in cls.esm_config_fields.items():
99
+ value = getattr(config, attribute, None)
100
+ if value is not None:
101
+ forwarded.setdefault(keyword, value)
102
+ return esmc_class(cls.esm_class_name).from_pretrained(
103
+ pretrained_model_name_or_path, *args, **forwarded
104
+ )
105
+
106
+
107
+ class EsmcRemoteModel(_EsmcRemoteLoader):
108
+ """``AutoModel`` -- the bare encoder."""
109
+
110
+ esm_class_name = "EsmcModel"
111
+
112
+
113
+ class EsmcRemoteForMaskedLM(_EsmcRemoteLoader):
114
+ """``AutoModelForMaskedLM`` -- the encoder plus the published LM head."""
115
+
116
+ esm_class_name = "EsmcForMaskedLM"
117
+
118
+
119
+ #: A head load also has to carry the shape of the head, which transformers
120
+ #: takes as ``num_labels`` and resolves against ``id2label``.
121
+ _HEAD_FIELDS = {
122
+ **_EsmcRemoteLoader.esm_config_fields,
123
+ "num_labels": "num_labels",
124
+ "problem_type": "problem_type",
125
+ "classifier_dropout": "classifier_dropout",
126
+ }
127
+
128
+
129
+ class EsmcRemoteForSequenceClassification(_EsmcRemoteLoader):
130
+ """``AutoModelForSequenceClassification`` -- head is randomly initialised."""
131
+
132
+ esm_class_name = "EsmcForSequenceClassification"
133
+ esm_config_fields = _HEAD_FIELDS
134
+
135
+
136
+ class EsmcRemoteForTokenClassification(_EsmcRemoteLoader):
137
+ """``AutoModelForTokenClassification`` -- head is randomly initialised."""
138
+
139
+ esm_class_name = "EsmcForTokenClassification"
140
+ esm_config_fields = _HEAD_FIELDS
tokenizer_config.json CHANGED
@@ -1,65 +1,13 @@
1
  {
2
- "added_tokens_decoder": {
3
- "0": {
4
- "content": "<cls>",
5
- "lstrip": false,
6
- "normalized": false,
7
- "rstrip": false,
8
- "single_word": false,
9
- "special": true
10
- },
11
- "1": {
12
- "content": "<pad>",
13
- "lstrip": false,
14
- "normalized": false,
15
- "rstrip": false,
16
- "single_word": false,
17
- "special": true
18
- },
19
- "2": {
20
- "content": "<eos>",
21
- "lstrip": false,
22
- "normalized": false,
23
- "rstrip": false,
24
- "single_word": false,
25
- "special": true
26
- },
27
- "3": {
28
- "content": "<unk>",
29
- "lstrip": false,
30
- "normalized": false,
31
- "rstrip": false,
32
- "single_word": false,
33
- "special": true
34
- },
35
- "31": {
36
- "content": "|",
37
- "lstrip": false,
38
- "normalized": false,
39
- "rstrip": false,
40
- "single_word": false,
41
- "special": true
42
- },
43
- "32": {
44
- "content": "<mask>",
45
- "lstrip": false,
46
- "normalized": false,
47
- "rstrip": false,
48
- "single_word": false,
49
- "special": true
50
- }
51
- },
52
- "additional_special_tokens": [
53
- "|"
54
- ],
55
  "bos_token": "<cls>",
56
- "clean_up_tokenization_spaces": false,
57
  "cls_token": "<cls>",
58
  "eos_token": "<eos>",
59
- "extra_special_tokens": {},
60
  "mask_token": "<mask>",
61
  "model_max_length": 1000000000000000019884624838656,
62
  "pad_token": "<pad>",
63
- "tokenizer_class": "ESMCTokenizer",
64
  "unk_token": "<unk>"
65
  }
 
1
  {
2
+ "backend": "tokenizers",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  "bos_token": "<cls>",
4
+ "chain_break_token": "|",
5
  "cls_token": "<cls>",
6
  "eos_token": "<eos>",
7
+ "extra_special_tokens": [],
8
  "mask_token": "<mask>",
9
  "model_max_length": 1000000000000000019884624838656,
10
  "pad_token": "<pad>",
11
+ "tokenizer_class": "EsmcTokenizer",
12
  "unk_token": "<unk>"
13
  }