MCPcopy Create free account
hub / github.com/AnswerDotAI/ModernBERT / create_flex_bert_mlm

Function create_flex_bert_mlm

src/flex_bert.py:174–312  ·  view source on GitHub ↗

FlexBERT masked language model based on |:hugging_face:| Transformers. For more information, see `Transformers. `_. This function creates a FlexBERT, which includes several throughput optimizations not available in |:hugging_face:| BERT as well

(
    pretrained_model_name: str = "bert-base-uncased",
    model_config: Optional[dict] = None,
    tokenizer_name: Optional[str] = None,
    gradient_checkpointing: Optional[bool] = False,
    pretrained_checkpoint: Optional[str] = None,
    recompute_metric_loss: Optional[bool] = False,
    disable_train_metrics: Optional[bool] = False,
)

Source from the content-addressed store, hash-verified

172
173
174def create_flex_bert_mlm(
175 pretrained_model_name: str = "bert-base-uncased",
176 model_config: Optional[dict] = None,
177 tokenizer_name: Optional[str] = None,
178 gradient_checkpointing: Optional[bool] = False,
179 pretrained_checkpoint: Optional[str] = None,
180 recompute_metric_loss: Optional[bool] = False,
181 disable_train_metrics: Optional[bool] = False,
182):
183 """FlexBERT masked language model based on |:hugging_face:| Transformers.
184
185 For more information, see
186 `Transformers. <https://huggingface.co/transformers/>`_.
187
188 This function creates a FlexBERT, which includes several throughput
189 optimizations not available in |:hugging_face:| BERT as well as
190 architecture changes based on ALiBi and Gated Linear Units.
191
192 Args:
193 pretrained_model_name (str): Name of the Hugging Face model to
194 instantiate. This will determine the default model configuration.
195 Default: ``bert-base-uncased``.
196 model_config (dict): A dictionary of user-specified configurations to
197 update/add to the default model configuration.
198 tokenizer_name (str, optional): Tokenizer name used to preprocess the
199 dataset and validate the models inputs.
200 gradient_checkpointing (bool, optional): Use gradient checkpointing.
201 Default: ``False``.
202 pretrained_checkpoint (str, optional): The pretrained checkpoint to
203 initialize the model weights. If provided, the state dictionary
204 stored at `pretrained_checkpoint` will be loaded into the model
205 after initialization. Default: ``None``.
206 disable_train_metrics (bool, optional): Only calculate metrics for
207 validation set when True.
208 Default: ``False``.
209
210 .. code-block::
211
212 {
213 "_name_or_path": "bert-base-uncased",
214 "alibi_starting_size": 512,
215 "architectures": ["BertForMaskedLM"],
216 "attention_probs_dropout_prob": 0.0,
217 "classifier_dropout": null,
218 "gradient_checkpointing": false,
219 "hidden_act": "silu",
220 "hidden_dropout_prob": 0.1,
221 "hidden_size": 768,
222 "initializer_range": 0.02,
223 "intermediate_size": 3072,
224 "layer_norm_eps": 1e-12,
225 "max_position_embeddings": 512,
226 "model_type": "bert",
227 "num_attention_heads": 12,
228 "num_hidden_layers": 12,
229 "pad_token_id": 0,
230 "position_embedding_type": "absolute",
231 "transformers_version": "4.16.0",

Callers

nothing calls this directly

Calls 5

EfficientZLossClass · 0.85
from_composerMethod · 0.45

Tested by

no test coverage detected