code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Union[Cache, Tuple[Tuple[torch.Tensor]]]] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch... |
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_dim)`, *optional*):
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_ids* indices in... | forward | python | huggingface/transformers | src/transformers/models/codegen/modeling_codegen.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/codegen/modeling_codegen.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Union[Cache, Tuple[Tuple[torch.Tensor]]]] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch... |
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_dim)`, *optional*):
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_ids* indices in... | forward | python | huggingface/transformers | src/transformers/models/codegen/modeling_codegen.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/codegen/modeling_codegen.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 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 sequence
pair mask has the following format:
```
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
```
If `token_ids_1` is `None`, thi... | create_token_type_ids_from_sequences | python | huggingface/transformers | src/transformers/models/codegen/tokenization_codegen.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/codegen/tokenization_codegen.py | Apache-2.0 |
def __init__(self, hidden_size=None, eps=1e-5, bias=False):
"""The hidden size can be a tuple or an int. The tuple is used for QKNorm to normalize across head_dim"""
super().__init__()
self.weight = nn.Parameter(torch.ones(hidden_size))
self.variance_epsilon = eps | The hidden size can be a tuple or an int. The tuple is used for QKNorm to normalize across head_dim | __init__ | python | huggingface/transformers | src/transformers/models/cohere/modeling_cohere.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cohere/modeling_cohere.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_value: Optional[Cache] = None,
output_attentions: Optional[bool] = False,
use_cache: Optional[bool] = False,
... |
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`, *optional*):
attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
qu... | forward | python | huggingface/transformers | src/transformers/models/cohere/modeling_cohere.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cohere/modeling_cohere.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
inputs_embeds: Optional[torch.FloatTen... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/cohere/modeling_cohere.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cohere/modeling_cohere.py | Apache-2.0 |
def apply_tool_use_template(
self,
conversation: Union[List[Dict[str, str]]],
tools: List[Dict],
**kwargs,
) -> Union[str, List[int]]:
"""Create a Command-R tool-use prompt.
Once rendered, the prompt instructs the model to generate a list of actions to perform on a s... | Create a Command-R tool-use prompt.
Once rendered, the prompt instructs the model to generate a list of actions to perform on a set of user supplied tools
to help carry out the user's requests.
Conceptually, this works in the same way as `apply_chat_format`, but takes an additional `tools` par... | apply_tool_use_template | python | huggingface/transformers | src/transformers/models/cohere/tokenization_cohere_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cohere/tokenization_cohere_fast.py | Apache-2.0 |
def apply_grounded_generation_template(
self,
conversation: Union[List[Dict[str, str]]],
documents: List[Dict],
citation_mode: Literal["fast", "accurate"] = "accurate",
**kwargs,
) -> Union[str, List[int]]:
"""Create a Command-R grounded generation (aka RAG) prompt.
... | Create a Command-R grounded generation (aka RAG) prompt.
Once rendered, the prompt instructs the model to generate a response with citations in, based on supplied documents.
Conceptually, this works in the same way as `apply_chat_format`, but takes additional `documents`
and parameter `citatio... | apply_grounded_generation_template | python | huggingface/transformers | src/transformers/models/cohere/tokenization_cohere_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cohere/tokenization_cohere_fast.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
attention_mask: Optional[torch.Tensor] = None,
past_key_value: Optional[Cache] = None,
output_attentions: Optional[bool] = False,
use_cache: Optional[bool] = Fa... |
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
position_embeddings (`Tuple[torch.FloatTensor, torch.FloatTensor]`):
Tuple containing the cosine and sine positional embeddings of shape `(batch_size, seq_len, head_dim)`... | forward | python | huggingface/transformers | src/transformers/models/cohere2/modeling_cohere2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cohere2/modeling_cohere2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
inputs_embeds: Optional[torch.FloatTen... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/cohere2/modeling_cohere2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cohere2/modeling_cohere2.py | Apache-2.0 |
def __call__(
self,
images: ImageInput = None,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
audio=None,
videos=None,
**kwargs: Unpack[ColPaliProcessorKwargs],
) -> BatchFeature:
"""
Main method to prepare ... |
Main method to prepare for the model either (1) one or several texts, either (2) one or several image(s). This method is a custom
wrapper around the PaliGemmaProcessor's [`~PaliGemmaProcessor.__call__`] method adapted for the ColPali model. It cannot process
both text and images at the same tim... | __call__ | python | huggingface/transformers | src/transformers/models/colpali/modular_colpali.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colpali/modular_colpali.py | Apache-2.0 |
def process_images(
self,
images: ImageInput = None,
**kwargs: Unpack[ColPaliProcessorKwargs],
) -> BatchFeature:
"""
Prepare for the model one or several image(s). This method is a wrapper around the `__call__` method of the ColPaliProcessor's
[`ColPaliProcessor.__ca... |
Prepare for the model one or several image(s). This method is a wrapper around the `__call__` method of the ColPaliProcessor's
[`ColPaliProcessor.__call__`].
This method forwards the `images` and `kwargs` arguments to the image processor.
Args:
images (`PIL.Image.Image`, `... | process_images | python | huggingface/transformers | src/transformers/models/colpali/modular_colpali.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colpali/modular_colpali.py | Apache-2.0 |
def process_queries(
self,
text: Union[TextInput, List[TextInput]],
**kwargs: Unpack[ColPaliProcessorKwargs],
) -> BatchFeature:
"""
Prepare for the model one or several texts. This method is a wrapper around the `__call__` method of the ColPaliProcessor's
[`ColPaliPr... |
Prepare for the model one or several texts. This method is a wrapper around the `__call__` method of the ColPaliProcessor's
[`ColPaliProcessor.__call__`].
This method forwards the `text` and `kwargs` arguments to the tokenizer.
Args:
text (`str`, `List[str]`, `List[List[st... | process_queries | python | huggingface/transformers | src/transformers/models/colpali/modular_colpali.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colpali/modular_colpali.py | Apache-2.0 |
def score_retrieval(
self,
query_embeddings: Union["torch.Tensor", List["torch.Tensor"]],
passage_embeddings: Union["torch.Tensor", List["torch.Tensor"]],
batch_size: int = 128,
output_dtype: Optional["torch.dtype"] = None,
output_device: Union["torch.device", str] = "cpu... |
Compute the late-interaction/MaxSim score (ColBERT-like) for the given multi-vector
query embeddings (`qs`) and passage embeddings (`ps`). For ColPali, a passage is the
image of a document page.
Because the embedding tensors are multi-vector and can thus have different shapes, they
... | score_retrieval | python | huggingface/transformers | src/transformers/models/colpali/modular_colpali.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colpali/modular_colpali.py | Apache-2.0 |
def _get_num_multimodal_tokens(self, image_sizes=None, **kwargs):
"""
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (List[List[str]], *optional*):
The input sizes formatted as (height, width) per each i... |
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (List[List[str]], *optional*):
The input sizes formatted as (height, width) per each image.
Returns:
Dict[str, List[int]]: A dictionary mapping... | _get_num_multimodal_tokens | python | huggingface/transformers | src/transformers/models/colpali/processing_colpali.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colpali/processing_colpali.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[List[torch.FloatTensor]] = None,
labels: Optional[torch.LongTensor] = None,
i... |
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
The temporal, height and width of feature shape of each image in LLM.
| forward | python | huggingface/transformers | src/transformers/models/colqwen2/modeling_colqwen2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colqwen2/modeling_colqwen2.py | Apache-2.0 |
def __call__(
self,
images: ImageInput = None,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
audio=None,
videos=None,
**kwargs: Unpack[ColQwen2ProcessorKwargs],
) -> BatchFeature:
"""
Main method to prepare... |
Main method to prepare for the model either (1) one or several texts, either (2) one or several image(s). This method is a custom
wrapper around the Qwen2VLProcessor's [`~Qwen2VLProcessor.__call__`] method adapted for the ColQwen2 model. It cannot process
both text and images at the same time.
... | __call__ | python | huggingface/transformers | src/transformers/models/colqwen2/modular_colqwen2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colqwen2/modular_colqwen2.py | Apache-2.0 |
def process_images(
self,
images: ImageInput = None,
**kwargs: Unpack[ColQwen2ProcessorKwargs],
) -> BatchFeature:
"""
Prepare for the model one or several image(s). This method is a wrapper around the `__call__` method of the ColQwen2Processor's
[`ColQwen2Processor._... |
Prepare for the model one or several image(s). This method is a wrapper around the `__call__` method of the ColQwen2Processor's
[`ColQwen2Processor.__call__`].
This method forwards the `images` and `kwargs` arguments to the image processor.
Args:
images (`PIL.Image.Image`,... | process_images | python | huggingface/transformers | src/transformers/models/colqwen2/processing_colqwen2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colqwen2/processing_colqwen2.py | Apache-2.0 |
def process_queries(
self,
text: Union[TextInput, List[TextInput]],
**kwargs: Unpack[ColQwen2ProcessorKwargs],
) -> BatchFeature:
"""
Prepare for the model one or several texts. This method is a wrapper around the `__call__` method of the ColQwen2Processor's
[`ColQwen... |
Prepare for the model one or several texts. This method is a wrapper around the `__call__` method of the ColQwen2Processor's
[`ColQwen2Processor.__call__`].
This method forwards the `text` and `kwargs` arguments to the tokenizer.
Args:
text (`str`, `List[str]`, `List[List[... | process_queries | python | huggingface/transformers | src/transformers/models/colqwen2/processing_colqwen2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colqwen2/processing_colqwen2.py | Apache-2.0 |
def score_retrieval(
self,
query_embeddings: Union["torch.Tensor", List["torch.Tensor"]],
passage_embeddings: Union["torch.Tensor", List["torch.Tensor"]],
batch_size: int = 128,
output_dtype: Optional["torch.dtype"] = None,
output_device: Union["torch.device", str] = "cpu... |
Compute the late-interaction/MaxSim score (ColBERT-like) for the given multi-vector
query embeddings (`qs`) and passage embeddings (`ps`). For ColQwen2, a passage is the
image of a document page.
Because the embedding tensors are multi-vector and can thus have different shapes, they
... | score_retrieval | python | huggingface/transformers | src/transformers/models/colqwen2/processing_colqwen2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/colqwen2/processing_colqwen2.py | Apache-2.0 |
def get_image_size_for_max_height_width(
input_image: np.ndarray,
max_height: int,
max_width: int,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
) -> Tuple[int, int]:
"""
Computes the output image size given the input image and the maximum allowed height and width. Keep aspec... |
Computes the output image size given the input image and the maximum allowed height and width. Keep aspect ratio.
Important, even if image_height < max_height and image_width < max_width, the image will be resized
to at least one of the edges be equal to max_height or max_width.
For example:
-... | get_image_size_for_max_height_width | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr.py | Apache-2.0 |
def post_process_panoptic_sample(
out_logits: np.ndarray,
masks: np.ndarray,
boxes: np.ndarray,
processed_size: Tuple[int, int],
target_size: Tuple[int, int],
is_thing_map: Dict,
threshold=0.85,
) -> Dict:
"""
Converts the output of [`ConditionalDetrForSegmentation`] into panoptic se... |
Converts the output of [`ConditionalDetrForSegmentation`] into panoptic segmentation predictions for a single sample.
Args:
out_logits (`torch.Tensor`):
The logits for this sample.
masks (`torch.Tensor`):
The predicted segmentation masks for this sample.
boxes (... | post_process_panoptic_sample | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr.py | Apache-2.0 |
def resize(
self,
image: np.ndarray,
size: Dict[str, int],
resample: PILImageResampling = PILImageResampling.BILINEAR,
data_format: Optional[ChannelDimension] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> np.ndarray:
... |
Resize the image to the given size. Size can be `min_size` (scalar) or `(height, width)` tuple. If size is an
int, smaller edge of the image will be matched to this number.
Args:
image (`np.ndarray`):
Image to resize.
size (`Dict[str, int]`):
... | resize | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr.py | Apache-2.0 |
def _update_annotation_for_padded_image(
self,
annotation: Dict,
input_image_size: Tuple[int, int],
output_image_size: Tuple[int, int],
padding,
update_bboxes,
) -> Dict:
"""
Update the annotation for a padded image.
"""
new_annotation ... |
Update the annotation for a padded image.
| _update_annotation_for_padded_image | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr.py | Apache-2.0 |
def pad(
self,
images: List[np.ndarray],
annotations: Optional[Union[AnnotationType, List[AnnotationType]]] = None,
constant_values: Union[float, Iterable[float]] = 0,
return_pixel_mask: bool = True,
return_tensors: Optional[Union[str, TensorType]] = None,
data_fo... |
Pads a batch of images to the bottom and right of the image with zeros to the size of largest height and width
in the batch and optionally returns their corresponding pixel mask.
Args:
images (List[`np.ndarray`]):
Images to pad.
annotations (`AnnotationT... | pad | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
annotations: Optional[Union[AnnotationType, List[AnnotationType]]] = None,
return_segmentation_masks: Optional[bool] = None,
masks_path: Optional[Union[str, pathlib.Path]] = None,
do_resize: Optional[bool] = None,
size: Op... |
Preprocess an image or a batch of images so that it can be used by the model.
Args:
images (`ImageInput`):
Image or batch of images to preprocess. Expects a single or batch of images with pixel values ranging
from 0 to 255. If passing in images with pixel va... | preprocess | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr.py | Apache-2.0 |
def post_process(self, outputs, target_sizes):
"""
Converts the output of [`ConditionalDetrForObjectDetection`] into the format expected by the Pascal VOC format (xmin, ymin, xmax, ymax).
Only supports PyTorch.
Args:
outputs ([`ConditionalDetrObjectDetectionOutput`]):
... |
Converts the output of [`ConditionalDetrForObjectDetection`] into the format expected by the Pascal VOC format (xmin, ymin, xmax, ymax).
Only supports PyTorch.
Args:
outputs ([`ConditionalDetrObjectDetectionOutput`]):
Raw outputs of the model.
target_siz... | post_process | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr.py | Apache-2.0 |
def post_process_semantic_segmentation(self, outputs, target_sizes: Optional[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*):
A ... | post_process_semantic_segmentation | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_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 | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_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 | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr.py | Apache-2.0 |
def prepare_coco_detection_annotation(
image,
target,
return_segmentation_masks: bool = False,
input_data_format: Optional[Union[ChannelDimension, str]] = None,
):
"""
Convert the target in COCO format into the format expected by CONDITIONAL_DETR.
"""
image_height, image_width = image.si... |
Convert the target in COCO format into the format expected by CONDITIONAL_DETR.
| prepare_coco_detection_annotation | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | Apache-2.0 |
def from_dict(cls, image_processor_dict: Dict[str, Any], **kwargs):
"""
Overrides the `from_dict` method from the base class to make sure parameters are updated if image processor is
created using from_dict and kwargs e.g. `ConditionalDetrImageProcessorFast.from_pretrained(checkpoint, size=600,
... |
Overrides the `from_dict` method from the base class to make sure parameters are updated if image processor is
created using from_dict and kwargs e.g. `ConditionalDetrImageProcessorFast.from_pretrained(checkpoint, size=600,
max_size=800)`
| from_dict | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | Apache-2.0 |
def prepare_annotation(
self,
image: torch.Tensor,
target: Dict,
format: Optional[AnnotationFormat] = None,
return_segmentation_masks: Optional[bool] = None,
masks_path: Optional[Union[str, pathlib.Path]] = None,
input_data_format: Optional[Union[str, ChannelDimen... |
Prepare an annotation for feeding into CONDITIONAL_DETR model.
| prepare_annotation | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | Apache-2.0 |
def resize(
self,
image: torch.Tensor,
size: SizeDict,
interpolation: "F.InterpolationMode" = None,
**kwargs,
) -> torch.Tensor:
"""
Resize the image to the given size. Size can be `min_size` (scalar) or `(height, width)` tuple. If size is an
int, smal... |
Resize the image to the given size. Size can be `min_size` (scalar) or `(height, width)` tuple. If size is an
int, smaller edge of the image will be matched to this number.
Args:
image (`torch.Tensor`):
Image to resize.
size (`SizeDict`):
... | resize | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | Apache-2.0 |
def resize_annotation(
self,
annotation: Dict[str, Any],
orig_size: Tuple[int, int],
target_size: Tuple[int, int],
threshold: float = 0.5,
interpolation: "F.InterpolationMode" = None,
):
"""
Resizes an annotation to a target size.
Args:
... |
Resizes an annotation to a target size.
Args:
annotation (`Dict[str, Any]`):
The annotation dictionary.
orig_size (`Tuple[int, int]`):
The original size of the input image.
target_size (`Tuple[int, int]`):
The target s... | resize_annotation | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
annotations: Optional[Union[AnnotationType, List[AnnotationType]]] = None,
masks_path: Optional[Union[str, pathlib.Path]] = None,
**kwargs: Unpack[ConditionalDetrFastImageProcessorKwargs],
) -> BatchFeature:
r"""
annot... |
annotations (`AnnotationType` or `List[AnnotationType]`, *optional*):
List of annotations associated with the image or batch of images. If annotation is for object
detection, the annotations should be a dictionary with the following keys:
- "image_id" (`int`): The image id.
... | preprocess | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | Apache-2.0 |
def _preprocess(
self,
images: List["torch.Tensor"],
annotations: Optional[Union[AnnotationType, List[AnnotationType]]],
masks_path: Optional[Union[str, pathlib.Path]],
return_segmentation_masks: bool,
do_resize: bool,
size: SizeDict,
interpolation: Option... |
Preprocess an image or a batch of images so that it can be used by the model.
| _preprocess | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | Apache-2.0 |
def post_process_object_detection(
self, outputs, threshold: float = 0.5, target_sizes: Union[TensorType, List[Tuple]] = None, top_k: int = 100
):
"""
Converts the raw output of [`ConditionalDetrForObjectDetection`] into final bounding boxes in (top_left_x,
top_left_y, bottom_right_x... |
Converts the raw output of [`ConditionalDetrForObjectDetection`] into final bounding boxes in (top_left_x,
top_left_y, bottom_right_x, bottom_right_y) format. Only supports PyTorch.
Args:
outputs ([`ConditionalDetrObjectDetectionOutput`]):
Raw outputs of the model.
... | post_process_object_detection | python | huggingface/transformers | src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/image_processing_conditional_detr_fast.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
de... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/conditional_detr/modeling_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/modeling_conditional_detr.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
de... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/conditional_detr/modeling_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/modeling_conditional_detr.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
d... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/conditional_detr/modeling_conditional_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/conditional_detr/modeling_conditional_detr.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,
... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/convbert/modeling_convbert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/convbert/modeling_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 | huggingface/transformers | src/transformers/models/convbert/tokenization_convbert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/convbert/tokenization_convbert.py | Apache-2.0 |
def resize(
self,
image: "torch.Tensor",
size: Dict[str, int],
crop_pct: float,
interpolation: PILImageResampling = PILImageResampling.BICUBIC,
**kwargs,
) -> "torch.Tensor":
"""
Resize an image.
Args:
image (`torch.Tensor`):
... |
Resize an image.
Args:
image (`torch.Tensor`):
Image to resize.
size (`Dict[str, int]`):
Dictionary of the form `{"shortest_edge": int}`, specifying the size of the output image. If
`size["shortest_edge"]` >= 384 image is resized ... | resize | python | huggingface/transformers | src/transformers/models/convnext/image_processing_convnext_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/convnext/image_processing_convnext_fast.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.Tensor,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> imp... |
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> import torch
>>> from PIL import Image
>>> import requests
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, ... | forward | python | huggingface/transformers | src/transformers/models/convnext/modeling_convnext.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/convnext/modeling_convnext.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.Tensor,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> imp... |
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> import torch
>>> from PIL import Image
>>> import requests
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, ... | forward | python | huggingface/transformers | src/transformers/models/convnextv2/modeling_convnextv2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/convnextv2/modeling_convnextv2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
use_cache: Optional[bool] = None,
return_dict: Optiona... |
input_ids (`torch.Tensor` of shape `(batch_size, seq_len)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`CPMAntTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
[What are in... | forward | python | huggingface/transformers | src/transformers/models/cpmant/modeling_cpmant.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cpmant/modeling_cpmant.py | Apache-2.0 |
def permute_for_rope(input_tensor, n_heads, dim1, dim2):
"""
When you go from the complex ROPE formulation to sin and cos one, you need
to permute the query and key weights (to avoid doing it on the fly)
"""
input_tensor = input_tensor.reshape(dim1, dim2)
input_tensor = input_tensor.view(n_heads... |
When you go from the complex ROPE formulation to sin and cos one, you need
to permute the query and key weights (to avoid doing it on the fly)
| permute_for_rope | python | huggingface/transformers | src/transformers/models/csm/convert_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/convert_csm.py | Apache-2.0 |
def load_llama3_tokenizer():
"""
https://github.com/huggingface/transformers/issues/22794#issuecomment-2092623992
"""
tokenizer_name = "meta-llama/Llama-3.2-1B"
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
bos = tokenizer.bos_token
eos = tokenizer.eos... | ERROR: type should be string, got "\n https://github.com/huggingface/transformers/issues/22794#issuecomment-2092623992\n " | load_llama3_tokenizer | python | huggingface/transformers | src/transformers/models/csm/convert_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/convert_csm.py | Apache-2.0 |
def _prepare_generation_config(
self, generation_config: Optional[GenerationConfig], use_model_defaults: Optional[bool] = None, **kwargs: Dict
) -> Tuple[GenerationConfig, Dict]:
"""
This method overrides [~generation.utils.GenerationMixin._prepare_generation_config].
It ensures that... |
This method overrides [~generation.utils.GenerationMixin._prepare_generation_config].
It ensures that the depth decoder generation config is initialized and that passed args as depth_decoder_* are properly handled.
| _prepare_generation_config | python | huggingface/transformers | src/transformers/models/csm/generation_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/generation_csm.py | Apache-2.0 |
def _sample(
self,
input_ids: torch.LongTensor,
logits_processor: LogitsProcessorList,
stopping_criteria: StoppingCriteriaList,
generation_config: GenerationConfig,
synced_gpus: bool,
streamer: Optional["BaseStreamer"],
**model_kwargs,
) -> Union[Gener... |
This method overrides [~generation.utils.GenerationMixin._sample].
To ease maintenance, modifications are marked with the comment "Csm specific".
Indeed, Csm model requires a custom generation sampling step:
1. Infer the backbone model to sample the first codebook token
2. Call... | _sample | python | huggingface/transformers | src/transformers/models/csm/generation_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/generation_csm.py | Apache-2.0 |
def generate(
self,
input_ids: Optional[torch.Tensor] = None,
input_values: Optional[torch.Tensor] = None,
input_values_cutoffs: Optional[torch.Tensor] = None,
generation_config: Optional[GenerationConfig] = None,
logits_processor: Optional[LogitsProcessorList] = None,
... |
This method overrides [`~generation.utils.GenerationMixin.generate`] to match the specifics of the Csm model.
Indeed, Csm model requires a custom generation sampling step:
1. Infer the backbone model to sample the first codebook token
2. Call generate on the depth decoder with the first... | generate | python | huggingface/transformers | src/transformers/models/csm/generation_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/generation_csm.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
backbone_last_hidden_state: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_e... |
backbone_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, backbone_hidden_size)`, *optional*):
The last hidden state of the backbone model. Such input is required when the first codebook token (the one generated by the backbone model)
is provided in the `input_ids` argument... | forward | python | huggingface/transformers | src/transformers/models/csm/modeling_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/modeling_csm.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
backbone_last_hidden_state: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Union[Cache, List[torch.FloatTe... |
backbone_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, backbone_hidden_size)`, *optional*):
The last hidden state of the backbone model. Such input is required when the first codebook token (the one generated by the backbone model)
is provided in the `input_ids` argument... | forward | python | huggingface/transformers | src/transformers/models/csm/modeling_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/modeling_csm.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
use_cache: ... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, num_codebooks) or (batch_size, sequence_length)`):
1. (batch_size, sequence_length): corresponds to the input sequence prepared with the processor from the text prompt. Such input
requires `input_values` to be provide... | forward | python | huggingface/transformers | src/transformers/models/csm/modeling_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/modeling_csm.py | Apache-2.0 |
def _merge_input_ids_with_input_values(
self,
input_ids: Optional[torch.Tensor] = None,
input_values: Optional[torch.Tensor] = None,
input_values_cutoffs: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
) -> Optional[torch.Tensor]:
"""
Me... |
Merges the input_ids and input_values to produce a single inputs_embeds tensor:
1 - Infers the codec model on the input_values to retreive codebook token.
2 - Embeds codebook tokens and places them at the correct positions in the inputs_embeds tensor.
3 - If labels are provided, expands... | _merge_input_ids_with_input_values | python | huggingface/transformers | src/transformers/models/csm/modeling_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/modeling_csm.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
input_values: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
input_values_cutoffs: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, num_codebooks) or (batch_size, sequence_length)`):
1. (batch_size, sequence_length): corresponds to the input sequence prepared with the processor from the text prompt. Such input
requires `input_values` to be provide... | forward | python | huggingface/transformers | src/transformers/models/csm/modeling_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/modeling_csm.py | Apache-2.0 |
def _get_encoded_length(audio_length, kernel_sizes=None, strides=None, dilations=None, use_causal_conv=None):
"""
Compute the length of the encoded audio sequence.
Args:
audio_length (int): The length of the audio sequence.
kernel_sizes (List[int]): The kernel sizes for ... |
Compute the length of the encoded audio sequence.
Args:
audio_length (int): The length of the audio sequence.
kernel_sizes (List[int]): The kernel sizes for the convolutional layers.
strides (List[int]): The strides for the convolutional layers.
use_caus... | _get_encoded_length | python | huggingface/transformers | src/transformers/models/csm/processing_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/processing_csm.py | Apache-2.0 |
def __call__(
self,
text: Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]],
audio: Optional[AudioInput] = None,
output_labels: Optional[bool] = False,
depth_decoder_labels_ratio: Optional[float] = 1.0,
**kwargs: Unpack[CsmProcessorKw... |
Main method to prepare text(s) and audio to be fed as input to the model. This method forwards the `text`
arguments to PreTrainedTokenizerFast's [`~PreTrainedTokenizerFast.__call__`] to encode
the text. To prepare the audio, this method forwards the `audio` arguments to
EncodecFeatureEx... | __call__ | python | huggingface/transformers | src/transformers/models/csm/processing_csm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/csm/processing_csm.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... |
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else `past_key_values[0].shape[-2]`
(`sequence_length` of input past key value states). Indices of input sequence tokens in the vocabulary.
... | forward | python | huggingface/transformers | src/transformers/models/ctrl/modeling_ctrl.py | https://github.com/huggingface/transformers/blob/master/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... |
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else `past_key_values[0].shape[-2]`
(`sequence_length` of input past key value states). Indices of input sequence tokens in the vocabulary.
... | forward | python | huggingface/transformers | src/transformers/models/ctrl/modeling_ctrl.py | https://github.com/huggingface/transformers/blob/master/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... |
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else `past_key_values[0].shape[-2]`
(`sequence_length` of input past key value states). Indices of input sequence tokens in the vocabulary.
... | forward | python | huggingface/transformers | src/transformers/models/ctrl/modeling_ctrl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ctrl/modeling_ctrl.py | Apache-2.0 |
def convert_cvt_checkpoint(cvt_model, image_size, cvt_file_name, pytorch_dump_folder):
"""
Function 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... |
Function to convert the microsoft cvt checkpoint to huggingface checkpoint
| convert_cvt_checkpoint | python | huggingface/transformers | src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/cvt/convert_cvt_original_pytorch_checkpoint_to_pytorch.py | Apache-2.0 |
def replace_batch_norm(model):
r"""
Recursively replace all `torch.nn.BatchNorm2d` with `DabDetrFrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
"""
for name, module in model.named_children():
if isinstance(module, nn.BatchNorm2d):
new_module = ... |
Recursively replace all `torch.nn.BatchNorm2d` with `DabDetrFrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
| replace_batch_norm | python | huggingface/transformers | src/transformers/models/dab_detr/modeling_dab_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dab_detr/modeling_dab_detr.py | Apache-2.0 |
def gen_sine_position_embeddings(pos_tensor, hidden_size=256):
"""
This function computes position embeddings using sine and cosine functions from the input positional tensor,
which has a shape of (batch_size, num_queries, 4).
The last dimension of `pos_tensor` represents the following coordinates:
... |
This function computes position embeddings using sine and cosine functions from the input positional tensor,
which has a shape of (batch_size, num_queries, 4).
The last dimension of `pos_tensor` represents the following coordinates:
- 0: x-coord
- 1: y-coord
- 2: width
- 3: height
The ... | gen_sine_position_embeddings | python | huggingface/transformers | src/transformers/models/dab_detr/modeling_dab_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dab_detr/modeling_dab_detr.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: torch.Tensor,
object_queries: torch.Tensor,
output_attentions: Optional[bool] = None,
):
"""
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, em... |
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, source_len)` where padding elements are indicated by very large negative
values.
... | forward | python | huggingface/transformers | src/transformers/models/dab_detr/modeling_dab_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dab_detr/modeling_dab_detr.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
object_queries: Optional[torch.Tensor] = None,
query_position_embeddings: Optional[torch.Tensor] = None,
query_sine_embed: Optional[torch.Tensor] = None,
encoder_hidden_... |
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, target_len, source_len)` where padding elements are indicated by very large negative
... | forward | python | huggingface/transformers | src/transformers/models/dab_detr/modeling_dab_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dab_detr/modeling_dab_detr.py | Apache-2.0 |
def forward(
self,
inputs_embeds,
attention_mask,
object_queries,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
):
r"""
Args:
inputs_embeds (`torch.FloatTe... |
Args:
inputs_embeds (`torch.FloatTensor` of shape `(sequence_length, batch_size, 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 | huggingface/transformers | src/transformers/models/dab_detr/modeling_dab_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dab_detr/modeling_dab_detr.py | Apache-2.0 |
def forward(
self,
inputs_embeds,
encoder_hidden_states,
memory_key_padding_mask,
object_queries,
query_position_embeddings,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
... |
Args:
inputs_embeds (`torch.FloatTensor` of shape `(sequence_length, batch_size, hidden_size)`):
The query embeddings that are passed into the decoder.
encoder_hidden_states (`torch.FloatTensor` of shape `(encoder_sequence_length, batch_size, hidden_size)`, *optional*):
... | forward | python | huggingface/transformers | src/transformers/models/dab_detr/modeling_dab_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dab_detr/modeling_dab_detr.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
de... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/dab_detr/modeling_dab_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dab_detr/modeling_dab_detr.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
de... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/dab_detr/modeling_dab_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dab_detr/modeling_dab_detr.py | Apache-2.0 |
def __call__(
self,
raw_audio: Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]],
padding: Optional[Union[bool, str, PaddingStrategy]] = None,
truncation: Optional[bool] = False,
max_length: Optional[int] = None,
return_tensors: Optional[Union[str, Tenso... |
Main method to featurize and prepare for the model one or several sequence(s).
Args:
raw_audio (`np.ndarray`, `List[float]`, `List[np.ndarray]`, `List[List[float]]`):
The sequence or batch of sequences to be processed. Each sequence can be a numpy array, a list of float
... | __call__ | python | huggingface/transformers | src/transformers/models/dac/feature_extraction_dac.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dac/feature_extraction_dac.py | Apache-2.0 |
def forward(self, hidden_state):
"""
Forward pass through the residual unit.
Args:
hidden_state (`torch.Tensor` of shape `(batch_size, channels, time_steps)`):
Input tensor .
Returns:
output_tensor (`torch.Tensor` of shape `(batch_size, channels,... |
Forward pass through the residual unit.
Args:
hidden_state (`torch.Tensor` of shape `(batch_size, channels, time_steps)`):
Input tensor .
Returns:
output_tensor (`torch.Tensor` of shape `(batch_size, channels, time_steps)`):
Input tensor... | forward | python | huggingface/transformers | src/transformers/models/dac/modeling_dac.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dac/modeling_dac.py | Apache-2.0 |
def from_codes(self, audio_codes: torch.Tensor):
"""
Reconstructs the continuous representation from quantized codes.
Args:
audio_codes (`torch.Tensor` of shape `(batch_size, num_codebooks, time_steps)`):
Quantized discrete representation of input.
Returns:
... |
Reconstructs the continuous representation from quantized codes.
Args:
audio_codes (`torch.Tensor` of shape `(batch_size, num_codebooks, time_steps)`):
Quantized discrete representation of input.
Returns:
quantized_representation (`torch.Tensor`):
... | from_codes | python | huggingface/transformers | src/transformers/models/dac/modeling_dac.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dac/modeling_dac.py | Apache-2.0 |
def from_latents(self, latents: torch.Tensor):
"""Reconstructs the quantized representation from unquantized latents.
Args:
latents (`torch.Tensor` of shape `(batch_size, total_latent_dimension, time_steps)`):
Continuous representation of input after projection.
Ret... | Reconstructs the quantized representation from unquantized latents.
Args:
latents (`torch.Tensor` of shape `(batch_size, total_latent_dimension, time_steps)`):
Continuous representation of input after projection.
Returns:
quantized_representation (`torch.Tensor`... | from_latents | python | huggingface/transformers | src/transformers/models/dac/modeling_dac.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dac/modeling_dac.py | Apache-2.0 |
def encode(
self,
input_values: torch.Tensor,
n_quantizers: Optional[int] = None,
return_dict: Optional[bool] = None,
):
r"""
input_values (`torch.Tensor of shape `(batch_size, 1, time_steps)`):
Input audio data to encode,
n_quantizers (int, *optio... |
input_values (`torch.Tensor of shape `(batch_size, 1, time_steps)`):
Input audio data to encode,
n_quantizers (int, *optional*):
Number of quantizers to use. If None, all quantizers are used. Default is None.
| encode | python | huggingface/transformers | src/transformers/models/dac/modeling_dac.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dac/modeling_dac.py | Apache-2.0 |
def decode(
self,
quantized_representation: Optional[torch.Tensor] = None,
audio_codes: Optional[torch.Tensor] = None,
return_dict: Optional[bool] = None,
):
r"""
quantized_representation (torch.Tensor of shape `(batch_size, dimension, time_steps)`, *optional*):
... |
quantized_representation (torch.Tensor of shape `(batch_size, dimension, time_steps)`, *optional*):
Quantized continuous representation of input.
audio_codes (`torch.Tensor` of shape `(batch_size, num_codebooks, time_steps)`, *optional*):
The codebook indices for each codebook, ... | decode | python | huggingface/transformers | src/transformers/models/dac/modeling_dac.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dac/modeling_dac.py | Apache-2.0 |
def forward(
self,
input_values: torch.Tensor,
n_quantizers: Optional[int] = None,
return_dict: Optional[bool] = None,
):
r"""
input_values (`torch.Tensor` of shape `(batch_size, 1, time_steps)`):
Audio data to encode.
n_quantizers (`int`, *optiona... |
input_values (`torch.Tensor` of shape `(batch_size, 1, time_steps)`):
Audio data to encode.
n_quantizers (`int`, *optional*):
Number of quantizers to use. If `None`, all quantizers are used. Default is `None`.
Examples:
```python
>>> from datasets impor... | forward | python | huggingface/transformers | src/transformers/models/dac/modeling_dac.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dac/modeling_dac.py | Apache-2.0 |
def forward(
self,
input_values: Optional[torch.Tensor],
attention_mask: Optional[torch.Tensor] = None,
mask_time_indices: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optio... |
mask_time_indices (`torch.BoolTensor` of shape `(batch_size, sequence_length)`, *optional*):
Indices to mask extracted features for contrastive loss. When in training mode, model learns to predict
masked extracted features in *config.proj_codevector_dim* space.
| forward | python | huggingface/transformers | src/transformers/models/data2vec/modeling_data2vec_audio.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/data2vec/modeling_data2vec_audio.py | Apache-2.0 |
def __init__(self, config):
r"""
target_lang (`str`, *optional*):
Language id of adapter weights. Adapter weights are stored in the format adapter.<lang>.safetensors or
adapter.<lang>.bin. Only relevant when using an instance of [`Data2VecAudioForCTC`] with adapters. Uses 'eng' b... |
target_lang (`str`, *optional*):
Language id of adapter weights. Adapter weights are stored in the format adapter.<lang>.safetensors or
adapter.<lang>.bin. Only relevant when using an instance of [`Data2VecAudioForCTC`] with adapters. Uses 'eng' by
default.
| __init__ | python | huggingface/transformers | src/transformers/models/data2vec/modeling_data2vec_audio.py | https://github.com/huggingface/transformers/blob/master/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... |
input_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
Float values of input raw speech waveform. Values can be obtained by loading a `.flac` or `.wav` audio file
into an array of type `List[float]` or a `numpy.ndarray`, *e.g.* via the soundfile library (`pip insta... | forward | python | huggingface/transformers | src/transformers/models/data2vec/modeling_data2vec_audio.py | https://github.com/huggingface/transformers/blob/master/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,
... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the left-to-right language modeling loss (next word prediction). Indices should be in
`[-100, 0, ..., config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` ... | forward | python | huggingface/transformers | src/transformers/models/data2vec/modeling_data2vec_text.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/data2vec/modeling_data2vec_text.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/data2vec/modeling_data2vec_text.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/data2vec/modeling_data2vec_text.py | Apache-2.0 |
def __init__(self, config: Data2VecVisionConfig, add_pooling_layer: bool = False) -> None:
r"""
add_pooling_layer (bool, *optional*, defaults to `False`):
Whether to add a pooling layer
"""
super().__init__(config)
self.config = config
self.embeddings = Data2... |
add_pooling_layer (bool, *optional*, defaults to `False`):
Whether to add a pooling layer
| __init__ | python | huggingface/transformers | src/transformers/models/data2vec/modeling_data2vec_vision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/data2vec/modeling_data2vec_vision.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,
interpolate_pos_encoding: bool =... |
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 | huggingface/transformers | src/transformers/models/data2vec/modeling_data2vec_vision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/data2vec/modeling_data2vec_vision.py | Apache-2.0 |
def load_balancing_loss_func(
gate_logits: torch.Tensor,
num_experts: int,
top_k: int,
attention_mask: Optional[torch.Tensor],
) -> torch.Tensor:
r"""Computes auxiliary load balancing loss as in Switch Transformer - implemented in Pytorch.
See Switch Transformer (https://arxiv.org/abs/2101.0396... | Computes auxiliary load balancing loss as in Switch Transformer - implemented in Pytorch.
See Switch Transformer (https://arxiv.org/abs/2101.03961) for more details. This function implements the loss
function presented in equations (4) - (6) of the paper. It aims at penalizing cases where the routing between
... | load_balancing_loss_func | python | huggingface/transformers | src/transformers/models/dbrx/modeling_dbrx.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dbrx/modeling_dbrx.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_value: Optional[Cache] = None,
output_attentions: Optional[bool] = False,
output_router_logits: Optional[bool] ... | Forward function for DbrxBlock.
Args:
hidden_states (`torch.Tensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
position_ids (`torch.LongTensor`): position ids of shape `(batch, seq_len)`
attention_mask (`torch.Tensor`, *optional*): attention mask of size (ba... | forward | python | huggingface/transformers | src/transformers/models/dbrx/modeling_dbrx.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dbrx/modeling_dbrx.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.Tensor] = None,
labels: Optional... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/dbrx/modeling_dbrx.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dbrx/modeling_dbrx.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: torch.Tensor,
output_attentions: bool = False,
query_states: Optional[torch.Tensor] = None,
relative_pos: Optional[torch.Tensor] = None,
rel_embeddings: Optional[torch.Tensor] = None,
) -> Tuple[t... |
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.BoolTensor`):
An attention mask m... | forward | python | huggingface/transformers | src/transformers/models/deberta/modeling_deberta.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deberta/modeling_deberta.py | Apache-2.0 |
def call(
self,
hidden_states: tf.Tensor,
attention_mask: tf.Tensor,
query_states: Optional[tf.Tensor] = None,
relative_pos: Optional[tf.Tensor] = None,
rel_embeddings: Optional[tf.Tensor] = None,
output_attentions: bool = False,
training: bool = False,
... |
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 | huggingface/transformers | src/transformers/models/deberta/modeling_tf_deberta.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deberta/modeling_tf_deberta.py | Apache-2.0 |
def forward(
self,
states: Optional[torch.FloatTensor] = None,
actions: Optional[torch.FloatTensor] = None,
rewards: Optional[torch.FloatTensor] = None,
returns_to_go: Optional[torch.FloatTensor] = None,
timesteps: Optional[torch.LongTensor] = None,
attention_mask... |
states (`torch.FloatTensor` of shape `(batch_size, episode_length, state_dim)`):
The states for each step in the trajectory
actions (`torch.FloatTensor` of shape `(batch_size, episode_length, act_dim)`):
The actions taken by the "expert" policy for the current state, these are m... | forward | python | huggingface/transformers | src/transformers/models/decision_transformer/modeling_decision_transformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/decision_transformer/modeling_decision_transformer.py | Apache-2.0 |
def moe(self, hidden_states: torch.Tensor, topk_indices: torch.Tensor, topk_weights: torch.Tensor):
r"""
CALL FOR CONTRIBUTION! I don't have time to optimise this right now, but expert weights need to be fused
to not have to do a loop here (deepseek has 256 experts soooo yeah).
"""
... |
CALL FOR CONTRIBUTION! I don't have time to optimise this right now, but expert weights need to be fused
to not have to do a loop here (deepseek has 256 experts soooo yeah).
| moe | python | huggingface/transformers | src/transformers/models/deepseek_v3/modeling_deepseek_v3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deepseek_v3/modeling_deepseek_v3.py | Apache-2.0 |
def apply_rotary_pos_emb_interleave(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
r"""
TODO let's just use the original freqcis computation to not have the view
transpose + reshape! This is not optimized!
Applies Rotary Position Embedding to the query and key tensors.
Args:
q (`torch... |
TODO let's just use the original freqcis computation to not have the view
transpose + reshape! This is not optimized!
Applies Rotary Position Embedding to the query and key tensors.
Args:
q (`torch.Tensor`): The query tensor.
k (`torch.Tensor`): The key tensor.
cos (`torch.Tens... | apply_rotary_pos_emb_interleave | python | huggingface/transformers | src/transformers/models/deepseek_v3/modeling_deepseek_v3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deepseek_v3/modeling_deepseek_v3.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Opt... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/deepseek_v3/modeling_deepseek_v3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deepseek_v3/modeling_deepseek_v3.py | Apache-2.0 |
def prepare_coco_detection_annotation(
image,
target,
return_segmentation_masks: bool = False,
input_data_format: Optional[Union[ChannelDimension, str]] = None,
):
"""
Convert the target in COCO format into the format expected by DEFORMABLE_DETR.
"""
image_height, image_width = image.siz... |
Convert the target in COCO format into the format expected by DEFORMABLE_DETR.
| prepare_coco_detection_annotation | python | huggingface/transformers | src/transformers/models/deformable_detr/image_processing_deformable_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deformable_detr/image_processing_deformable_detr_fast.py | Apache-2.0 |
def from_dict(cls, image_processor_dict: Dict[str, Any], **kwargs):
"""
Overrides the `from_dict` method from the base class to make sure parameters are updated if image processor is
created using from_dict and kwargs e.g. `DeformableDetrImageProcessorFast.from_pretrained(checkpoint, size=600,
... |
Overrides the `from_dict` method from the base class to make sure parameters are updated if image processor is
created using from_dict and kwargs e.g. `DeformableDetrImageProcessorFast.from_pretrained(checkpoint, size=600,
max_size=800)`
| from_dict | python | huggingface/transformers | src/transformers/models/deformable_detr/image_processing_deformable_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deformable_detr/image_processing_deformable_detr_fast.py | Apache-2.0 |
def prepare_annotation(
self,
image: torch.Tensor,
target: Dict,
format: Optional[AnnotationFormat] = None,
return_segmentation_masks: Optional[bool] = None,
masks_path: Optional[Union[str, pathlib.Path]] = None,
input_data_format: Optional[Union[str, ChannelDimen... |
Prepare an annotation for feeding into DEFORMABLE_DETR model.
| prepare_annotation | python | huggingface/transformers | src/transformers/models/deformable_detr/image_processing_deformable_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deformable_detr/image_processing_deformable_detr_fast.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
d... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
d... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/deformable_detr/modeling_deformable_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deformable_detr/modeling_deformable_detr.py | Apache-2.0 |
def interpolate_pos_encoding(self, embeddings: torch.Tensor, height: int, width: int) -> torch.Tensor:
"""
This method allows to interpolate the pre-trained position encodings, to be able to use the model on higher resolution
images. This method is also adapted to support torch.jit tracing and 2... |
This method allows to interpolate the pre-trained position encodings, to be able to use the model on higher resolution
images. This method is also adapted to support torch.jit tracing and 2 class embeddings.
Adapted from:
- https://github.com/facebookresearch/dino/blob/de9ee3df6cf39fac... | interpolate_pos_encoding | python | huggingface/transformers | src/transformers/models/deit/modeling_deit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deit/modeling_deit.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.