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, hidden_states: torch.Tensor, attention_mask: torch.Tensor, causal_attention_mask: torch.Tensor, output_attentions: Optional[bool] = False, ) -> Tuple[torch.FloatTensor]: """ Args: hidden_states (`torch.FloatTensor`): input to the...
Args: hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, 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/clip/modeling_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
Apache-2.0
def forward( self, inputs_embeds, attention_mask: Optional[torch.Tensor] = None, causal_attention_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, ) ...
Args: inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This is useful if you want more control over how to convert `input_...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
Apache-2.0
def forward( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, position_ids: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bo...
Returns: Examples: ```python >>> from transformers import CLIPTokenizer, CLIPTextModel >>> model = CLIPTextModel.from_pretrained("openai/clip-vit-base-patch32") >>> tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-base-patch32") >>> inputs = tokeniz...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
Apache-2.0
def forward( self, pixel_values: Optional[torch.FloatTensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, ) -> Union[Tuple, BaseModelOutputWithPooling]: r""" Returns: ...
Returns: Examples: ```python >>> from PIL import Image >>> import requests >>> from transformers import CLIPProcessor, CLIPVisionModel >>> model = CLIPVisionModel.from_pretrained("openai/clip-vit-base-patch32") >>> processor = CLIPProcessor.from_pretra...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
Apache-2.0
def get_text_features( self, input_ids: Optional[torch.Tensor] = None, attention_mask: Optional[torch.Tensor] = None, position_ids: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: O...
Returns: text_features (`torch.FloatTensor` of shape `(batch_size, output_dim`): The text embeddings obtained by applying the projection layer to the pooled output of [`CLIPTextModel`]. Examples: ```python >>> from transformers import CLIPTokenizer, CLIPModel ...
get_text_features
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
Apache-2.0
def get_image_features( self, pixel_values: Optional[torch.FloatTensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, ) -> torch.FloatTensor: r""" Returns: image_f...
Returns: image_features (`torch.FloatTensor` of shape `(batch_size, output_dim`): The image embeddings obtained by applying the projection layer to the pooled output of [`CLIPVisionModel`]. Examples: ```python >>> from PIL import Image >>> import reques...
get_image_features
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, pixel_values: Optional[torch.FloatTensor] = None, attention_mask: Optional[torch.Tensor] = None, position_ids: Optional[torch.LongTensor] = None, return_loss: Optional[bool] = None, output_attentions...
Returns: Examples: ```python >>> from PIL import Image >>> import requests >>> from transformers import CLIPProcessor, CLIPModel >>> model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32") >>> processor = CLIPProcessor.from_pretrained("openai...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_clip.py
Apache-2.0
def get_text_features( self, input_ids, attention_mask=None, position_ids=None, params: dict = None, dropout_rng: jax.random.PRNGKey = None, train=False, ): r""" Args: input_ids (`numpy.ndarray` of shape `(batch_size, sequence_lengt...
Args: input_ids (`numpy.ndarray` 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 [`CLIPTokenizer`]. See [`PreTraine...
get_text_features
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_flax_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_flax_clip.py
Apache-2.0
def get_image_features( self, pixel_values, params: dict = None, dropout_rng: jax.random.PRNGKey = None, train=False ): r""" Args: pixel_values (`numpy.ndarray` of shape `(batch_size, num_channels, height, width)`): Pixel values. Padding will be ignored by default...
Args: pixel_values (`numpy.ndarray` of shape `(batch_size, num_channels, height, width)`): Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using [`CLIPFeatureExtractor`]. See [`CLIPFeatureExtractor.__call__`] for d...
get_image_features
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_flax_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_flax_clip.py
Apache-2.0
def call(self, pixel_values: tf.Tensor) -> tf.Tensor: """`pixel_values` is expected to be of NCHW format.""" batch_size, num_channels, height, width = shape_list(pixel_values) # When running on CPU, `tf.nn.conv2d` doesn't support `NCHW` format. # So change the input format from `NCHW` ...
`pixel_values` is expected to be of NCHW format.
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
Apache-2.0
def call( self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, causal_attention_mask: tf.Tensor, output_attentions: bool, training: bool = False, ) -> Tuple[tf.Tensor]: """ Args: hidden_states (`tf.Tensor`): input to the layer of shap...
Args: hidden_states (`tf.Tensor`): input to the layer of shape `(batch, seq_len, 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. causal_attenti...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
Apache-2.0
def call( self, input_ids: Optional[TFModelInputType] = None, attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, position_ids: Optional[Union[np.ndarray, tf.Tensor]] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None,...
Returns: Examples: ```python >>> from transformers import CLIPTokenizer, TFCLIPTextModel >>> model = TFCLIPTextModel.from_pretrained("openai/clip-vit-base-patch32") >>> tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-base-patch32") >>> inputs = tok...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
Apache-2.0
def call( self, pixel_values: Optional[TFModelInputType] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, training: Optional[bool] = False, ) -> Union[TFBaseModelOutputWithPooling, Tuple...
Returns: Examples: ```python >>> from PIL import Image >>> import requests >>> from transformers import CLIPProcessor, TFCLIPVisionModel >>> model = TFCLIPVisionModel.from_pretrained("openai/clip-vit-base-patch32") >>> processor = CLIPProcessor.from_pr...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
Apache-2.0
def get_text_features( self, input_ids: Optional[TFModelInputType] = None, attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, position_ids: Optional[Union[np.ndarray, tf.Tensor]] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[...
Returns: text_features (`tf.Tensor` of shape `(batch_size, output_dim`): The text embeddings obtained by applying the projection layer to the pooled output of [`TFCLIPTextModel`]. Examples: ```python >>> from transformers import CLIPTokenizer, TFCLIPModel ...
get_text_features
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
Apache-2.0
def get_image_features( self, pixel_values: Optional[TFModelInputType] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, training: bool = False, ) -> tf.Tensor: r""" Retur...
Returns: image_features (`tf.Tensor` of shape `(batch_size, output_dim`): The image embeddings obtained by applying the projection layer to the pooled output of [`TFCLIPVisionModel`]. Examples: ```python >>> from PIL import Image >>> import requests ...
get_image_features
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
Apache-2.0
def call( self, input_ids: Optional[TFModelInputType] = None, pixel_values: Optional[TFModelInputType] = None, attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, position_ids: Optional[Union[np.ndarray, tf.Tensor]] = None, return_loss: Optional[bool] = None, ...
Returns: Examples: ```python >>> import tensorflow as tf >>> from PIL import Image >>> import requests >>> from transformers import CLIPProcessor, TFCLIPModel >>> model = TFCLIPModel.from_pretrained("openai/clip-vit-base-patch32") >>> processor...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/modeling_tf_clip.py
Apache-2.0
def __call__(self, text=None, images=None, return_tensors=None, **kwargs): """ Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text` and `kwargs` arguments to CLIPTokenizerFast's [`~CLIPTokenizerFast.__call__`] if `text` is not `None` to e...
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text` and `kwargs` arguments to CLIPTokenizerFast's [`~CLIPTokenizerFast.__call__`] if `text` is not `None` to encode the text. To prepare the image(s), this method forwards the `images` and...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/processing_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/processing_clip.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 CLIP sequence has t...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A CLIP sequence has the following format: - single sequence: `<|startoftext|> X <|endoftext|>` Pairs of sequences are not the expected use case, but t...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/tokenization_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/tokenization_clip.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. CLIP does not make use of token type ids, therefore a list of zeros is returned. Args: ...
Create a mask from the two sequences passed. CLIP 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]`, *optional*): Optional second list of IDs...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/clip/tokenization_clip.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/clip/tokenization_clip.py
Apache-2.0
def duplicate_interleave(m): """ A simple version of `torch.repeat_interleave` for duplicating a matrix while interleaving the copy. """ dim0 = m.shape[0] m = m.view(-1, 1) # flatten the matrix m = m.repeat(1, 2) # repeat all elements into the 2nd dimension m = m.view(dim0, -1) # reshape ...
A simple version of `torch.repeat_interleave` for duplicating a matrix while interleaving the copy.
duplicate_interleave
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/codegen/modeling_codegen.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/codegen/modeling_codegen.py
Apache-2.0
def _reorder_cache(past: Tuple[Tuple[torch.Tensor]], beam_idx: torch.Tensor) -> Tuple[Tuple[torch.Tensor]]: """ This function is used to re-order the `past_key_values` cache if [`~PretrainedModel.beam_search`] or [`~PretrainedModel.beam_sample`] is called. This is required to match `past_key_val...
This function is used to re-order the `past_key_values` cache if [`~PretrainedModel.beam_search`] or [`~PretrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct beam_idx at every generation step.
_reorder_cache
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/codegen/modeling_codegen.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/codegen/modeling_codegen.py
Apache-2.0
def decode( self, token_ids: Union[int, List[int], "np.ndarray", "torch.Tensor", "tf.Tensor"], skip_special_tokens: bool = False, clean_up_tokenization_spaces: bool = True, truncate_before_pattern: Optional[List[str]] = None, **kwargs ) -> str: """ Con...
Converts a sequence of ids in a string, using the tokenizer and vocabulary with options to remove special tokens and clean up tokenization spaces. Similar to doing `self.convert_tokens_to_string(self.convert_ids_to_tokens(token_ids))`. Args: token_ids (`Union[int, List[int...
decode
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/codegen/tokenization_codegen.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/codegen/tokenization_codegen.py
Apache-2.0
def convert_conditional_detr_checkpoint(model_name, pytorch_dump_folder_path): """ Copy/paste/tweak model's weights to our CONDITIONAL_DETR structure. """ # load default config config = ConditionalDetrConfig() # set backbone and dilation attributes if "resnet101" in model_name: conf...
Copy/paste/tweak model's weights to our CONDITIONAL_DETR structure.
convert_conditional_detr_checkpoint
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/convert_conditional_detr_original_pytorch_checkpoint_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/convert_conditional_detr_original_pytorch_checkpoint_to_pytorch.py
Apache-2.0
def center_to_corners_format(x): """ Converts a PyTorch tensor of bounding boxes of center format (center_x, center_y, width, height) to corners format (x_0, y_0, x_1, y_1). """ center_x, center_y, width, height = x.unbind(-1) b = [(center_x - 0.5 * width), (center_y - 0.5 * height), (center_x +...
Converts a PyTorch tensor of bounding boxes of center format (center_x, center_y, width, height) to corners format (x_0, y_0, x_1, y_1).
center_to_corners_format
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def corners_to_center_format(x): """ Converts a NumPy array of bounding boxes of shape (number of bounding boxes, 4) of corners format (x_0, y_0, x_1, y_1) to center format (center_x, center_y, width, height). """ x_transposed = x.T x0, y0, x1, y1 = x_transposed[0], x_transposed[1], x_transposed...
Converts a NumPy array of bounding boxes of shape (number of bounding boxes, 4) of corners format (x_0, y_0, x_1, y_1) to center format (center_x, center_y, width, height).
corners_to_center_format
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def masks_to_boxes(masks): """ Compute the bounding boxes around the provided panoptic segmentation masks. The masks should be in format [N, H, W] where N is the number of masks, (H, W) are the spatial dimensions. Returns a [N, 4] tensor, with the boxes in corner (xyxy) format. """ if masks.si...
Compute the bounding boxes around the provided panoptic segmentation masks. The masks should be in format [N, H, W] where N is the number of masks, (H, W) are the spatial dimensions. Returns a [N, 4] tensor, with the boxes in corner (xyxy) format.
masks_to_boxes
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def binary_mask_to_rle(mask): """ Args: Converts given binary mask of shape (height, width) to the run-length encoding (RLE) format. mask (`torch.Tensor` or `numpy.array`): A binary mask tensor of shape `(height, width)` where 0 denotes background and 1 denotes the target seg...
Args: Converts given binary mask of shape (height, width) to the run-length encoding (RLE) format. mask (`torch.Tensor` or `numpy.array`): A binary mask tensor of shape `(height, width)` where 0 denotes background and 1 denotes the target segment_id or class_id. Returns: ...
binary_mask_to_rle
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def convert_segmentation_to_rle(segmentation): """ Converts given segmentation map of shape (height, width) to the run-length encoding (RLE) format. Args: segmentation (`torch.Tensor` or `numpy.array`): A segmentation map of shape `(height, width)` where each value denotes a segment or ...
Converts given segmentation map of shape (height, width) to the run-length encoding (RLE) format. Args: segmentation (`torch.Tensor` or `numpy.array`): A segmentation map of shape `(height, width)` where each value denotes a segment or class id. Returns: `List[List]`: A list of...
convert_segmentation_to_rle
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def remove_low_and_no_objects(masks, scores, labels, object_mask_threshold, num_labels): """ Binarize the given masks using `object_mask_threshold`, it returns the associated values of `masks`, `scores` and `labels`. Args: masks (`torch.Tensor`): A tensor of shape `(num_queries, hei...
Binarize the given masks using `object_mask_threshold`, it returns the associated values of `masks`, `scores` and `labels`. Args: masks (`torch.Tensor`): A tensor of shape `(num_queries, height, width)`. scores (`torch.Tensor`): A tensor of shape `(num_queries)`. ...
remove_low_and_no_objects
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def prepare_coco_detection(self, image, target, return_segmentation_masks=False): """ Convert the target in COCO format into the format expected by ConditionalDETR. """ w, h = image.size image_id = target["image_id"] image_id = np.asarray([image_id], dtype=np.int64) ...
Convert the target in COCO format into the format expected by ConditionalDETR.
prepare_coco_detection
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def _resize(self, image, size, target=None, max_size=None): """ Resize the image to the given size. Size can be min_size (scalar) or (w, h) tuple. If size is an int, smaller edge of the image will be matched to this number. If given, also resize the target accordingly. """ ...
Resize the image to the given size. Size can be min_size (scalar) or (w, h) tuple. If size is an int, smaller edge of the image will be matched to this number. If given, also resize the target accordingly.
_resize
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def _normalize(self, image, mean, std, target=None): """ Normalize the image with a certain mean and std. If given, also normalize the target bounding boxes based on the size of the image. """ image = self.normalize(image, mean=mean, std=std) if target is None: ...
Normalize the image with a certain mean and std. If given, also normalize the target bounding boxes based on the size of the image.
_normalize
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def __call__( self, images: ImageInput, annotations: Union[List[Dict], List[List[Dict]]] = None, return_segmentation_masks: Optional[bool] = False, masks_path: Optional[pathlib.Path] = None, pad_and_return_pixel_mask: Optional[bool] = True, return_tensors: Optiona...
Main method to prepare for the model one or several image(s) and optional annotations. Images are by default padded up to the largest image in a batch, and a pixel mask is created that indicates which pixels are real/which are padding. <Tip warning={true}> NumPy arrays and PyT...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def pad_and_create_pixel_mask( self, pixel_values_list: List["torch.Tensor"], return_tensors: Optional[Union[str, TensorType]] = None ): """ Pad images up to the largest image in a batch and create a corresponding `pixel_mask`. Args: pixel_values_list (`List[torch.Tensor...
Pad images up to the largest image in a batch and create a corresponding `pixel_mask`. Args: pixel_values_list (`List[torch.Tensor]`): List of images (pixel values) to be padded. Each image should be a tensor of shape (C, H, W). return_tensors (`str` or [`~utils...
pad_and_create_pixel_mask
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def post_process(self, outputs, target_sizes): """ Args: Converts the output of [`ConditionalDetrForObjectDetection`] into the format expected by the COCO api. Only supports PyTorch. outputs ([`ConditionalDetrObjectDetectionOutput`]): Raw outputs of the model....
Args: Converts the output of [`ConditionalDetrForObjectDetection`] into the format expected by the COCO api. Only supports PyTorch. outputs ([`ConditionalDetrObjectDetectionOutput`]): Raw outputs of the model. target_sizes (`torch.Tensor` of shape `(batch...
post_process
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def post_process_object_detection( self, outputs, threshold: float = 0.5, target_sizes: Union[TensorType, List[Tuple]] = None ): """ Converts the output of [`ConditionalDetrForObjectDetection`] into the format expected by the COCO api. Only supports PyTorch. Args: ...
Converts the output of [`ConditionalDetrForObjectDetection`] into the format expected by the COCO api. Only supports PyTorch. Args: outputs ([`DetrObjectDetectionOutput`]): Raw outputs of the model. threshold (`float`, *optional*): Score ...
post_process_object_detection
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def post_process_semantic_segmentation(self, outputs, target_sizes: List[Tuple[int, int]] = None): """ Converts the output of [`ConditionalDetrForSegmentation`] into semantic segmentation maps. Only supports PyTorch. Args: outputs ([`ConditionalDetrForSegmentation`]): ...
Converts the output of [`ConditionalDetrForSegmentation`] into semantic segmentation maps. Only supports PyTorch. Args: outputs ([`ConditionalDetrForSegmentation`]): Raw outputs of the model. target_sizes (`List[Tuple[int, int]]`, *optional*, defaults to...
post_process_semantic_segmentation
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def post_process_instance_segmentation( self, outputs, threshold: float = 0.5, mask_threshold: float = 0.5, overlap_mask_area_threshold: float = 0.8, target_sizes: Optional[List[Tuple[int, int]]] = None, return_coco_annotation: Optional[bool] = False, ) -> Lis...
Converts the output of [`ConditionalDetrForSegmentation`] into instance segmentation predictions. Only supports PyTorch. Args: outputs ([`ConditionalDetrForSegmentation`]): Raw outputs of the model. threshold (`float`, *optional*, defaults to 0.5): ...
post_process_instance_segmentation
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def post_process_panoptic_segmentation( self, outputs, threshold: float = 0.5, mask_threshold: float = 0.5, overlap_mask_area_threshold: float = 0.8, label_ids_to_fuse: Optional[Set[int]] = None, target_sizes: Optional[List[Tuple[int, int]]] = None, ) -> List[...
Converts the output of [`ConditionalDetrForSegmentation`] into image panoptic segmentation predictions. Only supports PyTorch. Args: outputs ([`ConditionalDetrForSegmentation`]): The outputs from [`ConditionalDetrForSegmentation`]. threshold (`float`, *o...
post_process_panoptic_segmentation
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
Apache-2.0
def forward( self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, position_embeddings: torch.Tensor = None, output_attentions: bool = False, ): """ Args: hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch,...
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, target_len, source_len)` where padding elements are indicated by very large negative ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def forward( self, hidden_states: torch.Tensor, attention_mask: Optional[torch.Tensor] = None, position_embeddings: Optional[torch.Tensor] = None, query_position_embeddings: Optional[torch.Tensor] = None, query_sine_embed: Optional[torch.Tensor] = None, encoder_hi...
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, target_len, source_len)` where padding elements are indicated by very large negative ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def forward( self, inputs_embeds=None, attention_mask=None, position_embeddings=None, output_attentions=None, output_hidden_states=None, return_dict=None, ): r""" Args: inputs_embeds (`torch.FloatTensor` of shape `(batch_size, seque...
Args: inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): Flattened feature map (output of the backbone + projection layer) that is passed to the encoder. attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *op...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def forward( self, inputs_embeds=None, attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, position_embeddings=None, query_position_embeddings=None, output_attentions=None, output_hidden_states=None, return_dict=No...
Args: inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): The query embeddings that are passed into the decoder. attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*): Mask to avoid pe...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def forward( self, pixel_values, pixel_mask=None, decoder_attention_mask=None, encoder_outputs=None, inputs_embeds=None, decoder_inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, ): r""" ...
Returns: Examples: ```python >>> from transformers import AutoFeatureExtractor, AutoModel >>> from PIL import Image >>> import requests >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg" >>> image = Image.open(requests.get(url, stream=T...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def forward( self, pixel_values, pixel_mask=None, decoder_attention_mask=None, encoder_outputs=None, inputs_embeds=None, decoder_inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None, ...
labels (`List[Dict]` of len `(batch_size,)`, *optional*): Labels for computing the bipartite matching loss. List of dicts, each dictionary containing at least the following 2 keys: 'class_labels' and 'boxes' (the class labels and bounding boxes of an image in the batch respe...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def forward( self, pixel_values, pixel_mask=None, decoder_attention_mask=None, encoder_outputs=None, inputs_embeds=None, decoder_inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None, ...
labels (`List[Dict]` of len `(batch_size,)`, *optional*): Labels for computing the bipartite matching loss, DICE/F-1 loss and Focal loss. List of dicts, each dictionary containing at least the following 3 keys: 'class_labels', 'boxes' and 'masks' (the class labels, bounding ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def dice_loss(inputs, targets, num_boxes): """ Compute the DICE loss, similar to generalized IOU for masks Args: inputs: A float tensor of arbitrary shape. The predictions for each example. targets: A float tensor with the same shape as inputs. Stores the binary ...
Compute the DICE loss, similar to generalized IOU for masks Args: inputs: A float tensor of arbitrary shape. The predictions for each example. targets: A float tensor with the same shape as inputs. Stores the binary classification label for each element in inpu...
dice_loss
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def sigmoid_focal_loss(inputs, targets, num_boxes, alpha: float = 0.25, gamma: float = 2): """ Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002. Args: inputs (`torch.FloatTensor` of arbitrary shape): The predictions for each example. targets (`torch.F...
Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002. Args: inputs (`torch.FloatTensor` of arbitrary shape): The predictions for each example. targets (`torch.FloatTensor` with the same shape as `inputs`) A tensor storing the binary classificatio...
sigmoid_focal_loss
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def loss_labels(self, outputs, targets, indices, num_boxes): """ Classification loss (Binary focal loss) targets dicts must contain the key "class_labels" containing a tensor of dim [nb_target_boxes] """ if "logits" not in outputs: raise KeyError("No logits were found...
Classification loss (Binary focal loss) targets dicts must contain the key "class_labels" containing a tensor of dim [nb_target_boxes]
loss_labels
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def loss_cardinality(self, outputs, targets, indices, num_boxes): """ Compute the cardinality error, i.e. the absolute error in the number of predicted non-empty boxes. This is not really a loss, it is intended for logging purposes only. It doesn't propagate gradients. """ logit...
Compute the cardinality error, i.e. the absolute error in the number of predicted non-empty boxes. This is not really a loss, it is intended for logging purposes only. It doesn't propagate gradients.
loss_cardinality
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def loss_boxes(self, outputs, targets, indices, num_boxes): """ Compute the losses related to the bounding boxes, the L1 regression loss and the GIoU loss. Targets dicts must contain the key "boxes" containing a tensor of dim [nb_target_boxes, 4]. The target boxes are expected in format...
Compute the losses related to the bounding boxes, the L1 regression loss and the GIoU loss. Targets dicts must contain the key "boxes" containing a tensor of dim [nb_target_boxes, 4]. The target boxes are expected in format (center_x, center_y, w, h), normalized by the image size.
loss_boxes
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def loss_masks(self, outputs, targets, indices, num_boxes): """ Compute the losses related to the masks: the focal loss and the dice loss. Targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w]. """ if "pred_masks" not in outputs: ...
Compute the losses related to the masks: the focal loss and the dice loss. Targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w].
loss_masks
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def forward(self, outputs, targets): """ This performs the loss computation. Args: outputs (`dict`, *optional*): Dictionary of tensors, see the output specification of the model for the format. targets (`List[dict]`, *optional*): List of...
This performs the loss computation. Args: outputs (`dict`, *optional*): Dictionary of tensors, see the output specification of the model for the format. targets (`List[dict]`, *optional*): List of dicts, such that `len(targets) == batch_size`. ...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def forward(self, outputs, targets): """ Args: outputs (`dict`): A dictionary that contains at least these entries: * "logits": Tensor of dim [batch_size, num_queries, num_classes] with the classification logits * "pred_boxes": Tensor of dim [b...
Args: outputs (`dict`): A dictionary that contains at least these entries: * "logits": Tensor of dim [batch_size, num_queries, num_classes] with the classification logits * "pred_boxes": Tensor of dim [batch_size, num_queries, 4] with the predicted bo...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def box_area(boxes: Tensor) -> Tensor: """ Computes the area of a set of bounding boxes, which are specified by its (x1, y1, x2, y2) coordinates. Args: boxes (`torch.FloatTensor` of shape `(number_of_boxes, 4)`): Boxes for which the area will be computed. They are expected to be in (x1,...
Computes the area of a set of bounding boxes, which are specified by its (x1, y1, x2, y2) coordinates. Args: boxes (`torch.FloatTensor` of shape `(number_of_boxes, 4)`): Boxes for which the area will be computed. They are expected to be in (x1, y1, x2, y2) format with `0 <= x1 ...
box_area
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
Apache-2.0
def generalized_box_iou(boxes1, boxes2): """ Generalized IoU from https://giou.stanford.edu/. The boxes should be in [x0, y0, x1, y1] (corner) format. Returns: `torch.FloatTensor`: a [N, M] pairwise matrix, where N = len(boxes1) and M = len(boxes2) """ # degenerate boxes gives inf / nan res...
Generalized IoU from https://giou.stanford.edu/. The boxes should be in [x0, y0, x1, y1] (corner) format. Returns: `torch.FloatTensor`: a [N, M] pairwise matrix, where N = len(boxes1) and M = len(boxes2)
generalized_box_iou
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/conditional_detr/modeling_conditional_detr.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 ConvBERT sequence h...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A ConvBERT 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/convbert/tokenization_convbert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/convbert/tokenization_convbert.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 ConvBERT 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 ConvBERT 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/convbert/tokenization_convbert.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/convbert/tokenization_convbert.py
Apache-2.0
def convert_convnext_checkpoint(checkpoint_url, pytorch_dump_folder_path): """ Copy/paste/tweak model's weights to our ConvNext structure. """ # define ConvNext configuration based on URL config, expected_shape = get_convnext_config(checkpoint_url) # load original state_dict from URL state_...
Copy/paste/tweak model's weights to our ConvNext structure.
convert_convnext_checkpoint
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/convnext/convert_convnext_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/convnext/convert_convnext_to_pytorch.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). <Tip warning={true}> NumPy arrays and PyTorch tensors are converted to PIL images w...
Main method to prepare for the model one or several image(s). <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: images (`PIL.Image.Image`, `np.ndarray...
__call__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/convnext/feature_extraction_convnext.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/convnext/feature_extraction_convnext.py
Apache-2.0
def call( self, pixel_values: Optional[TFModelInputType] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, training: bool = False, ) -> Union[TFBaseModelOutputWithPooling, Tuple[tf.Tensor]]: r""" Returns: Example...
Returns: Examples: ```python >>> from transformers import ConvNextFeatureExtractor, TFConvNextModel >>> from PIL import Image >>> import requests >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg" >>> image = Image.open(requests.get(url...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/convnext/modeling_tf_convnext.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/convnext/modeling_tf_convnext.py
Apache-2.0
def call( self, pixel_values: Optional[TFModelInputType] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, labels: Optional[Union[np.ndarray, tf.Tensor]] = None, training: Optional[bool] = False, ) -> Union[TFSequenceClassifierOu...
labels (`tf.Tensor` or `np.ndarray` 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 ...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/convnext/modeling_tf_convnext.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/convnext/modeling_tf_convnext.py
Apache-2.0
def __init__( self, vocab_file, do_lower_case=False, remove_space=True, keep_accents=False, bos_token="<s>", eos_token="</s>", unk_token="<unk>", sep_token="<sep>", pad_token="<pad>", cls_token="<cls>", mask_token="<mask>", ...
Construct a CPM tokenizer. Based on [Jieba](https://pypi.org/project/jieba/) and [SentencePiece](https://github.com/google/sentencepiece). This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to this superclass for more inform...
__init__
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cpm/tokenization_cpm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cpm/tokenization_cpm.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 XLNet sequence has...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An XLNet sequence has the following format: - single sequence: `X <sep> <cls>` - pair of sequences: `A <sep> B <sep> <cls>` Args: ...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cpm/tokenization_cpm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cpm/tokenization_cpm.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. An XLNet sequence pair mask has the following format: ...
Create a mask from the two sequences passed to be used in a sequence-pair classification task. An XLNet 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 `Non...
create_token_type_ids_from_sequences
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cpm/tokenization_cpm.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cpm/tokenization_cpm.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTens...
Returns: Example: ```python >>> from transformers import CTRLTokenizer, CTRLModel >>> import torch >>> tokenizer = CTRLTokenizer.from_pretrained("ctrl") >>> model = CTRLModel.from_pretrained("ctrl") >>> # CTRL was trained with control codes as the fir...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/ctrl/modeling_ctrl.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/ctrl/modeling_ctrl.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTens...
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set `labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-10...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/ctrl/modeling_ctrl.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/ctrl/modeling_ctrl.py
Apache-2.0
def forward( self, input_ids: Optional[torch.LongTensor] = None, past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None, attention_mask: Optional[torch.FloatTensor] = None, token_type_ids: Optional[torch.LongTensor] = None, position_ids: Optional[torch.LongTens...
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/ctrl/modeling_ctrl.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/ctrl/modeling_ctrl.py
Apache-2.0
def call( self, input_ids: Optional[TFModelInputType] = None, past_key_values: Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]] = None, attention_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, token_type_ids: Optional[Union[np.ndarray, tf.Tensor]] = None, positi...
labels (`tf.Tensor` 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/ctrl/modeling_tf_ctrl.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/ctrl/modeling_tf_ctrl.py
Apache-2.0
def embeddings(idx): """ The function helps in renaming embedding layer weights. Args: idx: stage number in original model """ embed = [] embed.append( ( f"cvt.encoder.stages.{idx}.embedding.convolution_embeddings.projection.weight", f"stage{idx}.patch_em...
The function helps in renaming embedding layer weights. Args: idx: stage number in original model
embeddings
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py
Apache-2.0
def attention(idx, cnt): """ The function helps in renaming attention block layers weights. Args: idx: stage number in original model cnt: count of blocks in each stage """ attention_weights = [] attention_weights.append( ( f"cvt.encoder.stages.{idx}.layers.{...
The function helps in renaming attention block layers weights. Args: idx: stage number in original model cnt: count of blocks in each stage
attention
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py
Apache-2.0
def final(): """ Function helps in renaming final classification layer """ head = [] head.append(("layernorm.weight", "norm.weight")) head.append(("layernorm.bias", "norm.bias")) head.append(("classifier.weight", "head.weight")) head.append(("classifier.bias", "head.bias")) return he...
Function helps in renaming final classification layer
final
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py
Apache-2.0
def convert_cvt_checkpoint(cvt_model, image_size, cvt_file_name, pytorch_dump_folder): """ Fucntion to convert the microsoft cvt checkpoint to huggingface checkpoint """ img_labels_file = "imagenet-1k-id2label.json" num_labels = 1000 repo_id = "huggingface/label-files" num_labels = num_labe...
Fucntion to convert the microsoft cvt checkpoint to huggingface checkpoint
convert_cvt_checkpoint
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py
Apache-2.0
def call( self, pixel_values: Optional[tf.Tensor] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, training: Optional[bool] = False, ) -> Union[TFBaseModelOutputWithCLSToken, Tuple[tf.Tensor]]: r""" Returns: Exa...
Returns: Examples: ```python >>> from transformers import AutoFeatureExtractor, TFCvtModel >>> from PIL import Image >>> import requests >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg" >>> image = Image.open(requests.get(url, stream=...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cvt/modeling_tf_cvt.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cvt/modeling_tf_cvt.py
Apache-2.0
def call( self, pixel_values: Optional[tf.Tensor] = None, labels: Optional[tf.Tensor] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, training: Optional[bool] = False, ) -> Union[TFImageClassifierOutputWithNoAttention, Tuple[tf...
labels (`tf.Tensor` or `np.ndarray` 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 ...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/cvt/modeling_tf_cvt.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/cvt/modeling_tf_cvt.py
Apache-2.0
def freeze_feature_extractor(self): """ Calling this function will disable the gradient computation for the feature encoder so that its parameter will not be updated during training. """ warnings.warn( "The method `freeze_feature_extractor` is deprecated and will be r...
Calling this function will disable the gradient computation for the feature encoder so that its parameter will not be updated during training.
freeze_feature_extractor
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
Apache-2.0
def forward( self, input_values: Optional[torch.Tensor], attention_mask: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, labels: Optional[torch.Tensor] = None...
labels (`torch.LongTensor` of shape `(batch_size, target_length)`, *optional*): Labels for connectionist temporal classification. Note that `target_length` has to be smaller or equal to the sequence length of the output logits. Indices are selected in `[-100, 0, ..., config.vocab_size -...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
Apache-2.0
def freeze_feature_extractor(self): """ Calling this function will disable the gradient computation for the feature encoder so that its parameters will not be updated during training. """ warnings.warn( "The method `freeze_feature_extractor` is deprecated and will be ...
Calling this function will disable the gradient computation for the feature encoder so that its parameters will not be updated during training.
freeze_feature_extractor
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
Apache-2.0
def freeze_base_model(self): """ Calling this function will disable the gradient computation for the base model so that its parameters will not be updated during training. Only the classification head will be updated. """ for param in self.data2vec_audio.parameters(): ...
Calling this function will disable the gradient computation for the base model so that its parameters will not be updated during training. Only the classification head will be updated.
freeze_base_model
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
Apache-2.0
def _get_tdnn_output_lengths(self, input_lengths: Union[torch.LongTensor, int]): """ Computes the output length of the TDNN layers """ def _conv_out_length(input_length, kernel_size, stride): # 1D convolutional layer output length formula taken # from https://pyt...
Computes the output length of the TDNN layers
_get_tdnn_output_lengths
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_audio.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/data2vec/modeling_data2vec_text.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_text.py
Apache-2.0
def forward( self, pixel_values: Optional[torch.Tensor] = None, head_mask: Optional[torch.Tensor] = None, labels: Optional[torch.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = No...
labels (`torch.LongTensor` of shape `(batch_size, height, width)`, *optional*): Ground truth semantic segmentation maps for computing the 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/data2vec/modeling_data2vec_vision.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_data2vec_vision.py
Apache-2.0
def dummy_inputs(self) -> Dict[str, tf.Tensor]: """ Dummy inputs to build the network. Returns: `Dict[str, tf.Tensor]`: The dummy inputs. """ VISION_DUMMY_INPUTS = tf.random.uniform( shape=(3, self.config.num_channels, self.config.image_size, self.config.image_siz...
Dummy inputs to build the network. Returns: `Dict[str, tf.Tensor]`: The dummy inputs.
dummy_inputs
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Apache-2.0
def call( self, pixel_values: Optional[TFModelInputType] = None, head_mask: Optional[Union[np.ndarray, tf.Tensor]] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, labels: Optional[U...
labels (`tf.Tensor` or `np.ndarray` 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 ...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Apache-2.0
def get_kernels(ind, outd) -> List: """Returns a List [(kernel_offset_start,kernel_length)] defining all the pooling kernels for a 1-D adaptive pooling layer that takes an input of dimension `ind` and yields an output of dimension `outd`""" def start_index(a, b, c): ...
Returns a List [(kernel_offset_start,kernel_length)] defining all the pooling kernels for a 1-D adaptive pooling layer that takes an input of dimension `ind` and yields an output of dimension `outd`
get_kernels
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Apache-2.0
def call( self, pixel_values: Optional[tf.Tensor] = None, head_mask: Optional[tf.Tensor] = None, labels: Optional[tf.Tensor] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, ) ->...
labels (`tf.Tensor` of shape `(batch_size, height, width)`, *optional*): Ground truth semantic segmentation maps for computing the loss. Indices should be in `[0, ..., config.num_labels - 1]`. If `config.num_labels > 1`, a classification loss is computed (Cross-Entropy). Return...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Apache-2.0
def forward(self, x): """ Call the module Args: x (`torch.tensor`): The input tensor to apply dropout """ if self.training and self.drop_prob > 0: return XDropout.apply(x, self.get_context()) return x
Call the module Args: x (`torch.tensor`): The input tensor to apply dropout
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/modeling_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/modeling_deberta.py
Apache-2.0
def build_relative_position(query_size, key_size, device): """ Build relative position according to the query and key We assume the absolute position of query \\(P_q\\) is range from (0, query_size) and the absolute position of key \\(P_k\\) is range from (0, key_size), The relative positions from quer...
Build relative position according to the query and key We assume the absolute position of query \(P_q\) is range from (0, query_size) and the absolute position of key \(P_k\) is range from (0, key_size), The relative positions from query to key is \(R_{q \rightarrow k} = P_q - P_k\) Args: ...
build_relative_position
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/modeling_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/modeling_deberta.py
Apache-2.0
def forward( self, hidden_states, attention_mask, output_attentions=False, query_states=None, relative_pos=None, rel_embeddings=None, ): """ Call the module Args: hidden_states (`torch.FloatTensor`): Input s...
Call the module Args: hidden_states (`torch.FloatTensor`): Input states to the module usually the output from previous layer, it will be the Q,K and V in *Attention(Q,K,V)* attention_mask (`torch.ByteTensor`): An attention mask m...
forward
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/modeling_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/modeling_deberta.py
Apache-2.0
def xdropout(self, inputs): """ Applies dropout to the inputs, as vanilla dropout, but also scales the remaining elements up by 1/drop_prob. """ mask = tf.cast( 1 - tf.compat.v1.distributions.Bernoulli(probs=1.0 - self.drop_prob).sample(sample_shape=shape_list(inp...
Applies dropout to the inputs, as vanilla dropout, but also scales the remaining elements up by 1/drop_prob.
xdropout
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/modeling_tf_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/modeling_tf_deberta.py
Apache-2.0
def build_relative_position(query_size, key_size): """ Build relative position according to the query and key We assume the absolute position of query \\(P_q\\) is range from (0, query_size) and the absolute position of key \\(P_k\\) is range from (0, key_size), The relative positions from query to key...
Build relative position according to the query and key We assume the absolute position of query \(P_q\) is range from (0, query_size) and the absolute position of key \(P_k\) is range from (0, key_size), The relative positions from query to key is \(R_{q \rightarrow k} = P_q - P_k\) Args: ...
build_relative_position
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/modeling_tf_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/modeling_tf_deberta.py
Apache-2.0
def call( self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, query_states: tf.Tensor = None, relative_pos: tf.Tensor = None, rel_embeddings: tf.Tensor = None, output_attentions: bool = False, training: bool = False, ) -> Tuple[tf.Tensor]: ...
Call the module Args: hidden_states (`tf.Tensor`): Input states to the module usually the output from previous layer, it will be the Q,K and V in *Attention(Q,K,V)* attention_mask (`tf.Tensor`): An attention mask matrix of shape ...
call
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/modeling_tf_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/modeling_tf_deberta.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 DeBERTa sequence ha...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A DeBERTa sequence has the following format: - single sequence: [CLS] X [SEP] - pair of sequences: [CLS] A [SEP] B [SEP] Args: tok...
build_inputs_with_special_tokens
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/tokenization_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/tokenization_deberta.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` or `encode_plus` methods. Args: token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List...
get_special_tokens_mask
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/tokenization_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/tokenization_deberta.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 DeBERTa 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 DeBERTa 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/deberta/tokenization_deberta.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/tokenization_deberta.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. Deberta tokenizer has a special mask token to be used in the fill-mask pipeline. The mask token will greedily comprise ...
`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set. Deberta tokenizer has a special mask token to be used 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/deberta/tokenization_deberta_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/tokenization_deberta_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. """ # Mask token behave like a normal word, i.e. include the space before it # So we set lstrip to True value = AddedToken(value, lstrip=True, rstrip=Fal...
Overriding the default behavior of the mask token to have it eat the space before it.
mask_token
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta/tokenization_deberta_fast.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta/tokenization_deberta_fast.py
Apache-2.0
def build_relative_position(query_size, key_size, bucket_size=-1, max_position=-1): """ Build relative position according to the query and key We assume the absolute position of query \\(P_q\\) is range from (0, query_size) and the absolute position of key \\(P_k\\) is range from (0, key_size), The rel...
Build relative position according to the query and key We assume the absolute position of query \(P_q\) is range from (0, query_size) and the absolute position of key \(P_k\) is range from (0, key_size), The relative positions from query to key is \(R_{q \rightarrow k} = P_q - P_k\) Args: ...
build_relative_position
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta_v2/modeling_deberta_v2.py
Apache-2.0
def build_relative_position(query_size, key_size, bucket_size=-1, max_position=-1): """ Build relative position according to the query and key We assume the absolute position of query \\(P_q\\) is range from (0, query_size) and the absolute position of key \\(P_k\\) is range from (0, key_size), The rel...
Build relative position according to the query and key We assume the absolute position of query \(P_q\) is range from (0, query_size) and the absolute position of key \(P_k\) is range from (0, key_size), The relative positions from query to key is \(R_{q \rightarrow k} = P_q - P_k\) Args: ...
build_relative_position
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta_v2/modeling_tf_deberta_v2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta_v2/modeling_tf_deberta_v2.py
Apache-2.0
def _tokenize(self, text: str) -> List[str]: """Take as input a string and return a list of strings (tokens) for words/sub-words""" if self.do_lower_case: text = text.lower() return self._tokenizer.tokenize(text)
Take as input a string and return a list of strings (tokens) for words/sub-words
_tokenize
python
FMInference/FlexLLMGen
benchmark/third_party/transformers/src/transformers/models/deberta_v2/tokenization_deberta_v2.py
https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deberta_v2/tokenization_deberta_v2.py
Apache-2.0