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: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[List[torch.FloatTensor]] = None,
inputs_embeds:... |
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/got_ocr2/modeling_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/modeling_got_ocr2.py | Apache-2.0 |
def preprocess_box_annotation(box: Union[List, Tuple], image_size: Tuple[int, int]) -> List:
"""
Convert box annotation to the format [x1, y1, x2, y2] in the range [0, 1000].
"""
width, height = image_size
if len(box) == 4:
box[0] = int(box[0] / width * 1000)
box[1] = int(box[1] / he... |
Convert box annotation to the format [x1, y1, x2, y2] in the range [0, 1000].
| preprocess_box_annotation | python | huggingface/transformers | src/transformers/models/got_ocr2/processing_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/processing_got_ocr2.py | Apache-2.0 |
def __call__(
self,
images: Optional[ImageInput] = None,
text: Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None,
audio=None,
videos=None,
**kwargs: Unpack[GotOcr2ProcessorKwargs],
) -> BatchFeature:
"""
Mai... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to PreTrainedTokenizerFast's [`~PreTrainedTokenizerFast.__call__`] to encode the text if `text`
is not `None`, otherwise encode default OCR queries which depends... | __call__ | python | huggingface/transformers | src/transformers/models/got_ocr2/processing_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/processing_got_ocr2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Union[Tuple[Tuple[torch.Tensor]], Cache]] = None,
cache_position: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[tor... |
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][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the ... | forward | python | huggingface/transformers | src/transformers/models/gpt2/modeling_gpt2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt2/modeling_gpt2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
cache_position: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor]... |
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][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the ... | forward | python | huggingface/transformers | src/transformers/models/gpt2/modeling_gpt2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt2/modeling_gpt2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
cache_position: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor]... |
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][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the ... | forward | python | huggingface/transformers | src/transformers/models/gpt2/modeling_gpt2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt2/modeling_gpt2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] =... |
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][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the ... | forward | python | huggingface/transformers | src/transformers/models/gpt2/modeling_gpt2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt2/modeling_gpt2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] =... |
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][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the ... | forward | python | huggingface/transformers | src/transformers/models/gpt2/modeling_gpt2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt2/modeling_gpt2.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
past_key_values: Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]] = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
token_type_ids: np.ndarray | tf.Tensor | None = None,
position_ids: np.ndarray | ... |
mc_token_ids (`tf.Tensor` or `Numpy array` of shape `(batch_size, num_choices)`, *optional*, default to index of the last token of the input):
Index of the classification token in each input sequence. Selected in the range `[0, input_ids.size(-1) -
1]`.
Return:
Example... | call | python | huggingface/transformers | src/transformers/models/gpt2/modeling_tf_gpt2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt2/modeling_tf_gpt2.py | Apache-2.0 |
def from_tokenizer(cls, tokenizer: GPT2Tokenizer, *args, **kwargs):
"""Creates TFGPT2Tokenizer from GPT2Tokenizer
Args:
tokenizer (GPT2Tokenizer)
Examples:
```python
from transformers import AutoTokenizer, TFGPT2Tokenizer
tokenizer = AutoTokenizer.from_pre... | Creates TFGPT2Tokenizer from GPT2Tokenizer
Args:
tokenizer (GPT2Tokenizer)
Examples:
```python
from transformers import AutoTokenizer, TFGPT2Tokenizer
tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2")
tf_tokenizer = TFGPT2Tokenizer.from_to... | from_tokenizer | python | huggingface/transformers | src/transformers/models/gpt2/tokenization_gpt2_tf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt2/tokenization_gpt2_tf.py | Apache-2.0 |
def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], *init_inputs, **kwargs):
"""Creates TFGPT2Tokenizer from pretrained GPT2Tokenizer
Args:
pretrained_model_name_or_path (Union[str, os.PathLike]): Path to pretrained model
Examples:
```python
... | Creates TFGPT2Tokenizer from pretrained GPT2Tokenizer
Args:
pretrained_model_name_or_path (Union[str, os.PathLike]): Path to pretrained model
Examples:
```python
from transformers import TFGPT2Tokenizer
tf_tokenizer = TFGPT2Tokenizer.from_pretrained("openai-commun... | from_pretrained | python | huggingface/transformers | src/transformers/models/gpt2/tokenization_gpt2_tf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt2/tokenization_gpt2_tf.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] =... |
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/gptj/modeling_gptj.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gptj/modeling_gptj.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
past_key_values: Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]] = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
token_type_ids: np.ndarray | tf.Tensor | None = None,
position_ids: np.ndarray | ... |
labels (`np.ndarray` or `tf.Tensor` of shape `(batch_size, input_ids_length)`, *optional*):
Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
`labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels s... | call | python | huggingface/transformers | src/transformers/models/gptj/modeling_tf_gptj.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gptj/modeling_tf_gptj.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
past_key_values: Optional[List[torch.Tensor]] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask:... |
input_ids (`torch.Tensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else
`past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the voca... | forward | python | huggingface/transformers | src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | Apache-2.0 |
def _get_initial_cache_position(self, seq_length, device, model_kwargs):
"""
Calculates `cache_position` for the pre-fill stage based on `input_ids` and optionally past length.
Since gpt bigcode is special, the method is overridden here, other models use it from `generation.utils.py`.
""... |
Calculates `cache_position` for the pre-fill stage based on `input_ids` and optionally past length.
Since gpt bigcode is special, the method is overridden here, other models use it from `generation.utils.py`.
| _get_initial_cache_position | python | huggingface/transformers | src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
he... |
input_ids (`torch.Tensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else
`past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the voca... | forward | python | huggingface/transformers | src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
he... |
input_ids (`torch.Tensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else
`past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the voca... | forward | python | huggingface/transformers | src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
he... |
input_ids (`torch.Tensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else
`past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the voca... | forward | python | huggingface/transformers | src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = 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/gpt_neox/modeling_gpt_neox.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gpt_neox/modeling_gpt_neox.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/granite/modeling_granite.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granite/modeling_granite.py | Apache-2.0 |
def __init__(self, num_experts: int, input_size: int, output_size: int) -> None:
"""
Initialize the GraniteMoeParallelExperts module.
The experts weights are stored in [num_experts, output_size, input_size] format. Such that it's compatible with
many MoE libraries, such as [Megablock](ht... |
Initialize the GraniteMoeParallelExperts module.
The experts weights are stored in [num_experts, output_size, input_size] format. Such that it's compatible with
many MoE libraries, such as [Megablock](https://github.com/databricks/megablocks) and
[ScatterMoE](https://github.com/shawntan... | __init__ | python | huggingface/transformers | src/transformers/models/granitemoe/modeling_granitemoe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoe/modeling_granitemoe.py | Apache-2.0 |
def forward(self, inputs, expert_size):
"""
Forward pass of the GraniteMoeParallelExperts module.
Args:
inputs (Tensor):
Input tensor.
expert_size:
Expert size information.
Returns:
Tensor: Output tensor.
"""
... |
Forward pass of the GraniteMoeParallelExperts module.
Args:
inputs (Tensor):
Input tensor.
expert_size:
Expert size information.
Returns:
Tensor: Output tensor.
| forward | python | huggingface/transformers | src/transformers/models/granitemoe/modeling_granitemoe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoe/modeling_granitemoe.py | Apache-2.0 |
def __init__(self, input_size: int, num_experts: int, top_k: int):
"""
Initialize the top-k gating mechanism.
Args:
input_size (`int`):
Size of the input.
num_experts (`int`):
Number of experts.
top_k (`int`):
Nu... |
Initialize the top-k gating mechanism.
Args:
input_size (`int`):
Size of the input.
num_experts (`int`):
Number of experts.
top_k (`int`):
Number of top experts to select.
| __init__ | python | huggingface/transformers | src/transformers/models/granitemoe/modeling_granitemoe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoe/modeling_granitemoe.py | Apache-2.0 |
def forward(self, layer_input):
"""
Forward pass of the mixture of experts layer.
Args:
layer_input (Tensor):
Input tensor.
Returns:
Tensor:
Output tensor.
Tensor:
Router logits.
"""
bsz... |
Forward pass of the mixture of experts layer.
Args:
layer_input (Tensor):
Input tensor.
Returns:
Tensor:
Output tensor.
Tensor:
Router logits.
| forward | python | huggingface/transformers | src/transformers/models/granitemoe/modeling_granitemoe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoe/modeling_granitemoe.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/granitemoe/modeling_granitemoe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoe/modeling_granitemoe.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/granitemoe/modeling_granitemoe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoe/modeling_granitemoe.py | Apache-2.0 |
def __init__(self, num_experts: int, input_size: int, output_size: int) -> None:
"""
Initialize the GraniteMoeHybridParallelExperts module.
The experts weights are stored in [num_experts, output_size, input_size] format. Such that it's compatible with
many MoE libraries, such as [Megablo... |
Initialize the GraniteMoeHybridParallelExperts module.
The experts weights are stored in [num_experts, output_size, input_size] format. Such that it's compatible with
many MoE libraries, such as [Megablock](https://github.com/databricks/megablocks) and
[ScatterMoE](https://github.com/sh... | __init__ | python | huggingface/transformers | src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py | Apache-2.0 |
def forward(self, inputs, expert_size):
"""
Forward pass of the GraniteMoeHybridParallelExperts module.
Args:
inputs (Tensor):
Input tensor.
expert_size:
Expert size information.
Returns:
Tensor: Output tensor.
... |
Forward pass of the GraniteMoeHybridParallelExperts module.
Args:
inputs (Tensor):
Input tensor.
expert_size:
Expert size information.
Returns:
Tensor: Output tensor.
| forward | python | huggingface/transformers | src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
past_key_value: Optional[Cache] = None,
output_attentions: Optional[bool] = False,
use_cache: Optional[bool] = False,
cache_position: Optional[torch.LongTensor] = None,
... |
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/granitemoehybrid/modeling_granitemoehybrid.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.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/granitemoehybrid/modeling_granitemoehybrid.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py | Apache-2.0 |
def __init__(self, num_experts: int, input_size: int, output_size: int) -> None:
"""
Initialize the GraniteMoeSharedParallelExperts module.
The experts weights are stored in [num_experts, output_size, input_size] format. Such that it's compatible with
many MoE libraries, such as [Megablo... |
Initialize the GraniteMoeSharedParallelExperts module.
The experts weights are stored in [num_experts, output_size, input_size] format. Such that it's compatible with
many MoE libraries, such as [Megablock](https://github.com/databricks/megablocks) and
[ScatterMoE](https://github.com/sh... | __init__ | python | huggingface/transformers | src/transformers/models/granitemoeshared/modeling_granitemoeshared.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoeshared/modeling_granitemoeshared.py | Apache-2.0 |
def forward(self, inputs, expert_size):
"""
Forward pass of the GraniteMoeSharedParallelExperts module.
Args:
inputs (Tensor):
Input tensor.
expert_size:
Expert size information.
Returns:
Tensor: Output tensor.
... |
Forward pass of the GraniteMoeSharedParallelExperts module.
Args:
inputs (Tensor):
Input tensor.
expert_size:
Expert size information.
Returns:
Tensor: Output tensor.
| forward | python | huggingface/transformers | src/transformers/models/granitemoeshared/modeling_granitemoeshared.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoeshared/modeling_granitemoeshared.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/granitemoeshared/modeling_granitemoeshared.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granitemoeshared/modeling_granitemoeshared.py | Apache-2.0 |
def _ensure_melspec_transform_is_initialized(self):
"""
Ensures the mel spectrogram transform on this instance is initialized.
We do this for now since some logging explodes since the mel spectrogram
transform is not JSON serializable.
"""
requires_backends(self, ["torch... |
Ensures the mel spectrogram transform on this instance is initialized.
We do this for now since some logging explodes since the mel spectrogram
transform is not JSON serializable.
| _ensure_melspec_transform_is_initialized | python | huggingface/transformers | src/transformers/models/granite_speech/feature_extraction_granite_speech.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granite_speech/feature_extraction_granite_speech.py | Apache-2.0 |
def _extract_mel_spectrograms(self, audio: "torch.Tensor", device="cpu"):
"""
Compute the Mel features to be passed to the conformer encoder.
"""
requires_backends(self, ["torchaudio"])
# Initialize the mel spectrogram if isn't not already and
# move the melspec / audio ... |
Compute the Mel features to be passed to the conformer encoder.
| _extract_mel_spectrograms | python | huggingface/transformers | src/transformers/models/granite_speech/feature_extraction_granite_speech.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granite_speech/feature_extraction_granite_speech.py | Apache-2.0 |
def _get_num_audio_features(self, audio_lengths: Sequence[int]) -> Sequence[int]:
"""
Gets the (variable length) number of features (i.e., projector output) for the sequences
being considered.
Args:
audio_lengths (`Sequence[int]`):
Sequence of one or more raw... |
Gets the (variable length) number of features (i.e., projector output) for the sequences
being considered.
Args:
audio_lengths (`Sequence[int]`):
Sequence of one or more raw audio lengths.
| _get_num_audio_features | python | huggingface/transformers | src/transformers/models/granite_speech/feature_extraction_granite_speech.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granite_speech/feature_extraction_granite_speech.py | Apache-2.0 |
def _get_audios_and_audio_lengths(self, audios: AudioInput) -> Sequence["torch.Tensor", Sequence[int]]:
"""
Coerces audio inputs to torch tensors and extracts audio lengths prior to stacking.
Args:
audios (`AudioInput`):
Audio sequence, numpy array, or torch tensor.
... |
Coerces audio inputs to torch tensors and extracts audio lengths prior to stacking.
Args:
audios (`AudioInput`):
Audio sequence, numpy array, or torch tensor.
| _get_audios_and_audio_lengths | python | huggingface/transformers | src/transformers/models/granite_speech/feature_extraction_granite_speech.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granite_speech/feature_extraction_granite_speech.py | Apache-2.0 |
def get_audio_features(self, input_features: torch.Tensor) -> torch.Tensor:
"""Get the audio features to merged into the multimodal embeddings."""
encoder_embeds = self.encoder(input_features)
projected_embeds = self.projector(encoder_embeds)
return projected_embeds | Get the audio features to merged into the multimodal embeddings. | get_audio_features | python | huggingface/transformers | src/transformers/models/granite_speech/modeling_granite_speech.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granite_speech/modeling_granite_speech.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
input_features: torch.FloatTensor = None,
input_features_mask: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Op... |
input_features (`torch.FloatTensor` of shape `(batch_size, audio seq len, mel feat dim)):
The tensors corresponding to the input audios. input features can be obtained using
[`AutoFeatureExtractor`]. See [`GraniteSpeechFeatureExtractor.__call__`] for details.
[`GraniteSpeech... | forward | python | huggingface/transformers | src/transformers/models/granite_speech/modeling_granite_speech.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granite_speech/modeling_granite_speech.py | Apache-2.0 |
def get_merged_audio_embeddings(
self, input_ids: torch.Tensor, audio_features: torch.Tensor, input_features_mask: Optional[torch.Tensor] = None
) -> torch.Tensor:
"""
Adds the audio token to the model's LLM vocabulary so that we can pass it
through the tokenizer; it's assumed that t... |
Adds the audio token to the model's LLM vocabulary so that we can pass it
through the tokenizer; it's assumed that the embeddings corresponding to the
<|audio|> token will be clobbered with speech features.
Args:
input_ids (`torch.Tensor`):
Input IDs contain... | get_merged_audio_embeddings | python | huggingface/transformers | src/transformers/models/granite_speech/modeling_granite_speech.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/granite_speech/modeling_granite_speech.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 GroundingDino.
"""
image_height, image_width = get_image_s... |
Convert the target in COCO format into the format expected by GroundingDino.
| prepare_coco_detection_annotation | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino.py | Apache-2.0 |
def prepare_coco_panoptic_annotation(
image: np.ndarray,
target: Dict,
masks_path: Union[str, pathlib.Path],
return_masks: bool = True,
input_data_format: Union[ChannelDimension, str] = None,
) -> Dict:
"""
Prepare a coco panoptic annotation for GroundingDino.
"""
image_height, image... |
Prepare a coco panoptic annotation for GroundingDino.
| prepare_coco_panoptic_annotation | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino.py | Apache-2.0 |
def _scale_boxes(boxes, target_sizes):
"""
Scale batch of bounding boxes to the target sizes.
Args:
boxes (`torch.Tensor` of shape `(batch_size, num_boxes, 4)`):
Bounding boxes to scale. Each box is expected to be in (x1, y1, x2, y2) format.
target_sizes (`List[Tuple[int, int]]`... |
Scale batch of bounding boxes to the target sizes.
Args:
boxes (`torch.Tensor` of shape `(batch_size, num_boxes, 4)`):
Bounding boxes to scale. Each box is expected to be in (x1, y1, x2, y2) format.
target_sizes (`List[Tuple[int, int]]` or `torch.Tensor` of shape `(batch_size, 2)`)... | _scale_boxes | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino.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. `GroundingDinoImageProcessor.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. `GroundingDinoImageProcessor.from_pretrained(checkpoint, size=600,
max_size=800)`
| from_dict | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino.py | Apache-2.0 |
def prepare_annotation(
self,
image: np.ndarray,
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, ChannelDimensi... |
Prepare an annotation for feeding into GroundingDino model.
| prepare_annotation | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino.py | Apache-2.0 |
def post_process_object_detection(
self,
outputs: "GroundingDinoObjectDetectionOutput",
threshold: float = 0.1,
target_sizes: Optional[Union[TensorType, List[Tuple]]] = None,
):
"""
Converts the raw output of [`GroundingDinoForObjectDetection`] into final bounding box... |
Converts the raw output of [`GroundingDinoForObjectDetection`] into final bounding boxes in (top_left_x, top_left_y,
bottom_right_x, bottom_right_y) format.
Args:
outputs ([`GroundingDinoObjectDetectionOutput`]):
Raw outputs of the model.
threshold (`flo... | post_process_object_detection | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino.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 GROUNDING_DINO.
"""
image_height, image_width = image.size... |
Convert the target in COCO format into the format expected by GROUNDING_DINO.
| prepare_coco_detection_annotation | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino_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. `GroundingDinoImageProcessorFast.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. `GroundingDinoImageProcessorFast.from_pretrained(checkpoint, size=600,
max_size=800)`
| from_dict | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino_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 GROUNDING_DINO model.
| prepare_annotation | python | huggingface/transformers | src/transformers/models/grounding_dino/image_processing_grounding_dino_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/image_processing_grounding_dino_fast.py | Apache-2.0 |
def replace_batch_norm(model):
r"""
Recursively replace all `torch.nn.BatchNorm2d` with `GroundingDinoFrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
"""
for name, module in model.named_children():
if isinstance(module, nn.BatchNorm2d):
new_mod... |
Recursively replace all `torch.nn.BatchNorm2d` with `GroundingDinoFrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
| replace_batch_norm | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.FloatTensor,
attention_masks: Optional[torch.BoolTensor] = None,
position_embeddings: Optional[torch.FloatTensor] = None,
) -> Tuple[torch.FloatTensor, torch.FloatTensor]:
"""Text self-attention to enhance projection of text features ge... | Text self-attention to enhance projection of text features generated by
the text encoder (AutoModel based on text_config) within GroundingDinoEncoderLayer
Args:
hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_dim)`):
Text features generated ... | forward | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def forward(
self,
vision_features: torch.FloatTensor,
text_features: torch.FloatTensor,
vision_attention_mask: Optional[torch.BoolTensor] = None,
text_attention_mask: Optional[torch.BoolTensor] = None,
) -> Tuple[Tuple[torch.FloatTensor, torch.FloatTensor], Tuple[torch.Float... | Image-to-text and text-to-image cross-attention
Args:
vision_features (`torch.FloatTensor` of shape `(batch_size, vision_sequence_length, hidden_dim)`):
Projected flattened image features generated by the vision backbone.
text_features (`torch.FloatTensor` of shape `(bat... | forward | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def forward(
self,
vision_features: torch.FloatTensor,
text_features: torch.FloatTensor,
attention_mask_vision: Optional[torch.BoolTensor] = None,
attention_mask_text: Optional[torch.BoolTensor] = None,
) -> Tuple[Tuple[torch.FloatTensor, torch.FloatTensor], Tuple[torch.Float... | Image and text features fusion
Args:
vision_features (`torch.FloatTensor` of shape `(batch_size, vision_sequence_length, hidden_dim)`):
Projected flattened image features generated by the vision backbone.
text_features (`torch.FloatTensor` of shape `(batch_size, text_seq... | forward | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: torch.Tensor,
position_embeddings: Optional[torch.Tensor] = None,
reference_points=None,
spatial_shapes=None,
spatial_shapes_list=None,
level_start_index=None,
output_attentions: bool ... |
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 | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def get_sine_pos_embed(
pos_tensor: torch.Tensor, num_pos_feats: int = 128, temperature: int = 10000, exchange_xy: bool = True
) -> Tensor:
"""
Generate sine position embeddings from a position tensor.
Args:
pos_tensor (torch.Tensor):
Tensor containing positions. Shape: [..., n].
... |
Generate sine position embeddings from a position tensor.
Args:
pos_tensor (torch.Tensor):
Tensor containing positions. Shape: [..., n].
num_pos_feats (`int`, *optional*, defaults to 128):
Projected shape for each float in the tensor.
temperature (`int`, *option... | get_sine_pos_embed | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def get_reference_points(spatial_shapes, valid_ratios, device):
"""
Get reference points for each feature map.
Args:
spatial_shapes (`torch.LongTensor` of shape `(num_feature_levels, 2)`):
Spatial shapes of each feature map.
valid_ratios (`torch.FloatTens... |
Get reference points for each feature map.
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)`):
Valid ... | get_reference_points | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def forward(
self,
vision_features: Tensor,
vision_attention_mask: Tensor,
vision_position_embedding: Tensor,
spatial_shapes: Tensor,
spatial_shapes_list: List[Tuple[int, int]],
level_start_index: Tensor,
valid_ratios=None,
text_features: Optional[... |
Args:
vision_features (`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.
vision_attention_mask (`torch.Tensor` of shape `(batch_size, sequence_lengt... | forward | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def forward(
self,
inputs_embeds,
vision_encoder_hidden_states,
vision_encoder_attention_mask=None,
text_encoder_hidden_states=None,
text_encoder_attention_mask=None,
reference_points=None,
spatial_shapes=None,
spatial_shapes_list=None,
lev... |
Args:
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, num_queries, hidden_size)`):
The query embeddings that are passed into the decoder.
vision_encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
L... | forward | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def generate_masks_with_special_tokens_and_transfer_map(input_ids: torch.LongTensor) -> Tuple[Tensor, Tensor]:
"""Generate attention mask between each pair of special tokens and positional ids.
Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input se... | Generate attention mask between each pair of special tokens and positional ids.
Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Returns:
`tuple(torch.Tensor)` comprising attention mask between each spe... | generate_masks_with_special_tokens_and_transfer_map | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def generate_encoder_output_proposals(self, enc_output, padding_mask, spatial_shapes):
"""Generate the encoder output proposals from encoded enc_output.
Args:
enc_output (`torch.Tensor[batch_size, sequence_length, hidden_size]`): Output of the encoder.
padding_mask (`torch.Tenso... | Generate the encoder output proposals from encoded enc_output.
Args:
enc_output (`torch.Tensor[batch_size, sequence_length, hidden_size]`): Output of the encoder.
padding_mask (`torch.Tensor[batch_size, sequence_length]`): Padding mask for `enc_output`.
spatial_shapes (`torc... | generate_encoder_output_proposals | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def forward(
self,
pixel_values: Tensor,
input_ids: Tensor,
token_type_ids: Optional[Tensor] = None,
attention_mask: Optional[Tensor] = None,
pixel_mask: Optional[Tensor] = None,
encoder_outputs=None,
output_attentions=None,
output_hidden_states=No... |
input_ids (`torch.LongTensor` of shape `(batch_size, text_sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
it.
Indices can be obtained using [`AutoTokenizer`]. See [`BertTokenizer.__call__`] for de... | forward | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def build_text_mask(logits, attention_mask):
"""
Create text_mask based on the matching indices
"""
seq_len = attention_mask.shape[1]
text_mask = torch.zeros_like(logits, device=logits.device, dtype=attention_mask.dtype)
text_mask[:, :, :seq_len] = attention_mask[:, None, :]
return text_mas... |
Create text_mask based on the matching indices
| build_text_mask | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
input_ids: torch.LongTensor,
token_type_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.LongTensor] = None,
pixel_mask: Optional[torch.BoolTensor] = None,
encoder_outputs: Optional[Union[Gr... |
input_ids (`torch.LongTensor` of shape `(batch_size, text_sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
it.
Indices can be obtained using [`AutoTokenizer`]. See [`BertTokenizer.__call__`] for de... | forward | python | huggingface/transformers | src/transformers/models/grounding_dino/modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/modeling_grounding_dino.py | Apache-2.0 |
def get_phrases_from_posmap(posmaps, input_ids):
"""Get token ids of phrases from posmaps and input_ids.
Args:
posmaps (`torch.BoolTensor` of shape `(num_boxes, hidden_size)`):
A boolean tensor of text-thresholded logits related to the detected bounding boxes.
input_ids (`torch.Long... | Get token ids of phrases from posmaps and input_ids.
Args:
posmaps (`torch.BoolTensor` of shape `(num_boxes, hidden_size)`):
A boolean tensor of text-thresholded logits related to the detected bounding boxes.
input_ids (`torch.LongTensor`) of shape `(sequence_length, )`):
A ... | get_phrases_from_posmap | python | huggingface/transformers | src/transformers/models/grounding_dino/processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/processing_grounding_dino.py | Apache-2.0 |
def _is_list_of_candidate_labels(text) -> bool:
"""Check that text is list/tuple of strings and each string is a candidate label and not merged candidate labels text.
Merged candidate labels text is a string with candidate labels separated by a dot.
"""
if isinstance(text, (list, tuple)):
return... | Check that text is list/tuple of strings and each string is a candidate label and not merged candidate labels text.
Merged candidate labels text is a string with candidate labels separated by a dot.
| _is_list_of_candidate_labels | python | huggingface/transformers | src/transformers/models/grounding_dino/processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/processing_grounding_dino.py | Apache-2.0 |
def _merge_candidate_labels_text(text: List[str]) -> str:
"""
Merge candidate labels text into a single string. Ensure all labels are lowercase.
For example, ["A cat", "a dog"] -> "a cat. a dog."
"""
labels = [t.strip().lower() for t in text] # ensure lowercase
merged_labels_str = ". ".join(lab... |
Merge candidate labels text into a single string. Ensure all labels are lowercase.
For example, ["A cat", "a dog"] -> "a cat. a dog."
| _merge_candidate_labels_text | python | huggingface/transformers | src/transformers/models/grounding_dino/processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/processing_grounding_dino.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[GroundingDinoProcessorKwargs],
) -> BatchEncoding:
"""
This method uses... |
This method uses [`GroundingDinoImageProcessor.__call__`] method to prepare image(s) for the model, and
[`BertTokenizerFast.__call__`] to prepare text for the model.
Args:
images (`ImageInput`, `List[ImageInput]`, *optional*):
The image or batch of images to be proc... | __call__ | python | huggingface/transformers | src/transformers/models/grounding_dino/processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/processing_grounding_dino.py | Apache-2.0 |
def _preprocess_input_text(self, text):
"""
Preprocess input text to ensure that labels are in the correct format for the model.
If the text is a list of candidate labels, merge the candidate labels into a single string,
for example, ["a cat", "a dog"] -> "a cat. a dog.". In case candida... |
Preprocess input text to ensure that labels are in the correct format for the model.
If the text is a list of candidate labels, merge the candidate labels into a single string,
for example, ["a cat", "a dog"] -> "a cat. a dog.". In case candidate labels are already in a form of
"a cat. ... | _preprocess_input_text | python | huggingface/transformers | src/transformers/models/grounding_dino/processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/processing_grounding_dino.py | Apache-2.0 |
def post_process_grounded_object_detection(
self,
outputs: "GroundingDinoObjectDetectionOutput",
input_ids: Optional[TensorType] = None,
threshold: float = 0.25,
text_threshold: float = 0.25,
target_sizes: Optional[Union[TensorType, List[Tuple]]] = None,
text_labe... |
Converts the raw output of [`GroundingDinoForObjectDetection`] into final bounding boxes in (top_left_x, top_left_y,
bottom_right_x, bottom_right_y) format and get the associated text label.
Args:
outputs ([`GroundingDinoObjectDetectionOutput`]):
Raw outputs of the ... | post_process_grounded_object_detection | python | huggingface/transformers | src/transformers/models/grounding_dino/processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/grounding_dino/processing_grounding_dino.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 n... |
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 no class embeddings.
Adapted from:
- https://github.com/facebookresearch/dino/blob/de9ee3df6cf39fa... | interpolate_pos_encoding | python | huggingface/transformers | src/transformers/models/groupvit/modeling_groupvit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/groupvit/modeling_groupvit.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bo... |
Examples:
```python
>>> from transformers import CLIPTokenizer, GroupViTTextModel
>>> tokenizer = CLIPTokenizer.from_pretrained("nvidia/groupvit-gcc-yfcc")
>>> model = GroupViTTextModel.from_pretrained("nvidia/groupvit-gcc-yfcc")
>>> inputs = tokenizer(["a photo of a ... | forward | python | huggingface/transformers | src/transformers/models/groupvit/modeling_groupvit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/groupvit/modeling_groupvit.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple, BaseModelOutputWithPooling]:
r"""
Examples:
... |
Examples:
```python
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, GroupViTVisionModel
>>> processor = AutoProcessor.from_pretrained("nvidia/groupvit-gcc-yfcc")
>>> model = GroupViTVisionModel.from_pretrained("nvidia/g... | forward | python | huggingface/transformers | src/transformers/models/groupvit/modeling_groupvit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/groupvit/modeling_groupvit.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
pixel_values: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
return_loss: Optional[bool] = None,
output_attentions... |
return_loss (`bool`, *optional*):
Whether or not to return the contrastive loss.
output_segmentation (`bool`, *optional*):
Whether or not to return the segmentation logits.
Examples:
```python
>>> from PIL import Image
>>> import requests
... | forward | python | huggingface/transformers | src/transformers/models/groupvit/modeling_groupvit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/groupvit/modeling_groupvit.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/helium/modeling_helium.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/helium/modeling_helium.py | Apache-2.0 |
def forward(
self, pixel_values: Tensor, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers import RTDetrResNetConfig, RTDetrResNetBackbone
>>> import torch
>>> ... |
Examples:
```python
>>> from transformers import RTDetrResNetConfig, RTDetrResNetBackbone
>>> import torch
>>> config = RTDetrResNetConfig()
>>> model = RTDetrResNetBackbone(config)
>>> pixel_values = torch.randn(1, 3, 224, 224)
>>> with torch.no_grad... | forward | python | huggingface/transformers | src/transformers/models/hgnet_v2/modeling_hgnet_v2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hgnet_v2/modeling_hgnet_v2.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> ImageClassifierOutputWithNoAttention:
r"""
labels (`torch.Long... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
`config.n... | forward | python | huggingface/transformers | src/transformers/models/hgnet_v2/modeling_hgnet_v2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hgnet_v2/modeling_hgnet_v2.py | Apache-2.0 |
def masked_conv(
self, pixel_values: torch.FloatTensor, bool_masked_pos: Optional[torch.BoolTensor] = None
) -> torch.Tensor:
"""Zero-out the masked regions of the input before conv.
Prevents leakage of masked regions when using overlapping kernels.
"""
if bool_masked_pos is ... | Zero-out the masked regions of the input before conv.
Prevents leakage of masked regions when using overlapping kernels.
| masked_conv | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def random_masking(
self, pixel_values: torch.FloatTensor, noise: Optional[torch.FloatTensor] = None
) -> Tuple[torch.BoolTensor, torch.LongTensor]:
"""
Perform per-sample random masking by per-sample shuffling. Per-sample shuffling is done by argsort random
noise.
Args:
... |
Perform per-sample random masking by per-sample shuffling. Per-sample shuffling is done by argsort random
noise.
Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`)
noise (`torch.FloatTensor` of shape `(batch_size, num_mask_unit... | random_masking | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def interpolate_pos_encoding(
self, embeddings: torch.Tensor, pos_embeds: 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 ad... |
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, no class embeddings, and different patch strides.
Adapted from:
- https://github.com/facebookresearch... | interpolate_pos_encoding | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
head_mask: Optional[torch.FloatTensor] = None,
output_attentions: bool = False,
) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
"""Input should be of shape [batch, tokens, channels]."""
batch_size, seq_len, _ = hidden_... | Input should be of shape [batch, tokens, channels]. | forward | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def undo_windowing(hidden_states: torch.Tensor, shape: List[int], mask_unit_shape: List[int]) -> torch.Tensor:
"""
Restore spatial organization by undoing windowed organization of mask units.
Args:
hidden_states (`torch.Tensor`): The hidden states tensor of shape `[batch_size, num_mask_unit_height*... |
Restore spatial organization by undoing windowed organization of mask units.
Args:
hidden_states (`torch.Tensor`): The hidden states tensor of shape `[batch_size, num_mask_unit_height*num_mask_unit_width, hidden_size]`.
shape (`List[int]`): The original shape of the hidden states tensor before... | undo_windowing | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def reroll(
self, hidden_states: torch.Tensor, stage_idx: int, bool_masked_pos: Optional[torch.BoolTensor] = None
) -> torch.Tensor:
"""
Roll the given tensor back up to spatial order assuming it's from the given block.
If no bool_masked_pos is provided returns:
- [batch... |
Roll the given tensor back up to spatial order assuming it's from the given block.
If no bool_masked_pos is provided returns:
- [batch_size, height, width, hidden_size]
If a bool_masked_pos is provided returns:
- [batch_size, num_mask_units, mask_unit_height, mask_unit_... | reroll | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def unroll(
hidden_states: torch.Tensor, image_shape: Tuple[int, int], patch_stride: Tuple[int, int], schedule: List[List[int]]
) -> torch.Tensor:
"""
Reorders the tokens such that patches are contiguous in memory.
E.g., given [batch_size, (height, width), hidden_size] and stride of (stride, stride), th... |
Reorders the tokens such that patches are contiguous in memory.
E.g., given [batch_size, (height, width), hidden_size] and stride of (stride, stride), this will re-order the tokens as
[batch_size, (stride, stride, height // stride, width // stride), hidden_size]
This allows operations like Max2d to be... | unroll | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def __init__(self, config: HieraConfig, add_pooling_layer: bool = True, is_mae: bool = False):
r"""
add_pooling_layer (`bool`, *optional*, defaults to `True`):
Whether or not to apply pooling layer.
is_mae (`bool`, *optional*, defaults to `False`):
Whether or not to run t... |
add_pooling_layer (`bool`, *optional*, defaults to `True`):
Whether or not to apply pooling layer.
is_mae (`bool`, *optional*, defaults to `False`):
Whether or not to run the model on MAE mode.
| __init__ | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
noise: Optional[torch.FloatTensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
interpolate_pos_encoding: Op... |
noise (`torch.FloatTensor` of shape `(batch_size, num_mask_units)`, *optional*):
Mainly used for testing purposes to control randomness and maintain the reproducibility
| forward | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
noise: Optional[torch.FloatTensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
interpolate_pos_encoding: Op... |
noise (`torch.FloatTensor` of shape `(batch_size, num_mask_units)`, *optional*):
Mainly used for testing purposes to control randomness and maintain the reproducibility
Examples:
```python
>>> from transformers import AutoImageProcessor, HieraForPreTraining
>>> impo... | forward | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.Tensor,
output_hidden_states: Optional[bool] = None,
output_attentions: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
"""
Returns:
Examples:
```python
>>> from t... |
Returns:
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(... | forward | python | huggingface/transformers | src/transformers/models/hiera/modeling_hiera.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hiera/modeling_hiera.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.
Example:
... | forward | python | huggingface/transformers | src/transformers/models/hubert/modeling_hubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hubert/modeling_hubert.py | Apache-2.0 |
def __init__(self, config, target_lang: Optional[str] = None):
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 [`HubertForCTC`]... |
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 [`HubertForCTC`] with adapters. Uses 'eng' by
default.
| __init__ | python | huggingface/transformers | src/transformers/models/hubert/modeling_hubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hubert/modeling_hubert.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/hubert/modeling_hubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/hubert/modeling_hubert.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
image_num_channels: Optional[int] = 3,
image_size: Optional[Dict[str, int]] = None,
image_mean: Optional[Union[float, List[float]]] = None,
image_std: Optional[Union[float, List[float]]] = None,
transform: Optional[Callabl... |
Preprocess a batch of images.
Args:
images (`ImageInput`):
A list of images to preprocess.
image_size (`int`, *optional*, defaults to `self.image_size`):
Resize to image size
image_num_channels (`int`, *optional*, defaults to `self.im... | preprocess | python | huggingface/transformers | src/transformers/models/idefics/image_processing_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/image_processing_idefics.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
image_hidden_states: Optional[torch.Tensor] = None,
image_attention_mask: Optional[torch.Tensor] = None,
cross_attention_gate: Optional[torch.Tensor] = None,
output_atte... |
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, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values... | forward | python | huggingface/transformers | src/transformers/models/idefics/modeling_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_idefics.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,
inputs_embeds: Optional[torch.FloatTensor] = None,
... |
image_encoder_embeddings (`torch.FloatTensor`, *optional*):
The output of the image encoder.
perceiver_embeddings (`torch.FloatTensor`, *optional*):
The output of the perceiver resampler.
image_attention_mask (`torch.LongTensor`, *optional*):
The attention ma... | forward | python | huggingface/transformers | src/transformers/models/idefics/modeling_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_idefics.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,
inputs_embeds: Optional[torch.FloatTensor] = None,
... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/idefics/modeling_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_idefics.py | Apache-2.0 |
def __init__(
self,
num_embeddings,
num_additional_embeddings,
embedding_dim,
partially_freeze: Optional[bool] = False,
dtype=None,
**kwargs,
) -> None:
"""
Args:
num_embeddings (`int`):
Size of the dictionary of emb... |
Args:
num_embeddings (`int`):
Size of the dictionary of embeddings
num_additional_embeddings (`int`):
Number of additional embeddings. Only useful when you `partially_freeze=True`.
embedding_dim (`int`):
The size of each embedd... | __init__ | python | huggingface/transformers | src/transformers/models/idefics/modeling_tf_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_tf_idefics.py | Apache-2.0 |
def __init__(
self,
in_features: int,
out_features: int,
out_additional_features: int = 0,
bias: bool = True,
partially_freeze: bool = True,
**kwargs,
) -> None:
"""
out_additional_features: int. Number of additional trainable dimensions. Only ... |
out_additional_features: int. Number of additional trainable dimensions. Only makes sense when
`partially_freeze=True`. partially_freeze: bool. If True, the regular `weight` will be frozen and extra
parameters (if any) will be trainable. If False, default to the regular behavior of tf.keras.lay... | __init__ | python | huggingface/transformers | src/transformers/models/idefics/modeling_tf_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_tf_idefics.py | Apache-2.0 |
def _make_causal_mask(input_ids_shape, dtype, past_key_values_length=0):
"""
Make causal mask used for bi-directional self-attention, supporting both static and dynamic shapes.
"""
bsz, tgt_len = input_ids_shape
# Create a matrix where only the lower triangle and diagonal are filled with zeros (cau... |
Make causal mask used for bi-directional self-attention, supporting both static and dynamic shapes.
| _make_causal_mask | python | huggingface/transformers | src/transformers/models/idefics/modeling_tf_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_tf_idefics.py | Apache-2.0 |
def call(
self,
hidden_states: tf.Tensor,
attention_mask: Optional[tf.Tensor] = None,
position_ids: Optional[tf.Tensor] = None,
past_key_value: Optional[Tuple[tf.Tensor]] = None,
output_attentions: Optional[bool] = False,
use_cache: Optional[bool] = False,
... |
Args:
hidden_states (`tf.Tensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`tf.Tensor`, *optional*): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
ou... | call | python | huggingface/transformers | src/transformers/models/idefics/modeling_tf_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_tf_idefics.py | Apache-2.0 |
def call(
self,
hidden_states: tf.Tensor,
attention_mask: Optional[tf.Tensor] = None,
image_hidden_states: Optional[tf.Tensor] = None,
image_attention_mask: Optional[tf.Tensor] = None,
cross_attention_gate: Optional[tf.Tensor] = None,
output_attentions: Optional[b... |
Args:
hidden_states (`tf.Tensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`tf.Tensor`, *optional*): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
ou... | call | python | huggingface/transformers | src/transformers/models/idefics/modeling_tf_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_tf_idefics.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: Optional[tf.Tensor] = None,
position_ids: Optional[tf.Tensor] = None,
past_key_values: Optional[List[tf.Tensor]] = None,
inputs_embeds: Optional[tf.Tensor] = None,
pixel_values: Optional[tf... |
labels (`tf.Tensor` 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
... | call | python | huggingface/transformers | src/transformers/models/idefics/modeling_tf_idefics.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/idefics/modeling_tf_idefics.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.