code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Create a mask from the two sequences passed to be used in a sequence-pair classification task. A LayoutLM sequence pair mask has the following format: ...
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A LayoutLM sequence pair mask has the following format: ``` 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 | first sequence | second sequence | ``` If `token_ids_1` is `N...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlm/tokenization_layoutlm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlm/tokenization_layoutlm.py
Apache-2.0
def apply_tesseract(image: Image.Image, lang: Optional[str], tesseract_config: Optional[str]): """Applies Tesseract OCR on a document image, and returns recognized words + normalized bounding boxes.""" # apply OCR data = pytesseract.image_to_data(image, lang=lang, output_type="dict", config=tesseract_confi...
Applies Tesseract OCR on a document image, and returns recognized words + normalized bounding boxes.
apply_tesseract
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/feature_extraction_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/feature_extraction_layoutlmv2.py
Apache-2.0
def __call__( self, images: ImageInput, return_tensors: Optional[Union[str, TensorType]] = None, **kwargs ) -> BatchFeature: """ Main method to prepare for the model one or several image(s). Args: images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.I...
Main method to prepare for the model one or several image(s). Args: images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`): The image or batch of images to be prepared. Each image can be a PIL image, NumPy...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/feature_extraction_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/feature_extraction_layoutlmv2.py
Apache-2.0
def relative_position_bucket(relative_position, bidirectional=True, num_buckets=32, max_distance=128): """ Adapted from Mesh Tensorflow: https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593 Translate relative position to ...
Adapted from Mesh Tensorflow: https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593 Translate relative position to a bucket number for relative attention. The relative position is defined as memory_position - query_positi...
relative_position_bucket
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, bbox: Optional[torch.LongTensor] = None, image: Optional[torch.FloatTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids...
Return: Examples: ```python >>> from transformers import LayoutLMv2Processor, LayoutLMv2Model, set_seed >>> from PIL import Image >>> import torch >>> from datasets import load_dataset >>> set_seed(88) >>> processor = LayoutLMv2Processor.from_...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, bbox: Optional[torch.LongTensor] = None, image: Optional[torch.FloatTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the sequence classification/regression loss. Indices should be in `[0, ..., config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If `confi...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, bbox: Optional[torch.LongTensor] = None, image: Optional[torch.FloatTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids...
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`. Returns: Example: ```python >>> from transformers import LayoutLMv2Process...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, bbox: Optional[torch.LongTensor] = None, image: Optional[torch.FloatTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids...
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for position (index) of the start of the labelled span for computing the token classification loss. Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
Apache-2.0
def __call__( self, images, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None, text_pair: Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None, boxes: Union[List[List[int]], List[List[List[int]]]] = None, word_labels:...
This method first forwards the `images` argument to [`~LayoutLMv2FeatureExtractor.__call__`]. In case [`LayoutLMv2FeatureExtractor`] was initialized with `apply_ocr` set to `True`, it passes the obtained words and bounding boxes along with the additional arguments to [`~LayoutLMv2Tokenizer.__ca...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/processing_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/processing_layoutlmv2.py
Apache-2.0
def __call__( self, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]], text_pair: Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None, boxes: Union[List[List[int]], List[List[List[int]]]] = None, word_labels: Optional[Union[List[in...
Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of sequences with word-level normalized bounding boxes and optional labels. Args: text (`str`, `List[str]`, `List[List[str]]`): The sequence or batch of sequences ...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
Apache-2.0
def _batch_prepare_for_model( self, batch_text_or_text_pairs, is_pair: bool = None, boxes: Optional[List[List[int]]] = None, word_labels: Optional[List[List[int]]] = None, add_special_tokens: bool = True, padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_...
Prepares a sequence of input id, or a pair of sequences of inputs ids so that it can be used by the model. It adds special tokens, truncates sequences if overflowing while taking into account the special tokens and manages a moving window (with user defined stride) for overflowing tokens. ...
_batch_prepare_for_model
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
Apache-2.0
def encode_plus( self, text: Union[TextInput, PreTokenizedInput], text_pair: Optional[PreTokenizedInput] = None, boxes: Optional[List[List[int]]] = None, word_labels: Optional[List[int]] = None, add_special_tokens: bool = True, padding: Union[bool, str, PaddingStr...
Tokenize and prepare for the model a sequence or a pair of sequences. .. warning:: This method is deprecated, `__call__` should be used instead. Args: text (`str`, `List[str]`, `List[List[str]]`): The first sequence to be encoded. This can be a string, a list of str...
encode_plus
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
Apache-2.0
def prepare_for_model( self, text: Union[TextInput, PreTokenizedInput], text_pair: Optional[PreTokenizedInput] = None, boxes: Optional[List[List[int]]] = None, word_labels: Optional[List[int]] = None, add_special_tokens: bool = True, padding: Union[bool, str, Padd...
Prepares a sequence or a pair of sequences so that it can be used by the model. It adds special tokens, truncates sequences if overflowing while taking into account the special tokens and manages a moving window (with user defined stride) for overflowing tokens. Please Note, for *text_pair* dif...
prepare_for_model
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
Apache-2.0
def truncate_sequences( self, ids: List[int], token_boxes: List[List[int]], pair_ids: Optional[List[int]] = None, pair_token_boxes: Optional[List[List[int]]] = None, labels: Optional[List[int]] = None, num_tokens_to_remove: int = 0, truncation_strategy: Un...
Truncates a sequence pair in-place following the strategy. Args: ids (`List[int]`): Tokenized input ids of the first sequence. Can be obtained from a string by chaining the `tokenize` and `convert_tokens_to_ids` methods. token_boxes (`List[List[i...
truncate_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv2/tokenization_layoutlmv2.py
Apache-2.0
def generate_dummy_inputs( self, processor: "ProcessorMixin", batch_size: int = -1, seq_length: int = -1, is_pair: bool = False, framework: Optional["TensorType"] = None, num_channels: int = 3, image_width: int = 40, image_height: int = 40, ) -...
Generate inputs to provide to the ONNX exporter for the specific framework Args: processor ([`ProcessorMixin`]): The processor associated with this model configuration. batch_size (`int`, *optional*, defaults to -1): The batch size to export the ...
generate_dummy_inputs
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/configuration_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/configuration_layoutlmv3.py
Apache-2.0
def __call__( self, images: ImageInput, return_tensors: Optional[Union[str, TensorType]] = None, **kwargs ) -> BatchFeature: """ Main method to prepare for the model one or several image(s). Args: images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.I...
Main method to prepare for the model one or several image(s). Args: images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`): The image or batch of images to be prepared. Each image can be a PIL image, NumPy...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/feature_extraction_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/feature_extraction_layoutlmv3.py
Apache-2.0
def create_position_ids_from_input_ids(self, input_ids, padding_idx): """ Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols are ignored. This is modified from fairseq's `utils.make_positions`. """ # The series of cas...
Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols are ignored. This is modified from fairseq's `utils.make_positions`.
create_position_ids_from_input_ids
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
Apache-2.0
def create_position_ids_from_inputs_embeds(self, inputs_embeds): """ We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids. """ input_shape = inputs_embeds.size()[:-1] sequence_length = input_shape[1] position_ids ...
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.
create_position_ids_from_inputs_embeds
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
Apache-2.0
def cogview_attention(self, attention_scores, alpha=32): """ https://arxiv.org/abs/2105.13290 Section 2.4 Stabilization of training: Precision Bottleneck Relaxation (PB-Relax). A replacement of the original nn.Softmax(dim=-1)(attention_scores). Seems the new attention_probs will result i...
ERROR: type should be string, got "\n https://arxiv.org/abs/2105.13290 Section 2.4 Stabilization of training: Precision Bottleneck Relaxation\n (PB-Relax). A replacement of the original nn.Softmax(dim=-1)(attention_scores). Seems the new attention_probs\n will result in a slower speed and a little bias. Can use torch.allclose(standard_attention_probs,\n cogview_attention_probs, atol=1e-08) for comparison. The smaller atol (e.g., 1e-08), the better.\n "
cogview_attention
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
Apache-2.0
def init_visual_bbox(self, image_size=(14, 14), max_len=1000): """ Create the bounding boxes for the visual (patch) tokens. """ visual_bbox_x = torch.div( torch.arange(0, max_len * (image_size[1] + 1), max_len), image_size[1], rounding_mode="trunc" ) visual_bb...
Create the bounding boxes for the visual (patch) tokens.
init_visual_bbox
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
Apache-2.0
def forward( self, input_ids=None, bbox=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict...
Returns: Examples: ```python >>> from transformers import AutoProcessor, AutoModel >>> from datasets import load_dataset >>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False) >>> model = AutoModel.from_pretrained("microsof...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, bbox: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTensor] = None, head_m...
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`. Returns: Examples: ```python >>> from transformers import AutoProcessor, A...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTensor] = None, head_mask: Optional[torch.FloatTensor] = None, ...
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for position (index) of the start of the labelled span for computing the token classification loss. Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTensor] = None, head_mask: Optional[torch.FloatTensor] = None, ...
Returns: Examples: ```python >>> from transformers import AutoProcessor, AutoModelForSequenceClassification >>> from datasets import load_dataset >>> import torch >>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False) ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py
Apache-2.0
def create_position_ids_from_inputs_embeds(self, inputs_embds: tf.Tensor) -> tf.Tensor: """ We are provided embeddings directly. We cannot infer which are padded, so just generate sequential position ids. """ input_shape = tf.shape(inputs_embds) sequence_length = input_sh...
We are provided embeddings directly. We cannot infer which are padded, so just generate sequential position ids.
create_position_ids_from_inputs_embeds
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
Apache-2.0
def create_position_ids_from_input_ids(self, input_ids: tf.Tensor) -> tf.Tensor: """ Replace non-padding symbols with their position numbers. Position numbers begin at padding_token_index + 1. """ mask = tf.cast(tf.not_equal(input_ids, self.padding_token_index), input_ids.dtype) ...
Replace non-padding symbols with their position numbers. Position numbers begin at padding_token_index + 1.
create_position_ids_from_input_ids
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
Apache-2.0
def cogview_attention(self, attention_scores: tf.Tensor, alpha: Union[float, int] = 32): """ https://arxiv.org/abs/2105.13290 Section 2.4 Stabilization of training: Precision Bottleneck Relaxation (PB-Relax). A replacement of the original tf.keras.layers.Softmax(axis=-1)(attention_scores). Seems...
ERROR: type should be string, got "\n https://arxiv.org/abs/2105.13290 Section 2.4 Stabilization of training: Precision Bottleneck Relaxation\n (PB-Relax). A replacement of the original tf.keras.layers.Softmax(axis=-1)(attention_scores). Seems the new\n attention_probs will result in a slower speed and a little bias. Can use\n tf.debugging.assert_near(standard_attention_probs, cogview_attention_probs, atol=1e-08) for comparison. The\n smaller atol (e.g., 1e-08), the better.\n "
cogview_attention
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
Apache-2.0
def call( self, input_ids: Optional[tf.Tensor] = None, bbox: Optional[tf.Tensor] = None, attention_mask: Optional[tf.Tensor] = None, token_type_ids: Optional[tf.Tensor] = None, position_ids: Optional[tf.Tensor] = None, head_mask: Optional[tf.Tensor] = None, ...
Returns: Examples: ```python >>> from transformers import AutoProcessor, TFAutoModel >>> from datasets import load_dataset >>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False) >>> model = TFAutoModel.from_pretrained("micr...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
Apache-2.0
def call( self, input_ids: Optional[tf.Tensor] = None, attention_mask: Optional[tf.Tensor] = None, token_type_ids: Optional[tf.Tensor] = None, position_ids: Optional[tf.Tensor] = None, head_mask: Optional[tf.Tensor] = None, inputs_embeds: Optional[tf.Tensor] = Non...
Returns: Examples: ```python >>> from transformers import AutoProcessor, TFAutoModelForSequenceClassification >>> from datasets import load_dataset >>> import tensorflow as tf >>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
Apache-2.0
def call( self, input_ids: Optional[tf.Tensor] = None, bbox: Optional[tf.Tensor] = None, attention_mask: Optional[tf.Tensor] = None, token_type_ids: Optional[tf.Tensor] = None, position_ids: Optional[tf.Tensor] = None, head_mask: Optional[tf.Tensor] = None, ...
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`. Returns: Examples: ```python >>> from transformers import AutoProcessor, TFAutoMo...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
Apache-2.0
def call( self, input_ids: Optional[tf.Tensor] = None, attention_mask: Optional[tf.Tensor] = None, token_type_ids: Optional[tf.Tensor] = None, position_ids: Optional[tf.Tensor] = None, head_mask: Optional[tf.Tensor] = None, inputs_embeds: Optional[tf.Tensor] = Non...
start_positions (`tf.Tensor` of shape `(batch_size,)`, *optional*): Labels for position (index) of the start of the labelled span for computing the token classification loss. Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence ...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py
Apache-2.0
def __call__( self, images, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None, text_pair: Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None, boxes: Union[List[List[int]], List[List[List[int]]]] = None, word_labels:...
This method first forwards the `images` argument to [`~LayoutLMv3FeatureExtractor.__call__`]. In case [`LayoutLMv3FeatureExtractor`] was initialized with `apply_ocr` set to `True`, it passes the obtained words and bounding boxes along with the additional arguments to [`~LayoutLMv3Tokenizer.__ca...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/processing_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/processing_layoutlmv3.py
Apache-2.0
def build_inputs_with_special_tokens( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A RoBERTa sequence ha...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A RoBERTa sequence has the following format: - single sequence: `<s> X </s>` - pair of sequences: `<s> A </s></s> B </s>` Args: to...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/tokenization_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/tokenization_layoutlmv3.py
Apache-2.0
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Create a mask from the two sequences passed to be used in a sequence-pair classification task. RoBERTa does not make use of token type ids, therefore a ...
Create a mask from the two sequences passed to be used in a sequence-pair classification task. RoBERTa does not make use of token type ids, therefore a list of zeros is returned. Args: token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List[int]`, *op...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/tokenization_layoutlmv3.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/tokenization_layoutlmv3.py
Apache-2.0
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Args: Create a mask from the two sequences passed to be used in a sequence-pair classification task. RoBERTa does not: make use of token type id...
Args: Create a mask from the two sequences passed to be used in a sequence-pair classification task. RoBERTa does not: make use of token type ids, therefore a list of zeros is returned. token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List[int]`, *op...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutlmv3/tokenization_layoutlmv3_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/tokenization_layoutlmv3_fast.py
Apache-2.0
def __call__( self, images, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None, text_pair: Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None, boxes: Union[List[List[int]], List[List[List[int]]]] = None, word_labels:...
This method first forwards the `images` argument to [`~LayoutLMv2FeatureExtractor.__call__`]. In case [`LayoutLMv2FeatureExtractor`] was initialized with `apply_ocr` set to `True`, it passes the obtained words and bounding boxes along with the additional arguments to [`~LayoutXLMTokenizer.__cal...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutxlm/processing_layoutxlm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutxlm/processing_layoutxlm.py
Apache-2.0
def build_inputs_with_special_tokens( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An XLM-RoBERTa sequen...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An XLM-RoBERTa sequence has the following format: - single sequence: `<s> X </s>` - pair of sequences: `<s> A </s></s> B </s>` Args: ...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutxlm/tokenization_layoutxlm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutxlm/tokenization_layoutxlm.py
Apache-2.0
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Create a mask from the two sequences passed to be used in a sequence-pair classification task. XLM-RoBERTa does not make use of token type ids, therefor...
Create a mask from the two sequences passed to be used in a sequence-pair classification task. XLM-RoBERTa does not make use of token type ids, therefore a list of zeros is returned. Args: token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List[int]`,...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutxlm/tokenization_layoutxlm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutxlm/tokenization_layoutxlm.py
Apache-2.0
def prepare_for_model( self, text: Union[TextInput, PreTokenizedInput], text_pair: Optional[PreTokenizedInput] = None, boxes: Optional[List[List[int]]] = None, word_labels: Optional[List[int]] = None, add_special_tokens: bool = True, padding: Union[bool, str, Padd...
Prepares a sequence or a pair of sequences so that it can be used by the model. It adds special tokens, truncates sequences if overflowing while taking into account the special tokens and manages a moving window (with user defined stride) for overflowing tokens. Word-level `boxes` are ...
prepare_for_model
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutxlm/tokenization_layoutxlm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutxlm/tokenization_layoutxlm.py
Apache-2.0
def truncate_sequences( self, ids: List[int], token_boxes: List[List[int]], pair_ids: Optional[List[int]] = None, pair_token_boxes: Optional[List[List[int]]] = None, labels: Optional[List[int]] = None, num_tokens_to_remove: int = 0, truncation_strategy: Un...
Truncates a sequence pair in-place following the strategy. Args: ids (`List[int]`): Tokenized input ids of the first sequence. Can be obtained from a string by chaining the `tokenize` and `convert_tokens_to_ids` methods. token_boxes (`List[List[i...
truncate_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/layoutxlm/tokenization_layoutxlm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/layoutxlm/tokenization_layoutxlm.py
Apache-2.0
def forward( self, hidden_states, attention_mask=None, layer_head_mask=None, is_index_masked=None, is_index_global_attn=None, is_global_attn=None, output_attentions=False, ): """ [`LEDEncoderSelfAttention`] expects *len(hidden_states)* ...
[`LEDEncoderSelfAttention`] expects *len(hidden_states)* to be multiple of *attention_window*. Padding to *attention_window* happens in [`LEDEncoderModel.forward`] to avoid redoing the padding on each layer. The *attention_mask* is changed in [`LEDEncoderModel.forward`] from 0, 1, 2 to: ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def _pad_and_transpose_last_two_dims(hidden_states_padded, padding): """pads rows and then flips rows and columns""" hidden_states_padded = nn.functional.pad( hidden_states_padded, padding ) # padding value is not important because it will be overwritten hidden_states_padded...
pads rows and then flips rows and columns
_pad_and_transpose_last_two_dims
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def _pad_and_diagonalize(chunked_hidden_states): """ shift every row 1 step right, converting columns into diagonals. Example: ```python chunked_hidden_states: [ 0.4983, 2.6918, -0.0071, 1.0492, -1.8348, 0....
shift every row 1 step right, converting columns into diagonals. Example: ```python chunked_hidden_states: [ 0.4983, 2.6918, -0.0071, 1.0492, -1.8348, 0.7672, 0.2986, 0.0285, -0...
_pad_and_diagonalize
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def _chunk(hidden_states, window_overlap, onnx_export=False): """convert into overlapping chunks. Chunk size = 2w, overlap size = w""" if not onnx_export: # non-overlapping chunks of size = 2w hidden_states = hidden_states.view( hidden_states.size(0), ...
convert into overlapping chunks. Chunk size = 2w, overlap size = w
_chunk
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def _sliding_chunks_query_key_matmul(self, query: torch.Tensor, key: torch.Tensor, window_overlap: int): """ Matrix multiplication of query and key tensors using with a sliding window attention pattern. This implementation splits the input into overlapping chunks of size 2w (e.g. 512 for pretrai...
Matrix multiplication of query and key tensors using with a sliding window attention pattern. This implementation splits the input into overlapping chunks of size 2w (e.g. 512 for pretrained LEDEncoder) with an overlap of size window_overlap
_sliding_chunks_query_key_matmul
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def _sliding_chunks_matmul_attn_probs_value( self, attn_probs: torch.Tensor, value: torch.Tensor, window_overlap: int ): """ Same as _sliding_chunks_query_key_matmul but for attn_probs and value tensors. Returned tensor will be of the same shape as `attn_probs` """ ba...
Same as _sliding_chunks_query_key_matmul but for attn_probs and value tensors. Returned tensor will be of the same shape as `attn_probs`
_sliding_chunks_matmul_attn_probs_value
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def _get_global_attn_indices(is_index_global_attn): """compute global attn indices required throughout forward pass""" # helper variable num_global_attn_indices = is_index_global_attn.long().sum(dim=1) # max number of global attn indices in batch max_num_global_attn_indices = nu...
compute global attn indices required throughout forward pass
_get_global_attn_indices
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def forward( self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, layer_head_mask: torch.Tensor, is_index_masked=None, is_index_global_attn=None, is_global_attn=None, output_attentions=False, ): """ Args: hidden_...
Args: hidden_states (`torch.FloatTensor`): input to the layer of shape *(seq_len, batch, embed_dim)* attention_mask (`torch.FloatTensor`): attention mask of size *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values. ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def forward( self, hidden_states: torch.Tensor, attention_mask: Optional[torch.Tensor] = None, encoder_hidden_states: Optional[torch.Tensor] = None, encoder_attention_mask: Optional[torch.Tensor] = None, layer_head_mask: Optional[torch.Tensor] = None, cross_attn_l...
Args: hidden_states (`torch.FloatTensor`): input to the layer of shape *(seq_len, batch, embed_dim)* attention_mask (`torch.FloatTensor`): attention mask of size *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values. ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def _pad_to_window_size( self, input_ids: torch.Tensor, attention_mask: torch.Tensor, inputs_embeds: torch.Tensor, pad_token_id: int, ): """A helper function to pad tokens and mask to work with implementation of Longformer self-attention.""" # padding ...
A helper function to pad tokens and mask to work with implementation of Longformer self-attention.
_pad_to_window_size
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def forward( self, input_ids=None, attention_mask=None, global_attention_mask=None, head_mask=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, ): r""" Args: input_ids (`t...
Args: input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using [`LEDTokenizer`]. See [`PreTrai...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def forward( self, input_ids=None, attention_mask=None, global_attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, head_mask=None, cross_attn_head_mask=None, past_key_values=None, inputs_embeds=None, use_ca...
Args: input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using [`LEDTokenizer`]. See [`PreTrai...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.Tensor] = None, decoder_input_ids: Optional[torch.LongTensor] = None, decoder_attention_mask: Optional[torch.LongTensor] = None, head_mask: Optional[torch.Tensor] = None, ...
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the masked language modeling loss. Indices should either be in `[0, ..., config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_led.py
Apache-2.0
def call( self, inputs, training=False, ): """ LongformerSelfAttention expects *len(hidden_states)* to be multiple of *attention_window*. Padding to *attention_window* happens in LongformerModel.forward to avoid redoing the padding on each layer. The *attenti...
LongformerSelfAttention expects *len(hidden_states)* to be multiple of *attention_window*. Padding to *attention_window* happens in LongformerModel.forward to avoid redoing the padding on each layer. The *attention_mask* is changed in [`LongformerModel.forward`] from 0, 1, 2 to: -...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
Apache-2.0
def _sliding_chunks_query_key_matmul(self, query, key, window_overlap): """ Matrix multiplication of query and key tensors using with a sliding window attention pattern. This implementation splits the input into overlapping chunks of size 2w (e.g. 512 for pretrained Longformer) with an o...
Matrix multiplication of query and key tensors using with a sliding window attention pattern. This implementation splits the input into overlapping chunks of size 2w (e.g. 512 for pretrained Longformer) with an overlap of size window_overlap
_sliding_chunks_query_key_matmul
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
Apache-2.0
def call( self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, layer_head_mask: tf.Tensor, is_index_masked: tf.Tensor, is_index_global_attn: tf.Tensor, is_global_attn: bool, training=False, ): """ Args: hidden_states (...
Args: hidden_states (`tf.Tensor`): input to the layer of shape *(seq_len, batch, embed_dim)* attention_mask (`tf.Tensor`): attention mask of size *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values. layer_head_mas...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
Apache-2.0
def call( self, hidden_states, attention_mask: Optional[tf.Tensor] = None, encoder_hidden_states: Optional[tf.Tensor] = None, encoder_attention_mask: Optional[tf.Tensor] = None, layer_head_mask: Optional[tf.Tensor] = None, encoder_layer_head_mask: Optional[tf.Tens...
Args: hidden_states (`tf.Tensor`): input to the layer of shape *(seq_len, batch, embed_dim)* attention_mask (`tf.Tensor`): attention mask of size *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values. encoder_hidden...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
Apache-2.0
def call( self, input_ids=None, inputs_embeds=None, attention_mask=None, global_attention_mask=None, head_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None, training=False, ): """ Args: ...
Args: input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using [`LEDTokenizer`]. See [`PreTrainedToke...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
Apache-2.0
def _pad_to_window_size( self, input_ids, attention_mask, inputs_embeds, pad_token_id, ): """A helper function to pad tokens and mask to work with implementation of Longformer selfattention.""" # padding attention_window = ( self.attention_...
A helper function to pad tokens and mask to work with implementation of Longformer selfattention.
_pad_to_window_size
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
Apache-2.0
def call( self, input_ids=None, inputs_embeds=None, attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, head_mask=None, encoder_head_mask=None, past_key_values=None, use_cache=None, output_attentions=None, ...
Args: input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using [`LEDTokenizer`]. See [`PreTrainedTokenizer.encode`] an...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
Apache-2.0
def call( self, input_ids: Optional[TFModelInputType] = None, attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, decoder_input_ids: Optional[Union[np.ndarray, tf.Tensor]] = None, decoder_attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, head_mask:...
Returns: Examples: ```python >>> from transformers import LEDTokenizer, TFLEDForConditionalGeneration >>> import tensorflow as tf >>> mname = "allenai/led-base-16384" >>> tokenizer = LEDTokenizer.from_pretrained(mname) >>> TXT = "My friends are <mask> ...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/modeling_tf_led.py
Apache-2.0
def build_inputs_with_special_tokens( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A LED sequence has th...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A LED sequence has the following format: - single sequence: `<s> X </s>` - pair of sequences: `<s> A </s></s> B </s>` Args: token_...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/tokenization_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/tokenization_led.py
Apache-2.0
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Create a mask from the two sequences passed to be used in a sequence-pair classification task. LED does not make use of token type ids, therefore a list...
Create a mask from the two sequences passed to be used in a sequence-pair classification task. LED does not make use of token type ids, therefore a list of zeros is returned. Args: token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List[int]`, *option...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/tokenization_led.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/tokenization_led.py
Apache-2.0
def mask_token(self) -> str: """ `str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set. LED tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily comprise th...
`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set. LED tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily comprise the space before the *<mask>*.
mask_token
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/tokenization_led_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/tokenization_led_fast.py
Apache-2.0
def mask_token(self, value): """ Overriding the default behavior of the mask token to have it eat the space before it. This is needed to preserve backward compatibility with all the previously used models based on LED. """ # Mask token behave like a normal word, i.e. include the...
Overriding the default behavior of the mask token to have it eat the space before it. This is needed to preserve backward compatibility with all the previously used models based on LED.
mask_token
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/led/tokenization_led_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/led/tokenization_led_fast.py
Apache-2.0
def create_position_ids_from_input_ids(self, input_ids, padding_idx): """ Args: Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols are ignored. This is modified from fairseq's `utils.make_positions`. x: torch.Tens...
Args: Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols are ignored. This is modified from fairseq's `utils.make_positions`. x: torch.Tensor x: Returns: torch.Tensor
create_position_ids_from_input_ids
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
Apache-2.0
def create_position_ids_from_inputs_embeds(self, inputs_embeds): """ Args: We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.: inputs_embeds: torch.Tensor Returns: torch.Tensor """ input_shape = inpu...
Args: We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.: inputs_embeds: torch.Tensor Returns: torch.Tensor
create_position_ids_from_inputs_embeds
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, bbox: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, token_type_ids: Optional[torch.Tensor] = None, position_ids: Optional[torch.Tensor] = None, head_mask: Optional[torch.T...
Returns: Examples: ```python >>> from transformers import AutoTokenizer, AutoModel >>> from datasets import load_dataset >>> tokenizer = AutoTokenizer.from_pretrained("SCUT-DLVCLab/lilt-roberta-en-base") >>> model = AutoModel.from_pretrained("SCUT-DLVCLab/lil...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, bbox: Optional[torch.Tensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTensor] = None, head_mask:...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the sequence classification/regression loss. Indices should be in `[0, ..., config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If `confi...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, bbox: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTensor] = None, head_m...
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`. Returns: Examples: ```python >>> from transformers import AutoTokenizer, A...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, bbox: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTensor] = None, head_m...
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for position (index) of the start of the labelled span for computing the token classification loss. Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/lilt/modeling_lilt.py
Apache-2.0
def _get_question_end_index(input_ids, sep_token_id): """ Computes the index of the first occurrence of `sep_token_id`. """ sep_token_indices = (input_ids == sep_token_id).nonzero() batch_size = input_ids.shape[0] assert sep_token_indices.shape[1] == 2, "`input_ids` should have two dimensions"...
Computes the index of the first occurrence of `sep_token_id`.
_get_question_end_index
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
Apache-2.0
def _compute_global_attention_mask(input_ids, sep_token_id, before_sep_token=True): """ Computes global attention mask by putting attention on all tokens before `sep_token_id` if `before_sep_token is True` else after `sep_token_id`. """ question_end_index = _get_question_end_index(input_ids, sep_tok...
Computes global attention mask by putting attention on all tokens before `sep_token_id` if `before_sep_token is True` else after `sep_token_id`.
_compute_global_attention_mask
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
Apache-2.0
def create_position_ids_from_inputs_embeds(self, inputs_embeds): """ We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids. Args: inputs_embeds: torch.Tensor inputs_embeds: Returns: torch.Tensor """ in...
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids. Args: inputs_embeds: torch.Tensor inputs_embeds: Returns: torch.Tensor
create_position_ids_from_inputs_embeds
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
Apache-2.0
def forward( self, hidden_states, attention_mask=None, layer_head_mask=None, is_index_masked=None, is_index_global_attn=None, is_global_attn=None, output_attentions=False, ): """ [`LongformerSelfAttention`] expects *len(hidden_states)* ...
[`LongformerSelfAttention`] expects *len(hidden_states)* to be multiple of *attention_window*. Padding to *attention_window* happens in [`LongformerModel.forward`] to avoid redoing the padding on each layer. The *attention_mask* is changed in [`LongformerModel.forward`] from 0, 1, 2 to: ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, global_attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, token_type_ids: Optional[torch.Tensor] = None, position_ids:...
Returns: Examples: ```python >>> import torch >>> from transformers import LongformerModel, LongformerTokenizer >>> model = LongformerModel.from_pretrained("allenai/longformer-base-4096") >>> tokenizer = LongformerTokenizer.from_pretrained("allenai/longformer...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, global_attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, token_type_ids: Optional[torch.Tensor] = None, position_ids:...
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ..., config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, global_attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, token_type_ids: Optional[torch.Tensor] = None, position_ids:...
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for position (index) of the start of the labelled span for computing the token classification loss. Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/modeling_longformer.py
Apache-2.0
def call( self, input_ids: Optional[TFModelInputType] = None, attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, head_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, global_attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, token_type_ids: Opt...
start_positions (`tf.Tensor` of shape `(batch_size,)`, *optional*): Labels for position (index) of the start of the labelled span for computing the token classification loss. Positions are clamped to the length of the sequence (*sequence_length*). Position outside of the sequence ...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/modeling_tf_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/modeling_tf_longformer.py
Apache-2.0
def build_inputs_with_special_tokens( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A Longformer sequence...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A Longformer sequence has the following format: - single sequence: `<s> X </s>` - pair of sequences: `<s> A </s></s> B </s>` Args: ...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/tokenization_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/tokenization_longformer.py
Apache-2.0
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Create a mask from the two sequences passed to be used in a sequence-pair classification task. Longformer does not make use of token type ids, therefore...
Create a mask from the two sequences passed to be used in a sequence-pair classification task. Longformer does not make use of token type ids, therefore a list of zeros is returned. Args: token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List[int]`, ...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/tokenization_longformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/tokenization_longformer.py
Apache-2.0
def mask_token(self) -> str: """ `str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set. Longformer tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily comp...
`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set. Longformer tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily comprise the space before the *<mask>*. ...
mask_token
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/tokenization_longformer_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/tokenization_longformer_fast.py
Apache-2.0
def mask_token(self, value): """ Overriding the default behavior of the mask token to have it eat the space before it. This is needed to preserve backward compatibility with all the previously used models based on Longformer. """ # Mask token behave like a normal word, i.e. incl...
Overriding the default behavior of the mask token to have it eat the space before it. This is needed to preserve backward compatibility with all the previously used models based on Longformer.
mask_token
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longformer/tokenization_longformer_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longformer/tokenization_longformer_fast.py
Apache-2.0
def _pad_to_multiple(x: jnp.ndarray, block_len: int, axis: int, pad_value: int = 0) -> jnp.ndarray: """Pad an array so that a sequence length will be a multiple of `block_len`""" pad_len = -x.shape[axis] % block_len pad = [(0, 0)] * x.ndim pad[axis] = (0, pad_len) x = jnp.pad(x, pad_width=pad, mode=...
Pad an array so that a sequence length will be a multiple of `block_len`
_pad_to_multiple
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _split_into_blocks(x: jnp.ndarray, block_len: int, axis: int) -> jnp.ndarray: """Split an input array into blocks of a given `block_len` along the given `axis`. If the dimension length is not a multiple of `block_len`, it will be padded first with selected `pad_value`. """ # pad tensor to multiple o...
Split an input array into blocks of a given `block_len` along the given `axis`. If the dimension length is not a multiple of `block_len`, it will be padded first with selected `pad_value`.
_split_into_blocks
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _concatenate_3_blocks(x: jnp.ndarray, block_axis: int, sequence_axis: int, pad_value: int = 0) -> jnp.ndarray: """Concatenate three consecutive blocks for each input block for local attentiont. For more information, see: https://arxiv.org/pdf/2112.07916.pdf. """ num_blocks = x.shape[block_axis] ...
Concatenate three consecutive blocks for each input block for local attentiont. For more information, see: https://arxiv.org/pdf/2112.07916.pdf.
_concatenate_3_blocks
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _make_3block_relative_position_ids(block_len: int) -> jnp.ndarray: """Makes 3-blocked relative position ids for local attention.""" position_ids = jnp.arange(3 * block_len, dtype=jnp.int32) center_position_ids = position_ids[block_len:-block_len] relative_position_ids = position_ids[None, :] - cente...
Makes 3-blocked relative position ids for local attention.
_make_3block_relative_position_ids
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _mask_local_attention_mask(local_attention_mask: np.ndarray, block_len: int) -> jnp.ndarray: """Mask local attention mask to enforce that tokens are not allowed to attend tokens farther than ``local_radius.""" relative_position_ids = _make_3block_relative_position_ids(block_len) locality_mask = jnp.abs(...
Mask local attention mask to enforce that tokens are not allowed to attend tokens farther than ``local_radius.
_mask_local_attention_mask
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _get_local_attention_mask(attention_mask: np.ndarray, block_len: int) -> jnp.ndarray: """Prepare attention mask to be applied for a local attention.""" # [batch_size, num_blocks, block_len] _blocked_attention_mask = _split_into_blocks(attention_mask, block_len, axis=1) # [batch_size, num_block, 3 * ...
Prepare attention mask to be applied for a local attention.
_get_local_attention_mask
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _make_global_fixed_block_ids(attention_mask: np.ndarray, global_block_size: int) -> Tuple[jnp.ndarray, np.ndarray]: """Obtain the "fixed block" global id corresponding to each input token. This implementation is a simlified version of the original Flaxformr implementation adopted from: https://github.c...
Obtain the "fixed block" global id corresponding to each input token. This implementation is a simlified version of the original Flaxformr implementation adopted from: https://github.com/google/flaxformer/blob/main/flaxformer/architectures/longt5/long_attention.py. In our scenario, as we use this strategy...
_make_global_fixed_block_ids
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _make_side_relative_position_ids(attention_mask: np.ndarray, global_block_size: int) -> np.ndarray: """Create the relative position tensor for local -> global attention.""" block_ids, global_segment_ids = _make_global_fixed_block_ids(attention_mask, global_block_size) global_seq_len = global_segment_ids...
Create the relative position tensor for local -> global attention.
_make_side_relative_position_ids
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _create_global_aggregates(hidden_states: np.ndarray, block_ids: np.ndarray, global_seq_len: int) -> np.ndarray: """Compute individual block aggregates by summing over individual blocks.""" # (batch..., seq_len, global_seq_len)) one_hot_block_ids = jax.nn.one_hot(block_ids, global_seq_len) return jnp...
Compute individual block aggregates by summing over individual blocks.
_create_global_aggregates
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def __call__(self, hidden_states): """ Construct a layernorm module in the LongT5 style; No bias and no subtraction of mean. """ # layer norm should always be calculated in float32 variance = jnp.power(hidden_states.astype("f4"), 2).mean(axis=-1, keepdims=True) hidden_sta...
Construct a layernorm module in the LongT5 style; No bias and no subtraction of mean.
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _relative_position_bucket(relative_position, bidirectional=True, num_buckets=32, max_distance=128): """ Adapted from Mesh Tensorflow: https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593 Translate rel...
Adapted from Mesh Tensorflow: https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593 Translate relative position to a bucket number for relative attention. The relative position is defined as memory_positi...
_relative_position_bucket
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def __call__( self, hidden_states, attention_mask=None, key_value_states=None, position_bias=None, use_cache=False, output_attentions=False, deterministic=True, init_cache=False, ): """ Self-attention (if key_value_states is Non...
Self-attention (if key_value_states is None) or attention over source sentence (provided by key_value_states).
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def encode( self, input_ids: jnp.ndarray, attention_mask: Optional[jnp.ndarray] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, train: bool = False, params: dict = None, ...
Returns: Example: ```python >>> from transformers import T5Tokenizer, FlaxLongT5ForConditionalGeneration >>> tokenizer = T5Tokenizer.from_pretrained("t5-base") >>> model = FlaxLongT5ForConditionalGeneration.from_pretrained("google/long-t5-local-base") >>> tex...
encode
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def decode( self, decoder_input_ids, encoder_outputs, encoder_attention_mask: Optional[jnp.ndarray] = None, decoder_attention_mask: Optional[jnp.ndarray] = None, past_key_values: dict = None, output_attentions: Optional[bool] = None, output_hidden_states: ...
Returns: Example: ```python >>> from transformers import T5Tokenizer, FlaxLongT5ForConditionalGeneration >>> import jax.numpy as jnp >>> tokenizer = T5Tokenizer.from_pretrained("t5-base") >>> model = FlaxLongT5ForConditionalGeneration.from_pretrained("google/l...
decode
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def decode( self, decoder_input_ids, encoder_outputs, encoder_attention_mask: Optional[jnp.ndarray] = None, decoder_attention_mask: Optional[jnp.ndarray] = None, past_key_values: dict = None, output_attentions: Optional[bool] = None, output_hidden_states: ...
Returns: Example: ```python >>> from transformers import T5Tokenizer, FlaxLongT5ForConditionalGeneration >>> import jax.numpy as jnp >>> tokenizer = T5Tokenizer.from_pretrained("t5-base") >>> model = FlaxLongT5ForConditionalGeneration.from_pretrained("google/l...
decode
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_flax_longt5.py
Apache-2.0
def _pad_to_multiple(x: torch.Tensor, block_len: int, dim: int, pad_value: int = 0) -> torch.Tensor: """Pad a tensor so that a sequence length will be a multiple of `block_len`""" pad_len = -x.shape[dim] % block_len # Handle cases when an empty input sequence is given if not all(x.shape): new_sh...
Pad a tensor so that a sequence length will be a multiple of `block_len`
_pad_to_multiple
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_longt5.py
Apache-2.0
def _split_into_blocks(x: torch.Tensor, block_len: int, dim: int) -> torch.Tensor: """Split an input tensor into blocks of a given `block_len` along the given `dim`. If the dimension length is not a multiple of `block_len`, it will be padded first with selected `pad_value`. """ # pad tensor to multiple ...
Split an input tensor into blocks of a given `block_len` along the given `dim`. If the dimension length is not a multiple of `block_len`, it will be padded first with selected `pad_value`.
_split_into_blocks
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/longt5/modeling_longt5.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/longt5/modeling_longt5.py
Apache-2.0