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 forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, decoder_input_ids: Optional[torch.Tensor] = None, decoder_attention_mask: Optional[torch.Tensor] = None, encoder_outputs: Optional[Tuple[torch.FloatTensor]] = None,...
Returns: Example: ```python >>> from transformers import PegasusTokenizer, PegasusModel >>> tokenizer = PegasusTokenizer.from_pretrained("google/pegasus-x-large") >>> model = PegasusModel.from_pretrained("google/pegasus-x-large") >>> inputs = tokenizer("Studi...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/pegasus_x/modeling_pegasus_x.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/pegasus_x/modeling_pegasus_x.py
Apache-2.0
def convert_perceiver_checkpoint(pickle_file, pytorch_dump_folder_path, architecture="MLM"): """ Copy/paste/tweak model's weights to our Perceiver structure. """ # load parameters as FlatMapping data structure with open(pickle_file, "rb") as f: checkpoint = pickle.loads(f.read()) state...
Copy/paste/tweak model's weights to our Perceiver structure.
convert_perceiver_checkpoint
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/convert_perceiver_haiku_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/convert_perceiver_haiku_to_pytorch.py
Apache-2.0
def center_crop(self, image): """ Crops `image` to *self.crop_size* using a center crop. Note that if the image is too small to be cropped to the size given, it will be padded (so the returned result has the size asked). Args: image (`PIL.Image.Image` or `np.ndarray` or `tor...
Crops `image` to *self.crop_size* using a center crop. Note that if the image is too small to be cropped to the size given, it will be padded (so the returned result has the size asked). Args: image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`): The image to...
center_crop
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/feature_extraction_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/feature_extraction_perceiver.py
Apache-2.0
def forward( self, inputs: torch.FloatTensor, attention_mask: Optional[torch.FloatTensor] = None, subsampled_output_points: Optional[Dict[str, torch.Tensor]] = None, head_mask: Optional[torch.FloatTensor] = None, output_attentions: Optional[bool] = None, output_hi...
Returns: Examples: ```python >>> from transformers import PerceiverConfig, PerceiverTokenizer, PerceiverFeatureExtractor, PerceiverModel >>> from transformers.models.perceiver.modeling_perceiver import ( ... PerceiverTextPreprocessor, ... PerceiverImage...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def forward( self, inputs: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, labels: Optional[torch.Tensor]...
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/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def forward( self, inputs: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, labels: Optional[torch.Tensor]...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the 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 `config.num_labels > ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def forward( self, inputs: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, labels: Optional[torch.Tensor]...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the image 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 `config.n...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def forward( self, inputs: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, labels: Optional[torch.Tensor]...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the image 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 `config.n...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def forward( self, inputs: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, labels: Optional[torch.Tensor]...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the image 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 `config.n...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def forward( self, inputs: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, labels: Optional[torch.Tensor]...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the optical flow loss. Indices should be in `[0, ..., config.num_labels - 1]`. Returns: Examples: ```python >>> from transformers import PerceiverForOpticalFlow >>> impo...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def forward( self, inputs: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, subsampled_output_points: Optional[Dict[str, torch.Tensor]] = None, head_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the image 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 `config.n...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def build_position_encoding( position_encoding_type, out_channels=None, project_pos_dim=-1, trainable_position_encoding_kwargs=None, fourier_position_encoding_kwargs=None, ): """ Builds the position encoding. Args: - out_channels: refers to the number of channels of the position enc...
Builds the position encoding. Args: - out_channels: refers to the number of channels of the position encodings. - project_pos_dim: if specified, will project the position encodings to this dimension.
build_position_encoding
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def restructure(modality_sizes: ModalitySizeType, inputs: torch.Tensor) -> Mapping[str, torch.Tensor]: """ Partitions a [B, N, C] tensor into tensors for each modality. Args: modality_sizes dict specifying the size of the modality inputs: input tensor Returns: ...
Partitions a [B, N, C] tensor into tensors for each modality. Args: modality_sizes dict specifying the size of the modality inputs: input tensor Returns: dict mapping name of modality to its associated tensor.
restructure
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def space_to_depth(frames: torch.Tensor, temporal_block_size: int = 1, spatial_block_size: int = 1) -> torch.Tensor: """ Space to depth transform. Rearranges blocks of spatial data, into depth. This function assumes the channels to be first, but will place the channels last after transformation. Based...
Space to depth transform. Rearranges blocks of spatial data, into depth. This function assumes the channels to be first, but will place the channels last after transformation. Based on https://discuss.pytorch.org/t/is-there-any-layer-like-tensorflows-space-to-depth-function/3487/15.
space_to_depth
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def __init__( self, num_layers: int = 1, in_channels: int = 3, out_channels: int = 64, use_batchnorm: bool = True, ): """ Constructs a Conv2DDownsample model. Args: in_channels (`int`, *optional*, defaults to 3): The number of in...
Constructs a Conv2DDownsample model. Args: in_channels (`int`, *optional*, defaults to 3): The number of input channels. out_channels (`int`, *optional*, defaults to 64): The number of conv output channels. use_batchnorm (`bool`, *optional*, defaul...
__init__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def generate_fourier_features(pos, num_bands, max_resolution=(224, 224), concat_pos=True, sine_only=False): """ Generate a Fourier frequency position encoding with linear spacing. Args: pos (`torch.LongTensor` of shape `(batch_size, sequence_length, dim)`): The Tensor containing the position ...
Generate a Fourier frequency position encoding with linear spacing. Args: pos (`torch.LongTensor` of shape `(batch_size, sequence_length, dim)`): The Tensor containing the position of n points in d dimensional space. num_bands (`int`): The number of frequency bands (K) to use. ...
generate_fourier_features
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def build_linear_positions(index_dims, output_range=(-1.0, 1.0)): """ Generate an array of position indices for an N-D input array. Args: index_dims (`List[int]`): The shape of the index dimensions of the input array. output_range (`Tuple[float]`, *optional*, defaults to `(-1.0, 1.0)`):...
Generate an array of position indices for an N-D input array. Args: index_dims (`List[int]`): The shape of the index dimensions of the input array. output_range (`Tuple[float]`, *optional*, defaults to `(-1.0, 1.0)`): The min and max values taken by each input index dimension. ...
build_linear_positions
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def _check_or_build_spatial_positions(pos, index_dims, batch_size): """ Checks or builds spatial position features (x, y, ...). Args: pos (`torch.FloatTensor`): None, or an array of position features. If None, position features are built. Otherwise, their size is checked. index_dims (`L...
Checks or builds spatial position features (x, y, ...). Args: pos (`torch.FloatTensor`): None, or an array of position features. If None, position features are built. Otherwise, their size is checked. index_dims (`List[int]`): An iterable giving the spatial/index size of the data t...
_check_or_build_spatial_positions
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def output_size(self): """Returns size of positional encodings last dimension.""" num_dims = len(self.max_resolution) encoding_size = self.num_bands * num_dims if not self.sine_only: encoding_size *= 2 if self.concat_pos: encoding_size += self.num_dimensio...
Returns size of positional encodings last dimension.
output_size
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def _build_network_inputs(self, inputs: torch.Tensor, network_input_is_1d: bool = True): """ Construct the final input, including position encoding. This method expects the inputs to always have channels as last dimension. """ batch_size = inputs.shape[0] index_dims = i...
Construct the final input, including position encoding. This method expects the inputs to always have channels as last dimension.
_build_network_inputs
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
Apache-2.0
def _build_network_inputs(self, inputs): """Construct the final input, including position encoding.""" batch_size = inputs.shape[0] index_dims = inputs.shape[1:-1] # Construct the position encoding. if self.position_encoding_type == "trainable": pos_enc = self.positi...
Construct the final input, including position encoding.
_build_network_inputs
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/modeling_perceiver.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. A sequence has the following format: - single sequence:...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks. A sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] B [SEP]` Args: token_ids_0 (`List[int]`): List of...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/perceiver/tokenization_perceiver.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/perceiver/tokenization_perceiver.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 PhoBERT sequence ha...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A PhoBERT 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/phobert/tokenization_phobert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/phobert/tokenization_phobert.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. PhoBERT 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. PhoBERT 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/phobert/tokenization_phobert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/phobert/tokenization_phobert.py
Apache-2.0
def forward( self, input_ids: torch.LongTensor = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, inputs_embeds: Optional[torch.FloatTensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optio...
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 [`PLBartTokenizer`]. See [`PreT...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/plbart/modeling_plbart.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/plbart/modeling_plbart.py
Apache-2.0
def forward( self, input_ids: torch.LongTensor = None, attention_mask: Optional[torch.Tensor] = None, encoder_hidden_states: Optional[torch.FloatTensor] = None, encoder_attention_mask: Optional[torch.LongTensor] = None, head_mask: Optional[torch.Tensor] = None, cr...
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 [`PLBartTokenizer`]. See [`PreT...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/plbart/modeling_plbart.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/plbart/modeling_plbart.py
Apache-2.0
def forward( self, input_ids: torch.LongTensor = None, attention_mask: Optional[torch.Tensor] = None, encoder_hidden_states: Optional[torch.FloatTensor] = None, encoder_attention_mask: Optional[torch.FloatTensor] = None, head_mask: Optional[torch.Tensor] = None, c...
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 [`PLBartTokenizer`]. See [`PreT...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/plbart/modeling_plbart.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/plbart/modeling_plbart.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 PLBART sequence ha...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An PLBART sequence has the following format, where `X` represents the sequence: - `input_ids` (for encoder) `X [eos, src_lang_code]` - `decoder_input_i...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/plbart/tokenization_plbart.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/plbart/tokenization_plbart.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. PLBart does not make use of token type ids, therefore a l...
Create a mask from the two sequences passed to be used in a sequence-pair classification task. PLBart 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]`, *opt...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/plbart/tokenization_plbart.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/plbart/tokenization_plbart.py
Apache-2.0
def replace_key_with_offset(key, offset, original_name, new_name): """ Replaces the key by subtracting the offset from the original layer number """ to_find = original_name.split(".")[0] key_list = key.split(".") orig_block_num = int(key_list[key_list.index(to_find) - 2]) layer_num = int(key...
Replaces the key by subtracting the offset from the original layer number
replace_key_with_offset
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/poolformer/convert_poolformer_original_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/poolformer/convert_poolformer_original_to_pytorch.py
Apache-2.0
def convert_poolformer_checkpoint(model_name, checkpoint_path, pytorch_dump_folder_path): """ Copy/paste/tweak model's weights to our PoolFormer structure. """ # load default PoolFormer configuration config = PoolFormerConfig() # set attributes based on model_name repo_id = "huggingface/la...
Copy/paste/tweak model's weights to our PoolFormer structure.
convert_poolformer_checkpoint
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/poolformer/convert_poolformer_original_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/poolformer/convert_poolformer_original_to_pytorch.py
Apache-2.0
def convert_prophetnet_checkpoint_to_pytorch(prophetnet_checkpoint_path: str, pytorch_dump_folder_path: str): """ Copy/paste/tweak prohpetnet's weights to our prophetnet structure. """ if "xprophetnet" in prophetnet_checkpoint_path: prophet_old = XLMProphetNetForConditionalGenerationOld.from_pre...
Copy/paste/tweak prohpetnet's weights to our prophetnet structure.
convert_prophetnet_checkpoint_to_pytorch
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/convert_prophetnet_original_pytorch_checkpoint_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/convert_prophetnet_original_pytorch_checkpoint_to_pytorch.py
Apache-2.0
def ngram_attention_bias(sequence_length, ngram, device, dtype): """ This function computes the bias for the predict stream """ left_block = ( torch.ones((ngram, sequence_length, sequence_length), device=device, dtype=dtype) * torch.finfo(dtype).min ) right_block = left_block.detach().cl...
This function computes the bias for the predict stream
ngram_attention_bias
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
Apache-2.0
def compute_relative_buckets(num_buckets, max_distance, relative_positions, is_bidirectional=False): """ This function computes individual parts of the relative position buckets. For more detail, see paper. """ inv_relative_positions = -relative_positions rel_positions_bucket = 0 if is_bidirect...
This function computes individual parts of the relative position buckets. For more detail, see paper.
compute_relative_buckets
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
Apache-2.0
def compute_all_stream_relative_buckets(num_buckets, max_distance, position_ids): """ This function computes both main and predict relative position buckets. For more detail, see paper. """ # main stream main_stream_relative_positions = position_ids.unsqueeze(1).repeat(1, position_ids.size(-1), 1) ...
This function computes both main and predict relative position buckets. For more detail, see paper.
compute_all_stream_relative_buckets
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, inputs_embeds: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Opti...
Returns: Example: ```python >>> from transformers import ProphetNetTokenizer, ProphetNetEncoder >>> import torch >>> tokenizer = ProphetNetTokenizer.from_pretrained("microsoft/prophetnet-large-uncased") >>> model = ProphetNetEncoder.from_pretrained("patrickvon...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, encoder_hidden_states: Optional[torch.Tensor] = None, encoder_attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, cross...
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*): Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder. encoder_attention_mask (...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, decoder_input_ids: Optional[torch.Tensor] = None, decoder_attention_mask: Optional[torch.BoolTensor] = None, head_mask: Optional[torch.Tensor] = None, decod...
Returns: Example: ```python >>> from transformers import ProphetNetTokenizer, ProphetNetModel >>> tokenizer = ProphetNetTokenizer.from_pretrained("microsoft/prophetnet-large-uncased") >>> model = ProphetNetModel.from_pretrained("microsoft/prophetnet-large-uncased") ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, decoder_input_ids: Optional[torch.Tensor] = None, decoder_attention_mask: Optional[torch.BoolTensor] = None, head_mask: Optional[torch.Tensor] = None, decod...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the sequence classification/regression loss. Indices should be in `[-100, 0, ..., config.vocab_size - 1]`. All labels set to `-100` are ignored (masked), the loss is only computed for labe...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, encoder_hidden_states: Optional[torch.Tensor] = None, encoder_attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, cross...
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*): Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder. encoder_attention_mask (`...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/modeling_prophetnet.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. A ProphetNet 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 ProphetNet 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 ...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/prophetnet/tokenization_prophetnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/prophetnet/tokenization_prophetnet.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.Tensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTensor] = None, head_mask: Optional[torch.Tensor] = None, inputs_emb...
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*): Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder. encoder_attention_mask (...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/qdqbert/modeling_qdqbert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/qdqbert/modeling_qdqbert.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, ...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the next sequence prediction (classification) loss. Input should be a sequence pair (see `input_ids` docstring). Indices should be in `[0, 1]`: - 0 indicates sequence B is a continuation ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/qdqbert/modeling_qdqbert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/qdqbert/modeling_qdqbert.py
Apache-2.0
def from_pretrained_question_encoder_generator( cls, question_encoder_pretrained_model_name_or_path: str = None, generator_pretrained_model_name_or_path: str = None, retriever: RagRetriever = None, **kwargs ) -> PreTrainedModel: r""" Instantiates an question e...
Instantiates an question encoder and a generator from one or two base classes of the library from pretrained model checkpoints. The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train the model, you need to first set it back in tr...
from_pretrained_question_encoder_generator
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.Tensor] = None, encoder_outputs: Optional[Tuple[Tuple[torch.FloatTensor]]] = None, decoder_input_ids: Optional[torch.LongTensor] = None, decoder_attention_mask: Optional[torch....
Returns: Example: ```python >>> from transformers import RagTokenizer, RagRetriever, RagModel >>> import torch >>> tokenizer = RagTokenizer.from_pretrained("facebook/rag-token-base") >>> retriever = RagRetriever.from_pretrained( ... "facebook/rag-t...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.Tensor] = None, encoder_outputs: Optional[Tuple[Tuple[torch.Tensor]]] = None, decoder_input_ids: Optional[torch.LongTensor] = None, decoder_attention_mask: Optional[torch.BoolT...
exclude_bos_score (`bool`, *optional*): Only relevant if `labels` is passed. If `True`, the score of the BOS token is disregarded when computing the loss. reduce_loss (`bool`, *optional*): Only relevant if `labels` is passed. If `True`, the NLL loss is reduced using ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
Apache-2.0
def generate( self, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.LongTensor] = None, context_input_ids: Optional[torch.LongTensor] = None, context_attention_mask: Optional[torch.LongTensor] = None, doc_scores: Optional[torch.FloatTensor] = ...
Implements RAG sequence "thorough" decoding. Read the [`~generation_utils.GenerationMixin.generate`]` documentation for more information on how to set other generate input parameters. Args: input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): ...
generate
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
Apache-2.0
def _reorder_cache(past, beam_idx): """Reorders cache for generation. BART-inspired but we need to take care of the extra dimension for docs""" def _reorder_stacked(hidden_states, new_order): n_docs = hidden_states.shape[0] // new_order.shape[0] hidden_states = hidden_states.vie...
Reorders cache for generation. BART-inspired but we need to take care of the extra dimension for docs
_reorder_cache
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.FloatTensor] = None, encoder_outputs: Optional[Tuple[Tuple[torch.Tensor]]] = None, decoder_input_ids: Optional[torch.LongTensor] = None, decoder_attention_mask: Optional[torch....
do_marginalize (`bool`, *optional*): If `True`, the logits are marginalized over all documents by making use of `torch.nn.functional.log_softmax`. reduce_loss (`bool`, *optional*): Only relevant if `labels` is passed. If `True`, the NLL loss is reduced using the `tor...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
Apache-2.0
def shift_tokens_right(self, input_ids, start_token_id=None): """Shift input ids one token to the right, and pad with start_token_id""" if start_token_id is None: start_token_id = self.config.decoder_start_token_id shifted_input_ids = input_ids.new_zeros(input_ids.shape) shif...
Shift input ids one token to the right, and pad with start_token_id
shift_tokens_right
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_rag.py
Apache-2.0
def from_pretrained_question_encoder_generator( cls, question_encoder_pretrained_model_name_or_path: str = None, generator_pretrained_model_name_or_path: str = None, retriever: RagRetriever = None, *model_args, **kwargs ) -> TFPreTrainedModel: r""" Ins...
Instantiates an question encoder and a generator from one or two base classes of the library from pretrained model checkpoints. Params: question_encoder_pretrained_model_name_or_path (`str`, *optional*): Information necessary to initiate the question encoder. Can be...
from_pretrained_question_encoder_generator
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
Apache-2.0
def call( self, input_ids: Optional[TFModelInputType] = None, attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, encoder_outputs: Optional[Union[np.ndarray, tf.Tensor]] = None, decoder_input_ids: Optional[Union[np.ndarray, tf.Tensor]] = None, decoder_attention...
Returns: Example: ```python >>> from transformers import RagTokenizer, RagRetriever, TFRagModel >>> import torch >>> tokenizer = RagTokenizer.from_pretrained("facebook/rag-token-base") >>> retriever = RagRetriever.from_pretrained( ... "facebook/rag...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.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, encoder_ou...
do_marginalize (`bool`, *optional*): If `True`, the logits are marginalized over all documents by making use of `torch.nn.functional.log_softmax`. labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the cros...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
Apache-2.0
def generate( self, input_ids: Optional[TFModelInputType] = None, attention_mask: Optional[tf.Tensor] = None, context_input_ids=None, context_attention_mask=None, doc_scores=None, max_length=None, min_length=None, early_stopping=None, use_c...
Implements TFRAG token decoding. Args: input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*): The sequence used as a prompt for the generation. If `input_ids` is not passed, then `context_input_ids` has to be provided. atte...
generate
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
Apache-2.0
def extend_enc_output(tensor, num_beams=None): """ Broadcast tensor with `num_beams` replica, with correct order Input: tensor of shape (batch_size*n_docs , d) Output: tensor of shape (batch_size*num_beams*n_docs , d) """ # expand batch_size & num_beam dimens...
Broadcast tensor with `num_beams` replica, with correct order Input: tensor of shape (batch_size*n_docs , d) Output: tensor of shape (batch_size*num_beams*n_docs , d)
extend_enc_output
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.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, encoder_ou...
exclude_bos_score (`bool`, *optional*): Only relevant if `labels` is passed. If `True`, the score of the BOS token is disregarded when computing the loss. labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing ...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
Apache-2.0
def generate( self, input_ids: Optional[TFModelInputType] = None, attention_mask: Optional[tf.Tensor] = None, context_input_ids=None, context_attention_mask=None, doc_scores=None, do_deduplication=None, # defaults to True num_return_sequences=None, # def...
Implements RAG sequence "thorough" decoding. Read the [`~generation_utils.GenerationMixin.generate`]` documentation for more information on how to set other generate input parameters Args: input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*): ...
generate
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/modeling_tf_rag.py
Apache-2.0
def postprocess_docs(self, docs, input_strings, prefix, n_docs, return_tensors=None): r""" Postprocessing retrieved `docs` and combining them with `input_strings`. Args: docs (`dict`): Retrieved documents. input_strings (`str`): Input str...
Postprocessing retrieved `docs` and combining them with `input_strings`. Args: docs (`dict`): Retrieved documents. input_strings (`str`): Input strings decoded by `preprocess_query`. prefix (`str`): Prefix added at th...
postprocess_docs
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/retrieval_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/retrieval_rag.py
Apache-2.0
def retrieve(self, question_hidden_states: np.ndarray, n_docs: int) -> Tuple[np.ndarray, List[dict]]: """ Retrieves documents for specified `question_hidden_states`. Args: question_hidden_states (`np.ndarray` of shape `(batch_size, vector_size)`): A batch of query ve...
Retrieves documents for specified `question_hidden_states`. Args: question_hidden_states (`np.ndarray` of shape `(batch_size, vector_size)`): A batch of query vectors to retrieve with. n_docs (`int`): The number of docs retrieved per query. ...
retrieve
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/retrieval_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/retrieval_rag.py
Apache-2.0
def __call__( self, question_input_ids: List[List[int]], question_hidden_states: np.ndarray, prefix=None, n_docs=None, return_tensors=None, ) -> BatchEncoding: """ Retrieves documents for specified `question_hidden_states`. Args: q...
Retrieves documents for specified `question_hidden_states`. Args: question_input_ids: (`List[List[int]]`) batch of input ids question_hidden_states (`np.ndarray` of shape `(batch_size, vector_size)`: A batch of query vectors to retrieve with. prefix:...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rag/retrieval_rag.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rag/retrieval_rag.py
Apache-2.0
def span_candidates(masks): """ Generate span candidates. Args: masks: <bool> [num_retrievals, max_sequence_len] Returns: starts: <int32> [num_spans] ends: <int32> [num_spans] span_masks: <int32> [num_retrievals, num_spans] ...
Generate span candidates. Args: masks: <bool> [num_retrievals, max_sequence_len] Returns: starts: <int32> [num_spans] ends: <int32> [num_spans] span_masks: <int32> [num_retrievals, num_spans] whether spans locate in evidence block. ...
span_candidates
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
Apache-2.0
def forward( self, input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, ): r""" Returns: ...
Returns: Example: ```python >>> from transformers import RealmTokenizer, RealmEmbedder >>> import torch >>> tokenizer = RealmTokenizer.from_pretrained("google/realm-cc-news-pretrained-embedder") >>> model = RealmEmbedder.from_pretrained("google/realm-cc-news-p...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
Apache-2.0
def forward( self, input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, candidate_input_ids=None, candidate_attention_mask=None, candidate_token_type_ids=None, candidate_inputs_embeds=None, head_mask=None, in...
candidate_input_ids (`torch.LongTensor` of shape `(batch_size, num_candidates, sequence_length)`): Indices of candidate input sequence tokens in the vocabulary. Indices can be obtained using [`RealmTokenizer`]. See [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
Apache-2.0
def forward( self, input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, relevance_score=None, labels=None, mlm_mask=None, output_attentions=None, output_hidden_stat...
relevance_score (`torch.FloatTensor` of shape `(batch_size, num_candidates)`, *optional*): Relevance score derived from RealmScorer, must be specified if you want to compute the masked language modeling loss. labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
Apache-2.0
def forward( self, input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, relevance_score=None, block_mask=None, start_positions=None, end_positions=None, has_answers...
relevance_score (`torch.FloatTensor` of shape `(searcher_beam_size,)`, *optional*): Relevance score, which must be specified if you want to compute the logits and marginal log loss. block_mask (`torch.BoolTensor` of shape `(searcher_beam_size, sequence_length)`, *optional*): The...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
Apache-2.0
def marginal_log_loss(logits, is_correct): """Loss based on the negative marginal log-likelihood.""" def mask_to_score(mask, dtype=torch.float32): return (1.0 - mask.type(dtype)) * torch.finfo(dtype).min # [] log_numerator = torch.log...
Loss based on the negative marginal log-likelihood.
marginal_log_loss
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
Apache-2.0
def forward( self, input_ids, attention_mask=None, token_type_ids=None, answer_ids=None, return_dict=None, ): r""" Returns: Example: ```python >>> import torch >>> from transformers import RealmForOpenQA, RealmRetrieve...
Returns: Example: ```python >>> import torch >>> from transformers import RealmForOpenQA, RealmRetriever, RealmTokenizer >>> retriever = RealmRetriever.from_pretrained("google/realm-orqa-nq-openqa") >>> tokenizer = RealmTokenizer.from_pretrained("google/realm-...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/modeling_realm.py
Apache-2.0
def batch_encode_candidates(self, text, **kwargs): r""" Encode a batch of text or text pair. This method is similar to regular __call__ method but has the following differences: 1. Handle additional num_candidate axis. (batch_size, num_candidates, text) 2. Always pad the...
Encode a batch of text or text pair. This method is similar to regular __call__ method but has the following differences: 1. Handle additional num_candidate axis. (batch_size, num_candidates, text) 2. Always pad the sequences to *max_length*. 3. Must specify *max_le...
batch_encode_candidates
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/tokenization_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/tokenization_realm.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 REALM sequence has ...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A REALM sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] B [SEP]` Args: t...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/tokenization_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/tokenization_realm.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. A REALM 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 REALM 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 `None...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/tokenization_realm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/tokenization_realm.py
Apache-2.0
def batch_encode_candidates(self, text, **kwargs): r""" Encode a batch of text or text pair. This method is similar to regular __call__ method but has the following differences: 1. Handle additional num_candidate axis. (batch_size, num_candidates, text) 2. Always pad the...
Encode a batch of text or text pair. This method is similar to regular __call__ method but has the following differences: 1. Handle additional num_candidate axis. (batch_size, num_candidates, text) 2. Always pad the sequences to *max_length*. 3. Must specify *max_le...
batch_encode_candidates
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/realm/tokenization_realm_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/realm/tokenization_realm_fast.py
Apache-2.0
def _look_adjacent(self, vectors, num_chunks_before, num_chunks_after): """ Used to implement attention between consecutive chunks. Args: vectors: array of shape [batch_size, num_attention_heads, n_chunks, chunk_len, ...] num_chunks_before: chunks before current chunk to...
Used to implement attention between consecutive chunks. Args: vectors: array of shape [batch_size, num_attention_heads, n_chunks, chunk_len, ...] num_chunks_before: chunks before current chunk to include in attention num_chunks_after: chunks after current chunk to i...
_look_adjacent
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def _split_seq_length_dim_to(self, vectors, dim_factor_1, dim_factor_2, num_attn_heads, attn_head_size=None): """ splits sequence length dim of vectors into `dim_factor_1` and `dim_factor_2` dims """ batch_size = vectors.shape[0] split_dim_shape = (batch_size, num_attn_heads, dim...
splits sequence length dim of vectors into `dim_factor_1` and `dim_factor_2` dims
_split_seq_length_dim_to
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def _len_and_dim_norm(self, vectors): """ length and attention head size dim normalization """ vectors = self._len_norm(vectors) vectors = vectors * torch.rsqrt( torch.tensor(self.attention_head_size, device=vectors.device, dtype=vectors.dtype) ) retur...
length and attention head size dim normalization
_len_and_dim_norm
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def _gather_by_expansion(self, vectors, idxs, num_hashes): """ expand dims of idxs and vectors for all hashes and gather """ expanded_idxs = idxs.unsqueeze(-1).expand(-1, -1, -1, self.attention_head_size) vectors = vectors.repeat(1, 1, num_hashes, 1) return torch.gather(v...
expand dims of idxs and vectors for all hashes and gather
_gather_by_expansion
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def _init_attention_seed(self): """ This function sets a new seed for the attention layer to make dropout deterministic for both forward calls: 1 normal forward call and 1 forward call in backward to recalculate activations. """ # randomize seeds # use cuda generator if ...
This function sets a new seed for the attention layer to make dropout deterministic for both forward calls: 1 normal forward call and 1 forward call in backward to recalculate activations.
_init_attention_seed
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def _init_feed_forward_seed(self): """ This function sets a new seed for the feed forward layer to make dropout deterministic for both forward calls: 1 normal forward call and 1 forward call in backward to recalculate activations. """ # randomize seeds # use cuda generato...
This function sets a new seed for the feed forward layer to make dropout deterministic for both forward calls: 1 normal forward call and 1 forward call in backward to recalculate activations.
_init_feed_forward_seed
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, position_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, inputs_embeds: Optional[torch.Tensor] = None, num_hashes: Optional[in...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the sequence classification/regression loss. Indices should be in `[-100, 0, ..., config.vocab_size - 1]`. All labels set to `-100` are ignored (masked), the loss is only computed for ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, position_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, inputs_embeds: Optional[torch.Tensor] = None, num_hashes: Optional[in...
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), ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, position_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, inputs_embeds: Optional[torch.Tensor] = None, num_hashes: Optional[in...
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/reformer/modeling_reformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/reformer/modeling_reformer.py
Apache-2.0
def get_from_to_our_keys(model_name: str) -> Dict[str, str]: """ Returns a dictionary that maps from original model's key -> our implementation's keys """ # create our model (with small weights) our_config = RegNetConfig(depths=[2, 7, 17, 1], hidden_sizes=[8, 8, 8, 8], groups_width=8) if "in1k"...
Returns a dictionary that maps from original model's key -> our implementation's keys
get_from_to_our_keys
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/regnet/convert_regnet_seer_10b_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/regnet/convert_regnet_seer_10b_to_pytorch.py
Apache-2.0
def __call__(self, x: Tensor): """ Transfer the weights of `self.src` to `self.dest` by performing a forward pass using `x` as input. Under the hood we tracked all the operations in both modules. """ dest_traced = Tracker(self.dest)(x).parametrized src_traced = Tracker(se...
Transfer the weights of `self.src` to `self.dest` by performing a forward pass using `x` as input. Under the hood we tracked all the operations in both modules.
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/regnet/convert_regnet_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/regnet/convert_regnet_to_pytorch.py
Apache-2.0
def forward( self, pixel_values: Optional[torch.FloatTensor] = None, labels: Optional[torch.LongTensor] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, ) -> ImageClassifierOutputWithNoAttention: r""" labels (`torch.Long...
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*): Labels for computing the image classification/regression loss. Indices should be in `[0, ..., config.num_labels - 1]`. If `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/regnet/modeling_regnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/regnet/modeling_regnet.py
Apache-2.0
def call( self, pixel_values: tf.Tensor = None, labels: tf.Tensor = None, output_hidden_states: bool = None, return_dict: bool = None, training=False, ) -> Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]: r""" labels (`tf.Tensor` of shape `(batch_s...
labels (`tf.Tensor` of shape `(batch_size,)`, *optional*): Labels for computing the image classification/regression loss. Indices should be in `[0, ..., config.num_labels - 1]`. If `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/regnet/modeling_tf_regnet.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/regnet/modeling_tf_regnet.py
Apache-2.0
def forward( self, input_ids: torch.LongTensor = None, attention_mask: Optional[torch.LongTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTensor] = None, head_mask: Optional[torch.FloatTensor] = None, inputs_embe...
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*): Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder. encoder_attention_mask (...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rembert/modeling_rembert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rembert/modeling_rembert.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 REMBERT sequence ha...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A REMBERT sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] B [SEP]` Args: ...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert.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. A RemBERT 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 RemBERT 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 `No...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert.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 RemBERT sequence ha...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A RemBERT sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] B [SEP]` Args: ...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert_fast.py
Apache-2.0
def get_special_tokens_mask( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False ) -> List[int]: """ Retrieves sequence ids from a token list that has no special tokens added. This method is called when adding special tokens...
Retrieves sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer `prepare_for_model` method. Args: token_ids_0 (`List[int]`): List of ids. token_ids_1 (`List[int]`, *optional*...
get_special_tokens_mask
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert_fast.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]: """ Creates a mask from the two sequences passed to be used in a sequence-pair classification task. A RemBERT sequence pair mask has the following format: ...
Creates a mask from the two sequences passed to be used in a sequence-pair classification task. A RemBERT 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 None...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/rembert/tokenization_rembert_fast.py
Apache-2.0
def forward( self, input_ids_query: torch.LongTensor, attention_mask_query: Optional[torch.FloatTensor], input_ids_doc: torch.LongTensor, attention_mask_doc: Optional[torch.FloatTensor], checkpoint_batch_size: int = -1, ) -> torch.FloatTensor: r""" Arg...
Args: input_ids_query (`torch.LongTensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary for the queries in a batch. Indices can be obtained using [`RetriBertTokenizer`]. See [`PreTrainedTokenizer.encode`] and ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/retribert/modeling_retribert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/retribert/modeling_retribert.py
Apache-2.0
def create_position_ids_from_input_ids(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`. Args: input_ids: jnp.ndarray padding...
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`. Args: input_ids: jnp.ndarray padding_idx: int Returns: jnp.ndarray
create_position_ids_from_input_ids
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/roberta/modeling_flax_roberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/roberta/modeling_flax_roberta.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, ...
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*): Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder. encoder_attention_mask (...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/roberta/modeling_roberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/roberta/modeling_roberta.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. Roberta tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily compris...
`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set. Roberta 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/roberta/tokenization_roberta_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/roberta/tokenization_roberta_fast.py
Apache-2.0
def call( self, input_ids: tf.Tensor = None, token_type_ids: tf.Tensor = None, inputs_embeds: tf.Tensor = None, training: bool = False, ) -> tf.Tensor: """ Applies embedding based on inputs tensor. Returns: final_embeddings (`tf.Tensor`):...
Applies embedding based on inputs tensor. Returns: final_embeddings (`tf.Tensor`): output embedding tensor.
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/roformer/modeling_tf_roformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/roformer/modeling_tf_roformer.py
Apache-2.0
def call( self, input_ids: Optional[TFModelInputType] = None, attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, token_type_ids: Optional[Union[np.ndarray, tf.Tensor]] = None, head_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, inputs_embeds: Optional[Un...
labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the cross entropy classification loss. Indices should be in `[0, ..., config.vocab_size - 1]`.
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/roformer/modeling_tf_roformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/roformer/modeling_tf_roformer.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 RoFormer sequence h...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A RoFormer sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] B [SEP]` Args: ...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/roformer/tokenization_roformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/roformer/tokenization_roformer.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. A RoFormer 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 RoFormer 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/roformer/tokenization_roformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/roformer/tokenization_roformer.py
Apache-2.0
def convert_segformer_checkpoint(model_name, checkpoint_path, pytorch_dump_folder_path): """ Copy/paste/tweak model's weights to our SegFormer structure. """ # load default SegFormer configuration config = SegformerConfig() encoder_only = False # set attributes based on model_name repo...
Copy/paste/tweak model's weights to our SegFormer structure.
convert_segformer_checkpoint
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/segformer/convert_segformer_original_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/segformer/convert_segformer_original_to_pytorch.py
Apache-2.0
def __call__( self, images: ImageInput, segmentation_maps: ImageInput = None, return_tensors: Optional[Union[str, TensorType]] = None, **kwargs ) -> BatchFeature: """ Main method to prepare for the model one or several image(s) and optional corresponding segme...
Main method to prepare for the model one or several image(s) and optional corresponding segmentation maps. <Tip warning={true}> NumPy arrays and PyTorch tensors are converted to PIL images when resizing, so the most efficient is to pass PIL images. </Tip> Args: ...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/segformer/feature_extraction_segformer.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/segformer/feature_extraction_segformer.py
Apache-2.0