Run this model with HF Jobs
Run jinaai/jina-bert-flash-implementation on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/jinaai/jina-bert-flash-implementation. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/jinaai/jina-bert-flash-implementation on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use jinaai/jina-bert-flash-implementation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jinaai/jina-bert-flash-implementation with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("jinaai/jina-bert-flash-implementation", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
feat: added selective activation checkpointing
Browse filesFiles changed (2)
- configuration_bert.py+20-1
- modeling_bert.py+12-8
54 unmodified lines55565758596025 unmodified lines8687888990913 unmodified lines959697989910017 unmodified lines11811912012154 unmodified lineslayer_norm_eps (`float`, *optional*, defaults to 1e-12):The epsilon used by the layer normalization layers.window_size (`tuple`, *optional*, defaults to `(-1, -1)`): If not the default, use local attention"""model_type = "bert"25 unmodified linesemb_pooler=None,classifier_dropout=None,num_loras=5,**kwargs,):assert 'position_embedding_type' not in kwargs3 unmodified linesif mlp_type == 'fused_mlp' and hidden_act not in ["gelu_new", "gelu_fast", "gelu_pytorch_tanh"]:raise ValueError('Fused MLP only supports approximate gelu')self.vocab_size = vocab_sizeself.hidden_size = hidden_sizeself.num_hidden_layers = num_hidden_layers17 unmodified linesself.use_qk_norm = use_qk_normself.emb_pooler = emb_poolerself.classifier_dropout = classifier_dropoutself.num_loras = num_loras54 unmodified lines55565758596061626325 unmodified lines899091929394953 unmodified lines9910010110210310410510610710810911011111211311411511611711817 unmodified lines13613713813914054 unmodified lineslayer_norm_eps (`float`, *optional*, defaults to 1e-12):The epsilon used by the layer normalization layers.window_size (`tuple`, *optional*, defaults to `(-1, -1)`): If not the default, use local attentionactivation_checkpoint_lvl (`int`, *optional*, defaults to `0`): How many layers to activation-checkpoint.If larger than 0, the MLP activation checkpointing level is expected to be 0 for the first`activation_checkpoint_lvl` layers."""model_type = "bert"25 unmodified linesemb_pooler=None,classifier_dropout=None,num_loras=5,activation_checkpoint_lvl=0,**kwargs,):assert 'position_embedding_type' not in kwargs3 unmodified linesif mlp_type == 'fused_mlp' and hidden_act not in ["gelu_new", "gelu_fast", "gelu_pytorch_tanh"]:raise ValueError('Fused MLP only supports approximate gelu')if mlp_checkpoint_lvl != 0 and mlp_type != 'fused_mlp':raise ValueError('MLP checkpointing only available for `fused_mlp`')if activation_checkpoint_lvl > 0 and isinstance(mlp_checkpoint_lvl, int) and mlp_checkpoint_lvl > 0:raise ValueError('Trying to use layer-wise activation checkpointing and MLP-checkpointing ''in every layer simultaneously. Either only use one of the techniques, ''or specify layer-wise MLP checkpointing.')elif activation_checkpoint_lvl > 0 and mlp_checkpoint_lvl > 0:for layer_idx, mlp_lvl in enumerate(mlp_checkpoint_lvl):if layer_idx < activation_checkpoint_lvl and mlp_lvl > 0:raise ValueError(f'Layer {layer_idx} is being checkpointed as a whole and its MLP 'f'is being checkpointed. Either remove MLP checkpointing for this layer 'f'or reduce the `activation_checkpoint_lvl` appropriately')self.vocab_size = vocab_sizeself.hidden_size = hidden_sizeself.num_hidden_layers = num_hidden_layers17 unmodified linesself.use_qk_norm = use_qk_normself.emb_pooler = emb_poolerself.classifier_dropout = classifier_dropoutself.num_loras = num_lorasself.activation_checkpoint_lvl = activation_checkpoint_lvl
179 unmodified lines1801811821831841851861871881891901911925 unmodified lines19819920020120220320420511 unmodified lines2172182192202212222232244 unmodified lines22923023123223323423523627 unmodified lines264265266267268269270179 unmodified lines[create_block(config, layer_idx=i) for i in range(config.num_hidden_layers)])self._grad_checkpointing = False@propertydef gradient_checkpointing(self):return self._grad_checkpointing@gradient_checkpointing.setterdef gradient_checkpointing(self, value):self._grad_checkpointing = valuedef forward(self, hidden_states, key_padding_mask=None, subset_mask=None):5 unmodified linesmixer_kwargs = ({"key_padding_mask": key_padding_mask.bool()} if key_padding_mask is not None else None)for layer in self.layers:if self._grad_checkpointing:hidden_states = torch.utils.checkpoint.checkpoint(layer,hidden_states,11 unmodified lines)mixer_kwargs = {"cu_seqlens": cu_seqlens, "max_seqlen": max_seqlen_in_batch}if subset_mask is None:for layer in self.layers:if self._grad_checkpointing:hidden_states = torch.utils.checkpoint.checkpoint(layer,hidden_states,4 unmodified lineshidden_states = layer(hidden_states, mixer_kwargs=mixer_kwargs)hidden_states = pad_input(hidden_states, indices, batch, seqlen)else:for layer in self.layers[:-1]:if self._grad_checkpointing:hidden_states = torch.utils.checkpoint.checkpoint(layer,hidden_states,27 unmodified lines"cu_seqlens_k": cu_seqlens,"max_seqlen_k": max_seqlen_in_batch,}if self._grad_checkpointing:torch.utils.checkpoint.checkpoint(self.layers[-1],hidden_states_subset,179 unmodified lines1801811821831841851861871881891901911921931941951965 unmodified lines20220320420520620720820911 unmodified lines2212222232242252262272284 unmodified lines23323423523623723823924027 unmodified lines268269270271272273274179 unmodified lines[create_block(config, layer_idx=i) for i in range(config.num_hidden_layers)])self._grad_checkpointing = Falseself._num_checkpointed_layers = config.activation_checkpoint_lvl@propertydef gradient_checkpointing(self):return self._grad_checkpointing@gradient_checkpointing.setterdef gradient_checkpointing(self, value: bool):if value and self._num_checkpointed_layers <= 0:raise ValueError('Trying to use activation checkpointing, but `activation_checkpoint_lvl`''is set to zero.')self._grad_checkpointing = valuedef forward(self, hidden_states, key_padding_mask=None, subset_mask=None):5 unmodified linesmixer_kwargs = ({"key_padding_mask": key_padding_mask.bool()} if key_padding_mask is not None else None)for idx, layer in enumerate(self.layers):if self._grad_checkpointing and idx < self._num_checkpointed_layers:hidden_states = torch.utils.checkpoint.checkpoint(layer,hidden_states,11 unmodified lines)mixer_kwargs = {"cu_seqlens": cu_seqlens, "max_seqlen": max_seqlen_in_batch}if subset_mask is None:for idx, layer in enumerate(self.layers):if self._grad_checkpointing and idx < self._num_checkpointed_layers:hidden_states = torch.utils.checkpoint.checkpoint(layer,hidden_states,4 unmodified lineshidden_states = layer(hidden_states, mixer_kwargs=mixer_kwargs)hidden_states = pad_input(hidden_states, indices, batch, seqlen)else:for idx, layer in enumerate(self.layers[:-1]):if self._grad_checkpointing and idx < self._num_checkpointed_layers:hidden_states = torch.utils.checkpoint.checkpoint(layer,hidden_states,27 unmodified lines"cu_seqlens_k": cu_seqlens,"max_seqlen_k": max_seqlen_in_batch,}if self._grad_checkpointing and len(self.layers) <= self._num_checkpointed_layers:torch.utils.checkpoint.checkpoint(self.layers[-1],hidden_states_subset,
configuration_bert.py+20-1
modeling_bert.py+12-8