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,
states=None,
actions=None,
rewards=None,
returns_to_go=None,
timesteps=None,
attention_mask=None,
output_hidden_states=None,
output_attentions=None,
return_dict=None,
) -> Union[Tuple, DecisionTransformerOutput]:
... |
Returns:
Examples:
```python
>>> from transformers import DecisionTransformerModel
>>> import torch
>>> model = DecisionTransformerModel.from_pretrained("edbeeching/decision-transformer-gym-hopper-medium")
>>> # evaluation
>>> model = model.to(device)
... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/decision_transformer/modeling_decision_transformer.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/decision_transformer/modeling_decision_transformer.py | Apache-2.0 |
def convert_deformable_detr_checkpoint(
checkpoint_path,
single_scale,
dilation,
with_box_refine,
two_stage,
pytorch_dump_folder_path,
push_to_hub,
):
"""
Copy/paste/tweak model's weights to our Deformable DETR structure.
"""
# load default config
config = DeformableDetr... |
Copy/paste/tweak model's weights to our Deformable DETR structure.
| convert_deformable_detr_checkpoint | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/convert_deformable_detr_to_pytorch.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/convert_deformable_detr_to_pytorch.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 DETR.
"""
w, h = image.size
image_id = target["image_id"]
image_id = np.asarray([image_id], dtype=np.int64)
# get ... |
Convert the target in COCO format into the format expected by DETR.
| prepare_coco_detection | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/feature_extraction_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/feature_extraction_deformable_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/deformable_detr/feature_extraction_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/feature_extraction_deformable_detr.py | Apache-2.0 |
def post_process(self, outputs, target_sizes):
"""
Converts the output of [`DeformableDetrForObjectDetection`] into the format expected by the COCO api. Only
supports PyTorch.
Args:
outputs ([`DeformableDetrObjectDetectionOutput`]):
Raw outputs of the model.
... |
Converts the output of [`DeformableDetrForObjectDetection`] into the format expected by the COCO api. Only
supports PyTorch.
Args:
outputs ([`DeformableDetrObjectDetectionOutput`]):
Raw outputs of the model.
target_sizes (`torch.Tensor` of shape `(batch_... | post_process | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/feature_extraction_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/feature_extraction_deformable_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 [`DeformableDetrForObjectDetection`] into the format expected by the COCO api. Only
supports PyTorch.
Args:
... |
Converts the output of [`DeformableDetrForObjectDetection`] into the format expected by the COCO api. Only
supports PyTorch.
Args:
outputs ([`DetrObjectDetectionOutput`]):
Raw outputs of the model.
threshold (`float`, *optional*):
Score t... | post_process_object_detection | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/feature_extraction_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/feature_extraction_deformable_detr.py | Apache-2.0 |
def forward(self, pixel_values: torch.Tensor, pixel_mask: torch.Tensor):
"""
Outputs feature maps of latter stages C_3 through C_5 in ResNet if `config.num_feature_levels > 1`, otherwise
outputs feature maps of C_5.
"""
# send pixel_values through the model to get list of feature... |
Outputs feature maps of latter stages C_3 through C_5 in ResNet if `config.num_feature_levels > 1`, otherwise
outputs feature maps of C_5.
| forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: torch.Tensor,
position_embeddings: torch.Tensor = None,
reference_points=None,
spatial_shapes=None,
level_start_index=None,
output_attentions: bool = False,
):
"""
Args:
... |
Args:
hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
Input to the layer.
attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
Attention mask.
position_embeddings (`torch.Flo... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
position_embeddings: Optional[torch.Tensor] = None,
reference_points=None,
spatial_shapes=None,
level_start_index=None,
encoder_hidden_states: Optional[torch.Tensor] = None,
encoder_attention_mask: Optional[t... |
Args:
hidden_states (`torch.FloatTensor`):
Input to the layer of shape `(seq_len, batch, embed_dim)`.
position_embeddings (`torch.FloatTensor`, *optional*):
Position embeddings that are added to the queries and keys in the self-attention layer.
... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def get_reference_points(spatial_shapes, valid_ratios, device):
"""
Get reference points for each feature map. Used in decoder.
Args:
spatial_shapes (`torch.LongTensor` of shape `(num_feature_levels, 2)`):
Spatial shapes of each feature map.
valid_ratios ... |
Get reference points for each feature map. Used in decoder.
Args:
spatial_shapes (`torch.LongTensor` of shape `(num_feature_levels, 2)`):
Spatial shapes of each feature map.
valid_ratios (`torch.FloatTensor` of shape `(batch_size, num_feature_levels, 2)`):
... | get_reference_points | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def forward(
self,
inputs_embeds=None,
attention_mask=None,
position_embeddings=None,
spatial_shapes=None,
level_start_index=None,
valid_ratios=None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
):
r"""
... |
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)`, *opt... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def forward(
self,
inputs_embeds=None,
encoder_hidden_states=None,
encoder_attention_mask=None,
position_embeddings=None,
reference_points=None,
spatial_shapes=None,
level_start_index=None,
valid_ratios=None,
output_attentions=None,
... |
Args:
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, num_queries, hidden_size)`):
The query embeddings that are passed into the decoder.
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def get_valid_ratio(self, mask):
"""Get the valid ratio of all feature maps."""
_, height, width = mask.shape
valid_height = torch.sum(~mask[:, :, 0], 1)
valid_width = torch.sum(~mask[:, 0, :], 1)
valid_ratio_heigth = valid_height.float() / height
valid_ratio_width = val... | Get the valid ratio of all feature maps. | get_valid_ratio | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def get_proposal_pos_embed(self, proposals):
"""Get the position embedding of the proposals."""
num_pos_feats = 128
temperature = 10000
scale = 2 * math.pi
dim_t = torch.arange(num_pos_feats, dtype=torch.float32, device=proposals.device)
dim_t = temperature ** (2 * (dim... | Get the position embedding of the proposals. | get_proposal_pos_embed | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def gen_encoder_output_proposals(self, enc_output, padding_mask, spatial_shapes):
"""Generate the encoder output proposals from encoded enc_output.
Args:
enc_output (Tensor[batch_size, sequence_length, hidden_size]): Output of the encoder.
padding_mask (Tensor[batch_size, sequen... | Generate the encoder output proposals from encoded enc_output.
Args:
enc_output (Tensor[batch_size, sequence_length, hidden_size]): Output of the encoder.
padding_mask (Tensor[batch_size, sequence_length]): Padding mask for `enc_output`.
spatial_shapes (Tensor[num_feature_le... | gen_encoder_output_proposals | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_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, DeformableDetrModel
>>> from PIL import Image
>>> import requests
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_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/deformable_detr/modeling_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def convert_deit_checkpoint(deit_name, pytorch_dump_folder_path):
"""
Copy/paste/tweak model's weights to our DeiT structure.
"""
# define default DeiT configuration
config = DeiTConfig()
# all deit models have fine-tuned heads
base_model = False
# dataset (fine-tuned on ImageNet 2012),... |
Copy/paste/tweak model's weights to our DeiT structure.
| convert_deit_checkpoint | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deit/convert_deit_timm_to_pytorch.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deit/convert_deit_timm_to_pytorch.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
bool_masked_pos: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Option... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
Returns:
Examples:
```python
>>> from transformers import DeiTFeatureExtractor, DeiTForMaskedImageModel... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deit/modeling_deit.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deit/modeling_deit.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,)`, *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/deit/modeling_deit.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deit/modeling_deit.py | Apache-2.0 |
def call(
self,
pixel_values: Optional[tf.Tensor] = None,
bool_masked_pos: Optional[tf.Tensor] = None,
head_mask: Optional[tf.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,... |
bool_masked_pos (`tf.Tensor` of type bool and shape `(batch_size, num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
Returns:
Examples:
```python
>>> from transformers import DeiTFeatureExtractor, TFDeiTForMaskedI... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deit/modeling_tf_deit.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deit/modeling_tf_deit.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,)`, *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.num_labe... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/deit/modeling_tf_deit.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/deit/modeling_tf_deit.py | Apache-2.0 |
def convert_detr_checkpoint(model_name, pytorch_dump_folder_path):
"""
Copy/paste/tweak model's weights to our DETR structure.
"""
# load default config
config = DetrConfig()
# set backbone and dilation attributes
if "resnet101" in model_name:
config.backbone = "resnet101"
if "d... |
Copy/paste/tweak model's weights to our DETR structure.
| convert_detr_checkpoint | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/convert_detr_original_pytorch_checkpoint_to_pytorch.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/convert_detr_original_pytorch_checkpoint_to_pytorch.py | Apache-2.0 |
def post_process(self, outputs, target_sizes):
"""
Converts the output of [`DetrForObjectDetection`] into the format expected by the COCO api. Only supports
PyTorch.
Args:
outputs ([`DetrObjectDetectionOutput`]):
Raw outputs of the model.
target_s... |
Converts the output of [`DetrForObjectDetection`] into the format expected by the COCO api. Only supports
PyTorch.
Args:
outputs ([`DetrObjectDetectionOutput`]):
Raw outputs of the model.
target_sizes (`torch.Tensor` of shape `(batch_size, 2)`):
... | post_process | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | Apache-2.0 |
def post_process_segmentation(self, outputs, target_sizes, threshold=0.9, mask_threshold=0.5):
"""
Converts the output of [`DetrForSegmentation`] into image segmentation predictions. Only supports PyTorch.
Args:
outputs ([`DetrSegmentationOutput`]):
Raw outputs of th... |
Converts the output of [`DetrForSegmentation`] into image segmentation predictions. Only supports PyTorch.
Args:
outputs ([`DetrSegmentationOutput`]):
Raw outputs of the model.
target_sizes (`torch.Tensor` of shape `(batch_size, 2)` or `List[Tuple]` of length `b... | post_process_segmentation | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | Apache-2.0 |
def post_process_instance(self, results, outputs, orig_target_sizes, max_target_sizes, threshold=0.5):
"""
Converts the output of [`DetrForSegmentation`] into actual instance segmentation predictions. Only supports
PyTorch.
Args:
results (`List[Dict]`):
Resul... |
Converts the output of [`DetrForSegmentation`] into actual instance segmentation predictions. Only supports
PyTorch.
Args:
results (`List[Dict]`):
Results list obtained by [`~DetrFeatureExtractor.post_process`], to which "masks" results will be
added... | post_process_instance | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | Apache-2.0 |
def post_process_panoptic(self, outputs, processed_sizes, target_sizes=None, is_thing_map=None, threshold=0.85):
"""
Converts the output of [`DetrForSegmentation`] into actual panoptic predictions. Only supports PyTorch.
Args:
outputs ([`DetrSegmentationOutput`]):
Ra... |
Converts the output of [`DetrForSegmentation`] into actual panoptic predictions. Only supports PyTorch.
Args:
outputs ([`DetrSegmentationOutput`]):
Raw outputs of the model.
processed_sizes (`torch.Tensor` of shape `(batch_size, 2)` or `List[Tuple]` of length `b... | post_process_panoptic | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_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 [`DetrForObjectDetection`] into the format expected by the COCO api. Only supports
PyTorch.
Args:
outputs (... |
Converts the output of [`DetrForObjectDetection`] into the format expected by the COCO api. Only supports
PyTorch.
Args:
outputs ([`DetrObjectDetectionOutput`]):
Raw outputs of the model.
threshold (`float`, *optional*):
Score threshold t... | post_process_object_detection | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | Apache-2.0 |
def post_process_semantic_segmentation(self, outputs, target_sizes: List[Tuple[int, int]] = None):
"""
Converts the output of [`DetrForSegmentation`] into semantic segmentation maps. Only supports PyTorch.
Args:
outputs ([`DetrForSegmentation`]):
Raw outputs of the m... |
Converts the output of [`DetrForSegmentation`] into semantic segmentation maps. Only supports PyTorch.
Args:
outputs ([`DetrForSegmentation`]):
Raw outputs of the model.
target_sizes (`List[Tuple[int, int]]`, *optional*, defaults to `None`):
A li... | post_process_semantic_segmentation | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_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 [`DetrForSegmentation`] into instance segmentation predictions. Only supports PyTorch.
Args:
outputs ([`DetrForSegmentation`]):
Raw outputs of the model.
threshold (`float`, *optional*, defaults to 0.5):
The probability sco... | post_process_instance_segmentation | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_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 [`DetrForSegmentation`] into image panoptic segmentation predictions. Only supports
PyTorch.
Args:
outputs ([`DetrForSegmentation`]):
The outputs from [`DetrForSegmentation`].
threshold (`float`, *optional*, defaults to 0.5):
... | post_process_panoptic_segmentation | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/feature_extraction_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 DetrFeatureExtractor, DetrModel
>>> 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/detr/modeling_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/modeling_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/detr/modeling_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/modeling_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/detr/modeling_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/modeling_detr.py | Apache-2.0 |
def loss_labels(self, outputs, targets, indices, num_boxes):
"""
Classification loss (NLL) 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 in the output... |
Classification loss (NLL) 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/detr/modeling_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/detr/modeling_detr.py | Apache-2.0 |
def forward(self, input_ids: torch.Tensor) -> torch.Tensor:
"""
Parameters:
input_ids: torch.tensor(bs, max_seq_length) The token ids to embed.
Returns: torch.tensor(bs, max_seq_length, dim) The embedded tokens (plus position embeddings, no token_type
embeddings)
"""... |
Parameters:
input_ids: torch.tensor(bs, max_seq_length) The token ids to embed.
Returns: torch.tensor(bs, max_seq_length, dim) The embedded tokens (plus position embeddings, no token_type
embeddings)
| forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | Apache-2.0 |
def forward(
self,
query: torch.Tensor,
key: torch.Tensor,
value: torch.Tensor,
mask: torch.Tensor,
head_mask: Optional[torch.Tensor] = None,
output_attentions: bool = False,
) -> Tuple[torch.Tensor, ...]:
"""
Parameters:
query: tor... |
Parameters:
query: torch.tensor(bs, seq_length, dim)
key: torch.tensor(bs, seq_length, dim)
value: torch.tensor(bs, seq_length, dim)
mask: torch.tensor(bs, seq_length)
Returns:
weights: torch.tensor(bs, n_heads, seq_length, seq_length) Attent... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | Apache-2.0 |
def forward(
self,
x: torch.Tensor,
attn_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: bool = False,
) -> Tuple[torch.Tensor, ...]:
"""
Parameters:
x: torch.tensor(bs, seq_length, dim)
... |
Parameters:
x: torch.tensor(bs, seq_length, dim)
attn_mask: torch.tensor(bs, seq_length)
Returns:
sa_weights: torch.tensor(bs, n_heads, seq_length, seq_length) The attention weights ffn_output:
torch.tensor(bs, seq_length, dim) The output of the transfor... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | Apache-2.0 |
def forward(
self,
x: torch.Tensor,
attn_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: bool = False,
output_hidden_states: bool = False,
return_dict: Optional[bool] = None,
) -> Union[BaseModelOutput, Tuple[t... |
Parameters:
x: torch.tensor(bs, seq_length, dim) Input sequence embedded.
attn_mask: torch.tensor(bs, seq_length) Attention mask on the sequence.
Returns:
hidden_state: torch.tensor(bs, seq_length, dim) Sequence of hidden states in the last (top)
layer a... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | Apache-2.0 |
def resize_position_embeddings(self, new_num_position_embeddings: int):
"""
Resizes position embeddings of the model if `new_num_position_embeddings != config.max_position_embeddings`.
Arguments:
new_num_position_embeddings (`int`):
The number of new position embeddi... |
Resizes position embeddings of the model if `new_num_position_embeddings != config.max_position_embeddings`.
Arguments:
new_num_position_embeddings (`int`):
The number of new position embedding matrix. If position embeddings are learned, increasing the size
... | resize_position_embeddings | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.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,
labels: Optional[torch.LongTensor] = None,
output_attentions: Option... |
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/distilbert/modeling_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.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,
labels: Optional[torch.LongTensor] = None,
output_attentions: Option... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the multiple choice classification loss. Indices should be in `[0, ...,
num_choices-1]` where `num_choices` is the size of the second dimension of the input tensors. (See
`input_ids` above... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_distilbert.py | Apache-2.0 |
def call(self, query, key, value, mask, head_mask, output_attentions, training=False):
"""
Parameters:
query: tf.Tensor(bs, seq_length, dim)
key: tf.Tensor(bs, seq_length, dim)
value: tf.Tensor(bs, seq_length, dim)
mask: tf.Tensor(bs, seq_length)
... |
Parameters:
query: tf.Tensor(bs, seq_length, dim)
key: tf.Tensor(bs, seq_length, dim)
value: tf.Tensor(bs, seq_length, dim)
mask: tf.Tensor(bs, seq_length)
Returns:
weights: tf.Tensor(bs, n_heads, seq_length, seq_length) Attention weights con... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_tf_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_tf_distilbert.py | Apache-2.0 |
def call(self, x, attn_mask, head_mask, output_attentions, training=False): # removed: src_enc=None, src_len=None
"""
Parameters:
x: tf.Tensor(bs, seq_length, dim)
attn_mask: tf.Tensor(bs, seq_length)
Outputs: sa_weights: tf.Tensor(bs, n_heads, seq_length, seq_length) T... |
Parameters:
x: tf.Tensor(bs, seq_length, dim)
attn_mask: tf.Tensor(bs, seq_length)
Outputs: sa_weights: tf.Tensor(bs, n_heads, seq_length, seq_length) The attention weights ffn_output:
tf.Tensor(bs, seq_length, dim) The output of the transformer block contextualization.... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_tf_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_tf_distilbert.py | Apache-2.0 |
def call(self, x, attn_mask, head_mask, output_attentions, output_hidden_states, return_dict, training=False):
# docstyle-ignore
"""
Parameters:
x: tf.Tensor(bs, seq_length, dim) Input sequence embedded.
attn_mask: tf.Tensor(bs, seq_length) Attention mask on the sequence.... |
Parameters:
x: tf.Tensor(bs, seq_length, dim) Input sequence embedded.
attn_mask: tf.Tensor(bs, seq_length) Attention mask on the sequence.
Returns:
hidden_state: tf.Tensor(bs, seq_length, dim)
Sequence of hidden states in the last (top) layer
... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_tf_distilbert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/distilbert/modeling_tf_distilbert.py | Apache-2.0 |
def __call__(
self,
images: ImageInput,
return_tensors: Optional[Union[str, TensorType]] = None,
random_padding=False,
**kwargs
) -> BatchFeature:
"""
Main method to prepare for the model one or several image(s).
<Tip warning={true}>
NumPy ar... |
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/donut/feature_extraction_donut.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/donut/feature_extraction_donut.py | Apache-2.0 |
def window_partition(input_feature, window_size):
"""
Partitions the given input into windows.
"""
batch_size, height, width, num_channels = input_feature.shape
input_feature = input_feature.view(
batch_size, height // window_size, window_size, width // window_size, window_size, num_channels... |
Partitions the given input into windows.
| window_partition | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/donut/modeling_donut_swin.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/donut/modeling_donut_swin.py | Apache-2.0 |
def window_reverse(windows, window_size, height, width):
"""
Merges windows to produce higher resolution features.
"""
num_channels = windows.shape[-1]
windows = windows.view(-1, height // window_size, width // window_size, window_size, window_size, num_channels)
windows = windows.permute(0, 1, ... |
Merges windows to produce higher resolution features.
| window_reverse | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/donut/modeling_donut_swin.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/donut/modeling_donut_swin.py | Apache-2.0 |
def __call__(self, *args, **kwargs):
"""
When used in normal mode, this method forwards all its arguments to AutoFeatureExtractor's
[`~AutoFeatureExtractor.__call__`] and returns its output. If used in the context
[`~DonutProcessor.as_target_processor`] this method forwards all its argum... |
When used in normal mode, this method forwards all its arguments to AutoFeatureExtractor's
[`~AutoFeatureExtractor.__call__`] and returns its output. If used in the context
[`~DonutProcessor.as_target_processor`] this method forwards all its arguments to DonutTokenizer's
[`~DonutTokeniz... | __call__ | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/donut/processing_donut.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/donut/processing_donut.py | Apache-2.0 |
def as_target_processor(self):
"""
Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning TrOCR.
"""
warnings.warn(
"`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your "
... |
Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning TrOCR.
| as_target_processor | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/donut/processing_donut.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/donut/processing_donut.py | Apache-2.0 |
def token2json(self, tokens, is_inner_value=False):
"""
Convert a (generated) token sequence into an ordered JSON format.
"""
output = dict()
while tokens:
start_token = re.search(r"<s_(.*?)>", tokens, re.IGNORECASE)
if start_token is None:
... |
Convert a (generated) token sequence into an ordered JSON format.
| token2json | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/donut/processing_donut.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/donut/processing_donut.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[Tensor] = None,
attention_mask: Optional[Tensor] = None,
token_type_ids: Optional[Tensor] = None,
inputs_embeds: Optional[Tensor] = None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
) -> U... |
Return:
Examples:
```python
>>> from transformers import DPRContextEncoder, DPRContextEncoderTokenizer
>>> tokenizer = DPRContextEncoderTokenizer.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base")
>>> model = DPRContextEncoder.from_pretrained("facebook/dpr-ctx... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/modeling_dpr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/modeling_dpr.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[Tensor] = None,
attention_mask: Optional[Tensor] = None,
token_type_ids: Optional[Tensor] = None,
inputs_embeds: Optional[Tensor] = None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
) -> U... |
Return:
Examples:
```python
>>> from transformers import DPRQuestionEncoder, DPRQuestionEncoderTokenizer
>>> tokenizer = DPRQuestionEncoderTokenizer.from_pretrained("facebook/dpr-question_encoder-single-nq-base")
>>> model = DPRQuestionEncoder.from_pretrained("faceboo... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/modeling_dpr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/modeling_dpr.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[Tensor] = None,
attention_mask: Optional[Tensor] = None,
inputs_embeds: Optional[Tensor] = None,
output_attentions: bool = None,
output_hidden_states: bool = None,
return_dict=None,
) -> Union[DPRReaderOutput, Tuple[Tenso... |
Return:
Examples:
```python
>>> from transformers import DPRReader, DPRReaderTokenizer
>>> tokenizer = DPRReaderTokenizer.from_pretrained("facebook/dpr-reader-single-nq-base")
>>> model = DPRReader.from_pretrained("facebook/dpr-reader-single-nq-base")
>>> enco... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/modeling_dpr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/modeling_dpr.py | Apache-2.0 |
def call(
self,
input_ids=None,
attention_mask: Optional[tf.Tensor] = None,
token_type_ids: Optional[tf.Tensor] = None,
inputs_embeds: Optional[tf.Tensor] = None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
training: bool =... |
Return:
Examples:
```python
>>> from transformers import TFDPRContextEncoder, DPRContextEncoderTokenizer
>>> tokenizer = DPRContextEncoderTokenizer.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base")
>>> model = TFDPRContextEncoder.from_pretrained("facebook/dpr... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/modeling_tf_dpr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/modeling_tf_dpr.py | Apache-2.0 |
def call(
self,
input_ids=None,
attention_mask: Optional[tf.Tensor] = None,
token_type_ids: Optional[tf.Tensor] = None,
inputs_embeds: Optional[tf.Tensor] = None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
training: bool =... |
Return:
Examples:
```python
>>> from transformers import TFDPRQuestionEncoder, DPRQuestionEncoderTokenizer
>>> tokenizer = DPRQuestionEncoderTokenizer.from_pretrained("facebook/dpr-question_encoder-single-nq-base")
>>> model = TFDPRQuestionEncoder.from_pretrained("fac... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/modeling_tf_dpr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/modeling_tf_dpr.py | Apache-2.0 |
def call(
self,
input_ids=None,
attention_mask: Optional[tf.Tensor] = None,
inputs_embeds: Optional[tf.Tensor] = None,
output_attentions: bool = None,
output_hidden_states: bool = None,
return_dict=None,
training: bool = False,
) -> Union[TFDPRReaderOu... |
Return:
Examples:
```python
>>> from transformers import TFDPRReader, DPRReaderTokenizer
>>> tokenizer = DPRReaderTokenizer.from_pretrained("facebook/dpr-reader-single-nq-base")
>>> model = TFDPRReader.from_pretrained("facebook/dpr-reader-single-nq-base", from_pt=True... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/modeling_tf_dpr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/modeling_tf_dpr.py | Apache-2.0 |
def decode_best_spans(
self,
reader_input: BatchEncoding,
reader_output: DPRReaderOutput,
num_spans: int = 16,
max_answer_length: int = 64,
num_spans_per_passage: int = 4,
) -> List[DPRSpanPrediction]:
"""
Get the span predictions for the extractive Q&... |
Get the span predictions for the extractive Q&A model.
Returns: *List* of *DPRReaderOutput* sorted by descending *(relevance_score, span_score)*. Each
*DPRReaderOutput* is a *Tuple* with:
- **span_score**: `float` that corresponds to the score given by the reader for this span com... | decode_best_spans | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/tokenization_dpr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/tokenization_dpr.py | Apache-2.0 |
def _get_best_spans(
self,
start_logits: List[int],
end_logits: List[int],
max_answer_length: int,
top_spans: int,
) -> List[DPRSpanPrediction]:
"""
Finds the best answer span for the extractive Q&A model for one passage. It returns the best span by descending... |
Finds the best answer span for the extractive Q&A model for one passage. It returns the best span by descending
`span_score` order and keeping max `top_spans` spans. Spans longer that `max_answer_length` are ignored.
| _get_best_spans | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/tokenization_dpr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/tokenization_dpr.py | Apache-2.0 |
def decode_best_spans(
self,
reader_input: BatchEncoding,
reader_output: DPRReaderOutput,
num_spans: int = 16,
max_answer_length: int = 64,
num_spans_per_passage: int = 4,
) -> List[DPRSpanPrediction]:
"""
Get the span predictions for the extractive Q&... |
Get the span predictions for the extractive Q&A model.
Returns: *List* of *DPRReaderOutput* sorted by descending *(relevance_score, span_score)*. Each
*DPRReaderOutput* is a *Tuple* with:
- **span_score**: `float` that corresponds to the score given by the reader for this span com... | decode_best_spans | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpr/tokenization_dpr_fast.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpr/tokenization_dpr_fast.py | Apache-2.0 |
def convert_dpt_checkpoint(checkpoint_url, pytorch_dump_folder_path, push_to_hub, model_name):
"""
Copy/paste/tweak model's weights to our DPT structure.
"""
# define DPT configuration based on URL
config, expected_shape = get_dpt_config(checkpoint_url)
# load original state_dict from URL
s... |
Copy/paste/tweak model's weights to our DPT structure.
| convert_dpt_checkpoint | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpt/convert_dpt_to_pytorch.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpt/convert_dpt_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/dpt/feature_extraction_dpt.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpt/feature_extraction_dpt.py | Apache-2.0 |
def post_process_semantic_segmentation(self, outputs, target_sizes: List[Tuple] = None):
"""
Converts the output of [`DPTForSemanticSegmentation`] into semantic segmentation maps. Only supports PyTorch.
Args:
outputs ([`DPTForSemanticSegmentation`]):
Raw outputs of t... |
Converts the output of [`DPTForSemanticSegmentation`] into semantic segmentation maps. Only supports PyTorch.
Args:
outputs ([`DPTForSemanticSegmentation`]):
Raw outputs of the model.
target_sizes (`List[Tuple]` of length `batch_size`, *optional*):
... | post_process_semantic_segmentation | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpt/feature_extraction_dpt.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpt/feature_extraction_dpt.py | Apache-2.0 |
def forward(self, hidden_states: List[torch.Tensor]) -> List[torch.Tensor]:
"""
Args:
hidden_states (`List[torch.FloatTensor]`, each of shape `(batch_size, sequence_length + 1, hidden_size)`):
List of hidden states from the backbone.
"""
out = []
for ... |
Args:
hidden_states (`List[torch.FloatTensor]`, each of shape `(batch_size, sequence_length + 1, hidden_size)`):
List of hidden states from the backbone.
| forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpt/modeling_dpt.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpt/modeling_dpt.py | Apache-2.0 |
def forward(
self,
pixel_values,
head_mask=None,
labels=None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
):
r"""
labels (`torch.LongTensor` of shape `(batch_size, height, width)`, *optional*):
Ground truth ... |
labels (`torch.LongTensor` of shape `(batch_size, height, width)`, *optional*):
Ground truth depth estimation maps for computing the loss.
Returns:
Examples:
```python
>>> from transformers import DPTFeatureExtractor, DPTForDepthEstimation
>>> import torch
... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/dpt/modeling_dpt.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpt/modeling_dpt.py | Apache-2.0 |
def forward(
self,
pixel_values=None,
head_mask=None,
labels=None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
):
r"""
labels (`torch.LongTensor` of shape `(batch_size, height, width)`, *optional*):
Ground t... |
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/dpt/modeling_dpt.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/dpt/modeling_dpt.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the ELECTRA loss. Input should be a sequence of tokens (see `input_ids` docstring)
Indices should be in `[0, 1]`:
- 0 indicates the token is an original token,
... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/electra/modeling_electra.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/electra/modeling_electra.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
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/electra/modeling_electra.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/electra/modeling_electra.py | Apache-2.0 |
def __call__(self, hidden_states, cls_index=None, deterministic: bool = True):
"""
Compute a single vector summary of a sequence hidden states.
Args:
hidden_states (`jnp.array` of shape `[batch_size, seq_len, hidden_size]`):
The hidden states of the last layer.
... |
Compute a single vector summary of a sequence hidden states.
Args:
hidden_states (`jnp.array` of shape `[batch_size, seq_len, hidden_size]`):
The hidden states of the last layer.
cls_index (`jnp.array` of shape `[batch_size]` or `[batch_size, ...]` where ... are... | __call__ | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/electra/modeling_flax_electra.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/electra/modeling_flax_electra.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,
position_ids: Optional[Union[np.ndarray, tf.Tensor]] = None,
head_mask: Optional[Uni... |
Returns:
Examples:
```python
>>> import tensorflow as tf
>>> from transformers import ElectraTokenizer, TFElectraForPreTraining
>>> tokenizer = ElectraTokenizer.from_pretrained("google/electra-small-discriminator")
>>> model = TFElectraForPreTraining.from_pret... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/electra/modeling_tf_electra.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/electra/modeling_tf_electra.py | Apache-2.0 |
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
"""
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A ELECTRA sequence has the following format:
- single sequence: `[CLS] X ... |
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A ELECTRA 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/electra/tokenization_electra_fast.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/electra/tokenization_electra_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]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A ELECTRA
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 ELECTRA
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/electra/tokenization_electra_fast.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/electra/tokenization_electra_fast.py | Apache-2.0 |
def from_encoder_decoder_configs(
cls, encoder_config: PretrainedConfig, decoder_config: PretrainedConfig, **kwargs
) -> PretrainedConfig:
r"""
Instantiate a [`EncoderDecoderConfig`] (or a derived class) from a pre-trained encoder model configuration and
decoder model configuration.
... |
Instantiate a [`EncoderDecoderConfig`] (or a derived class) from a pre-trained encoder model configuration and
decoder model configuration.
Returns:
[`EncoderDecoderConfig`]: An instance of a configuration object
| from_encoder_decoder_configs | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/configuration_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/configuration_encoder_decoder.py | Apache-2.0 |
def to_dict(self):
"""
Serializes this instance to a Python dictionary. Override the default *to_dict()* from *PretrainedConfig*.
Returns:
`Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
"""
output = copy.deepcopy(self.__d... |
Serializes this instance to a Python dictionary. Override the default *to_dict()* from *PretrainedConfig*.
Returns:
`Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
| to_dict | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/configuration_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/configuration_encoder_decoder.py | Apache-2.0 |
def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
r"""
Example:
```python
>>> from transformers import EncoderDecoderModel
>>> model = EncoderDecoderModel.from_pretrained("patrickvonplaten/bert2bert-cnn_dailymail-fp16")
```"""
from... |
Example:
```python
>>> from transformers import EncoderDecoderModel
>>> model = EncoderDecoderModel.from_pretrained("patrickvonplaten/bert2bert-cnn_dailymail-fp16")
``` | from_pretrained | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | Apache-2.0 |
def from_encoder_decoder_pretrained(
cls,
encoder_pretrained_model_name_or_path: str = None,
decoder_pretrained_model_name_or_path: str = None,
*model_args,
**kwargs
) -> PreTrainedModel:
r"""
Instantiate an encoder and a decoder from one or two base classes o... |
Instantiate an encoder and a decoder 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 training mode... | from_encoder_decoder_pretrained | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
encoder_outputs: Optional[Tuple[torch.Floa... |
Returns:
Examples:
```python
>>> from transformers import EncoderDecoderModel, BertTokenizer
>>> import torch
>>> tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
>>> model = EncoderDecoderModel.from_encoder_decoder_pretrained(
... "b... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | Apache-2.0 |
def encode(
self,
input_ids: jnp.ndarray,
attention_mask: Optional[jnp.ndarray] = None,
position_ids: Optional[jnp.ndarray] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
t... |
Returns:
Example:
```python
>>> from transformers import FlaxEncoderDecoderModel, BertTokenizer
>>> # initialize a bert2gpt2 from pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>> model = FlaxEncoderDecoderModel.fro... | encode | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | Apache-2.0 |
def decode(
self,
decoder_input_ids,
encoder_outputs,
encoder_attention_mask: Optional[jnp.ndarray] = None,
decoder_attention_mask: Optional[jnp.ndarray] = None,
decoder_position_ids: Optional[jnp.ndarray] = None,
past_key_values: dict = None,
output_atten... |
Returns:
Example:
```python
>>> from transformers import FlaxEncoderDecoderModel, BertTokenizer
>>> import jax.numpy as jnp
>>> # initialize a bert2gpt2 from pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>>... | decode | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | Apache-2.0 |
def __call__(
self,
input_ids: jnp.ndarray,
attention_mask: Optional[jnp.ndarray] = None,
decoder_input_ids: Optional[jnp.ndarray] = None,
decoder_attention_mask: Optional[jnp.ndarray] = None,
position_ids: Optional[jnp.ndarray] = None,
decoder_position_ids: Optio... |
Returns:
Examples:
```python
>>> from transformers import FlaxEncoderDecoderModel, BertTokenizer, GPT2Tokenizer
>>> # load a fine-tuned bert2gpt2 model
>>> model = FlaxEncoderDecoderModel.from_pretrained("patrickvonplaten/bert2gpt2-cnn_dailymail-fp16")
>>> # l... | __call__ | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | Apache-2.0 |
def from_encoder_decoder_pretrained(
cls,
encoder_pretrained_model_name_or_path: Optional[Union[str, os.PathLike]] = None,
decoder_pretrained_model_name_or_path: Optional[Union[str, os.PathLike]] = None,
*model_args,
**kwargs
) -> FlaxPreTrainedModel:
r"""
Ins... |
Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.
Params:
encoder_pretrained_model_name_or_path (`Union[str, os.PathLike]`, *optional*):
Information necessary to initiate the encoder. Can be either:
... | from_encoder_decoder_pretrained | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | Apache-2.0 |
def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
r"""
Example:
```python
>>> from transformers import TFEncoderDecoderModel
>>> model = TFEncoderDecoderModel.from_pretrained("ydshieh/bert2bert-cnn_dailymail-fp16")
```"""
from_pt =... |
Example:
```python
>>> from transformers import TFEncoderDecoderModel
>>> model = TFEncoderDecoderModel.from_pretrained("ydshieh/bert2bert-cnn_dailymail-fp16")
``` | from_pretrained | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | Apache-2.0 |
def from_encoder_decoder_pretrained(
cls,
encoder_pretrained_model_name_or_path: str = None,
decoder_pretrained_model_name_or_path: str = None,
*model_args,
**kwargs
) -> TFPreTrainedModel:
r"""
Instantiate an encoder and a decoder from one or two base classes... |
Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.
Params:
encoder_pretrained_model_name_or_path (`str`, *optional*):
Information necessary to initiate the encoder. Can be either:
... | from_encoder_decoder_pretrained | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | Apache-2.0 |
def call(
self,
input_ids=None,
attention_mask=None,
decoder_input_ids=None,
decoder_attention_mask=None,
encoder_outputs=None,
past_key_values=None,
inputs_embeds=None,
decoder_inputs_embeds=None,
labels=None,
use_cache=None,
... |
Returns:
Examples:
```python
>>> from transformers import TFEncoderDecoderModel, BertTokenizer
>>> # initialize a bert2gpt2 from a pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>> model = TFEncoderDecoderModel.from... | call | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
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 (maske... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/ernie/modeling_ernie.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
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/ernie/modeling_ernie.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def collate_dense_tensors(samples: List[torch.Tensor], pad_v: float = 0) -> torch.Tensor:
"""
Takes a list of tensors with the following dimensions:
[(d_11, ..., d_1K),
(d_21, ..., d_2K), ..., (d_N1, ..., d_NK)]
and stack + pads them into a single tensor of:
(N, max_i=1,N { d_i1 }, ...,... |
Takes a list of tensors with the following dimensions:
[(d_11, ..., d_1K),
(d_21, ..., d_2K), ..., (d_N1, ..., d_NK)]
and stack + pads them into a single tensor of:
(N, max_i=1,N { d_i1 }, ..., max_i=1,N {diK})
| collate_dense_tensors | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def __init__(
self,
in_dim: int,
out_dim: int,
bias: bool = True,
init: str = "default",
init_fn: Optional[Callable[[torch.Tensor, torch.Tensor], None]] = None,
):
"""
Args:
in_dim:
The final dimension of inputs to the layer... |
Args:
in_dim:
The final dimension of inputs to the layer
out_dim:
The final dimension of layer outputs
bias:
Whether to learn an additive bias. True by default
init:
The initializer to use. Choose fr... | __init__ | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def softmax_no_cast(t: torch.Tensor, dim: int = -1) -> torch.Tensor:
"""
Softmax, but without automatic casting to fp32 when the input is of type bfloat16
"""
d = t.dtype
if d is torch.bfloat16 and not is_deepspeed_initialized():
with torch.cuda.amp.autocast(enabled=False):
s = t... |
Softmax, but without automatic casting to fp32 when the input is of type bfloat16
| softmax_no_cast | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def __init__(
self,
c_q: int,
c_k: int,
c_v: int,
c_hidden: int,
no_heads: int,
gating: bool = True,
):
"""
Args:
c_q:
Input dimension of query data
c_k:
Input dimension of key data
... |
Args:
c_q:
Input dimension of query data
c_k:
Input dimension of key data
c_v:
Input dimension of value data
c_hidden:
Per-head hidden dimension
no_heads:
Number of attent... | __init__ | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(
self,
q_x: torch.Tensor,
kv_x: torch.Tensor,
biases: Optional[List[torch.Tensor]] = None,
use_memory_efficient_kernel: bool = False,
use_lma: bool = False,
lma_q_chunk_size: int = 1024,
lma_kv_chunk_size: int = 4096,
use_flash: bool = ... |
Args:
q_x:
[*, Q, C_q] query data
kv_x:
[*, K, C_k] key data
biases:
List of biases that broadcast to [*, H, Q, K]
use_memory_efficient_kernel:
Whether to use a custom memory-efficient attention kern... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def __init__(self, c_in, c_hidden, no_heads, starting=True, inf=1e9):
"""
Args:
c_in:
Input channel dimension
c_hidden:
Overall hidden channel dimension (not per-head)
no_heads:
Number of attention heads
"""
... |
Args:
c_in:
Input channel dimension
c_hidden:
Overall hidden channel dimension (not per-head)
no_heads:
Number of attention heads
| __init__ | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(
self,
x: torch.Tensor,
mask: Optional[torch.Tensor] = None,
chunk_size: Optional[int] = None,
use_memory_efficient_kernel: bool = False,
use_lma: bool = False,
inplace_safe: bool = False,
) -> torch.Tensor:
"""
Args:
x:... |
Args:
x:
[*, I, J, C_in] input tensor (e.g. the pair representation)
Returns:
[*, I, J, C_in] output tensor
| forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def _inference_forward(
self,
z: torch.Tensor,
mask: Optional[torch.Tensor] = None,
inplace_chunk_size: Optional[int] = None,
with_add: bool = True,
):
"""
Args:
z:
A [*, N, N, C_z] pair representation
mask:
... |
Args:
z:
A [*, N, N, C_z] pair representation
mask:
A [*, N, N] pair mask
inplace_chunk_size:
Size of chunks used in the main computation. Increase to trade memory for speed.
with_add:
If True, z is ... | _inference_forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(
self,
z: torch.Tensor,
mask: Optional[torch.Tensor] = None,
inplace_safe: bool = False,
_add_with_inplace: bool = False,
_inplace_chunk_size: Optional[int] = 256,
) -> torch.Tensor:
"""
Args:
x:
[*, N_res, N_res... |
Args:
x:
[*, N_res, N_res, C_z] input tensor
mask:
[*, N_res, N_res] input mask
Returns:
[*, N_res, N_res, C_z] output tensor
| forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(self, x, mask=None, bias=None, indices=None):
"""
Basic self attention with optional mask and external pairwise bias. To handle sequences of different lengths,
use mask.
Inputs:
x: batch of input sequneces (.. x L x C) mask: batch of boolean masks where 1=valid, ... |
Basic self attention with optional mask and external pairwise bias. To handle sequences of different lengths,
use mask.
Inputs:
x: batch of input sequneces (.. x L x C) mask: batch of boolean masks where 1=valid, 0=padding position (..
x L_k) bias: batch of scalar pairw... | forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(self, sequence_state, pairwise_state, mask=None, chunk_size=None, **__kwargs):
"""
Inputs:
sequence_state: B x L x sequence_state_dim pairwise_state: B x L x L x pairwise_state_dim mask: B x L boolean
tensor of valid positions
Output:
sequence_state: B ... |
Inputs:
sequence_state: B x L x sequence_state_dim pairwise_state: B x L x L x pairwise_state_dim mask: B x L boolean
tensor of valid positions
Output:
sequence_state: B x L x sequence_state_dim pairwise_state: B x L x L x pairwise_state_dim
| forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def get_axial_mask(mask):
"""
Helper to convert B x L mask of valid positions to axial mask used in row column attentions.
Input:
mask: B x L tensor of booleans
Output:
mask: B x L x L tensor of booleans
"""
if mask is None:
return None
if len(mask.shape) != 2:
... |
Helper to convert B x L mask of valid positions to axial mask used in row column attentions.
Input:
mask: B x L tensor of booleans
Output:
mask: B x L x L tensor of booleans
| get_axial_mask | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(self, residue_index, mask=None):
"""
Input:
residue_index: B x L tensor of indices (dytpe=torch.long) mask: B x L tensor of booleans
Output:
pairwise_state: B x L x L x pairwise_state_dim tensor of embeddings
"""
if residue_index.dtype != torch.lo... |
Input:
residue_index: B x L tensor of indices (dytpe=torch.long) mask: B x L tensor of booleans
Output:
pairwise_state: B x L x L x pairwise_state_dim tensor of embeddings
| forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(self, s: torch.Tensor, s_initial: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
"""
Args:
s:
[*, C_hidden] single embedding
s_initial:
[*, C_hidden] single embedding as of the start of the StructureModule
Returns:
... |
Args:
s:
[*, C_hidden] single embedding
s_initial:
[*, C_hidden] single embedding as of the start of the StructureModule
Returns:
[*, no_angles, 2] predicted angles
| forward | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.