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 convert_tiktoken_to_fast(encoding: Any, output_dir: str):
"""
Converts given `tiktoken` encoding to `PretrainedTokenizerFast` and saves the configuration of converted tokenizer
on disk.
Args:
encoding (`str` or `tiktoken.Encoding`):
Tokenizer from `tiktoken` library. If `encodin... |
Converts given `tiktoken` encoding to `PretrainedTokenizerFast` and saves the configuration of converted tokenizer
on disk.
Args:
encoding (`str` or `tiktoken.Encoding`):
Tokenizer from `tiktoken` library. If `encoding` is `str`, the tokenizer will be loaded with
`tiktoken.... | convert_tiktoken_to_fast | python | huggingface/transformers | src/transformers/integrations/tiktoken.py | https://github.com/huggingface/transformers/blob/master/src/transformers/integrations/tiktoken.py | Apache-2.0 |
def replace_with_vptq_linear(
model,
quantization_config=None,
modules_to_not_convert=None,
current_key_name=None,
has_been_replaced=False,
):
"""
Public method that recursively replaces the Linear layers of the given model with VPTQ quantized layers.
`accelerate` is needed to use this m... |
Public method that recursively replaces the Linear layers of the given model with VPTQ quantized layers.
`accelerate` is needed to use this method. Returns the converted model and a boolean that indicates if the
conversion has been successful or not.
Args:
model (`torch.nn.Module`):
... | replace_with_vptq_linear | python | huggingface/transformers | src/transformers/integrations/vptq.py | https://github.com/huggingface/transformers/blob/master/src/transformers/integrations/vptq.py | Apache-2.0 |
def forward(self, outputs, targets):
"""
Differences:
- out_prob = outputs["logits"].flatten(0, 1).sigmoid() instead of softmax
- class_cost uses alpha and gamma
"""
batch_size, num_queries = outputs["logits"].shape[:2]
# We flatten to compute the cost matrices i... |
Differences:
- out_prob = outputs["logits"].flatten(0, 1).sigmoid() instead of softmax
- class_cost uses alpha and gamma
| forward | python | huggingface/transformers | src/transformers/loss/loss_deformable_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_deformable_detr.py | Apache-2.0 |
def bbox2distance(points, bbox, max_num_bins, reg_scale, up, eps=0.1):
"""
Converts bounding box coordinates to distances from a reference point.
Args:
points (Tensor): (n, 4) [x, y, w, h], where (x, y) is the center.
bbox (Tensor): (n, 4) bounding boxes in "xyxy" format.
max_num_bi... |
Converts bounding box coordinates to distances from a reference point.
Args:
points (Tensor): (n, 4) [x, y, w, h], where (x, y) is the center.
bbox (Tensor): (n, 4) bounding boxes in "xyxy" format.
max_num_bins (float): Maximum bin value.
reg_scale (float): Controlling curvartu... | bbox2distance | python | huggingface/transformers | src/transformers/loss/loss_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_d_fine.py | Apache-2.0 |
def sigmoid_focal_loss(
inputs: torch.Tensor,
targets: torch.Tensor,
num_boxes: int,
alpha: float = 0.25,
gamma: float = 2,
):
"""
Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002.
Args:
inputs (`torch.FloatTensor` of arbitrary shape):
The... |
Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002.
Args:
inputs (`torch.FloatTensor` of arbitrary shape):
The predictions for each example.
targets (`torch.FloatTensor` with the same shape as `inputs`)
A tensor storing the binary classificatio... | sigmoid_focal_loss | python | huggingface/transformers | src/transformers/loss/loss_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_grounding_dino.py | Apache-2.0 |
def forward(self, outputs, targets):
"""
Args:
outputs (`dict`):
A dictionary that contains at least these entries:
* "logits": Tensor of dim [batch_size, num_queries, num_classes] with the classification logits
* "pred_boxes": Tensor of dim [b... |
Args:
outputs (`dict`):
A dictionary that contains at least these entries:
* "logits": Tensor of dim [batch_size, num_queries, num_classes] with the classification logits
* "pred_boxes": Tensor of dim [batch_size, num_queries, 4] with the predicted bo... | forward | python | huggingface/transformers | src/transformers/loss/loss_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_grounding_dino.py | Apache-2.0 |
def _get_target_classes_one_hot(self, outputs, targets, indices):
"""
Create one_hot based on the matching indices
"""
logits = outputs["logits"]
# Add offsets to class_labels to select the correct label map
class_labels = torch.cat(
[
target["... |
Create one_hot based on the matching indices
| _get_target_classes_one_hot | python | huggingface/transformers | src/transformers/loss/loss_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_grounding_dino.py | Apache-2.0 |
def forward(self, outputs, targets):
"""Performs the matching
Params:
outputs: This is a dict that contains at least these entries:
"logits": Tensor of dim [batch_size, num_queries, num_classes] with the classification logits
"pred_boxes": Tensor of dim [ba... | Performs the matching
Params:
outputs: This is a dict that contains at least these entries:
"logits": Tensor of dim [batch_size, num_queries, num_classes] with the classification logits
"pred_boxes": Tensor of dim [batch_size, num_queries, 4] with the predicted box... | forward | python | huggingface/transformers | src/transformers/loss/loss_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_rt_detr.py | Apache-2.0 |
def loss_labels(self, outputs, targets, indices, num_boxes, log=True):
"""Classification loss (NLL)
targets dicts must contain the key "class_labels" containing a tensor of dim [nb_target_boxes]
"""
if "logits" not in outputs:
raise KeyError("No logits were found in the outpu... | Classification loss (NLL)
targets dicts must contain the key "class_labels" containing a tensor of dim [nb_target_boxes]
| loss_labels | python | huggingface/transformers | src/transformers/loss/loss_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_rt_detr.py | Apache-2.0 |
def loss_cardinality(self, outputs, targets, indices, num_boxes):
"""
Compute the cardinality error, i.e. the absolute error in the number of predicted non-empty boxes. This is not
really a loss, it is intended for logging purposes only. It doesn't propagate gradients.
"""
logits... |
Compute the cardinality error, i.e. the absolute error in the number of predicted non-empty boxes. This is not
really a loss, it is intended for logging purposes only. It doesn't propagate gradients.
| loss_cardinality | python | huggingface/transformers | src/transformers/loss/loss_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_rt_detr.py | Apache-2.0 |
def loss_boxes(self, outputs, targets, indices, num_boxes):
"""
Compute the losses related to the bounding boxes, the L1 regression loss and the GIoU loss. Targets dicts must
contain the key "boxes" containing a tensor of dim [nb_target_boxes, 4]. The target boxes are expected in
format ... |
Compute the losses related to the bounding boxes, the L1 regression loss and the GIoU loss. Targets dicts must
contain the key "boxes" containing a tensor of dim [nb_target_boxes, 4]. The target boxes are expected in
format (center_x, center_y, w, h), normalized by the image size.
| loss_boxes | python | huggingface/transformers | src/transformers/loss/loss_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_rt_detr.py | Apache-2.0 |
def loss_masks(self, outputs, targets, indices, num_boxes):
"""
Compute the losses related to the masks: the focal loss and the dice loss. Targets dicts must contain the key
"masks" containing a tensor of dim [nb_target_boxes, h, w].
"""
if "pred_masks" not in outputs:
... |
Compute the losses related to the masks: the focal loss and the dice loss. Targets dicts must contain the key
"masks" containing a tensor of dim [nb_target_boxes, h, w].
| loss_masks | python | huggingface/transformers | src/transformers/loss/loss_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/loss/loss_rt_detr.py | Apache-2.0 |
def __init__(self, config: AlbertConfig, add_pooling_layer: bool = True):
r"""
add_pooling_layer (bool, *optional*, defaults to `True`):
Whether to add a pooling layer
"""
super().__init__(config)
self.config = config
self.embeddings = AlbertEmbeddings(config... |
add_pooling_layer (bool, *optional*, defaults to `True`):
Whether to add a pooling layer
| __init__ | python | huggingface/transformers | src/transformers/models/albert/modeling_albert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/albert/modeling_albert.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 masked language modeling loss. Indices should be in `[-100, 0, ...,
config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
... | forward | python | huggingface/transformers | src/transformers/models/albert/modeling_albert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/albert/modeling_albert.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 masked language modeling loss. Indices should be in `[-100, 0, ...,
config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
... | forward | python | huggingface/transformers | src/transformers/models/albert/modeling_albert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/albert/modeling_albert.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.__call__`] and
[`PreTrainedTokenizer.encode`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/albert/modeling_albert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/albert/modeling_albert.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
token_type_ids: np.ndarray | tf.Tensor | None = None,
position_ids: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None = None,
... |
Return:
Example:
```python
>>> import tensorflow as tf
>>> from transformers import AutoTokenizer, TFAlbertForPreTraining
>>> tokenizer = AutoTokenizer.from_pretrained("albert/albert-base-v2")
>>> model = TFAlbertForPreTraining.from_pretrained("albert/albert-b... | call | python | huggingface/transformers | src/transformers/models/albert/modeling_tf_albert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/albert/modeling_tf_albert.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
token_type_ids: np.ndarray | tf.Tensor | None = None,
position_ids: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None = None,
... |
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
... | call | python | huggingface/transformers | src/transformers/models/albert/modeling_tf_albert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/albert/modeling_tf_albert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
Examples:
```python
>>> from transformers import AutoTokenizer, AlignTextModel
>>> model = AlignTextModel.from_pretrained("kakaobrain/align-base")
>>> tokenizer = AutoTokenizer.from_pretrained("kakaobrain/align-base")
>>> inputs = tokenizer(["a photo of a cat", "a pho... | forward | python | huggingface/transformers | src/transformers/models/align/modeling_align.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/align/modeling_align.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple, BaseModelOutputWithPoolingAndNoAttention]:
r"""
Examples:
```python
>>> from PIL im... |
Examples:
```python
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, AlignVisionModel
>>> model = AlignVisionModel.from_pretrained("kakaobrain/align-base")
>>> processor = AutoProcessor.from_pretrained("kakaobrain/align-... | forward | python | huggingface/transformers | src/transformers/models/align/modeling_align.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/align/modeling_align.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,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask:... |
return_loss (`bool`, *optional*):
Whether or not to return the contrastive loss.
Examples:
```python
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, AlignModel
>>> model = AlignModel.from_pretrained("kakaob... | forward | python | huggingface/transformers | src/transformers/models/align/modeling_align.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/align/modeling_align.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[AlignProcessorKwargs],
) -> BatchEncoding:
"""
Main method to prepare t... |
Main method to prepare text(s) and image(s) to be fed as input to the model. This method forwards the `text`
arguments to BertTokenizerFast's [`~BertTokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` arguments to
... | __call__ | python | huggingface/transformers | src/transformers/models/align/processing_align.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/align/processing_align.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
interpolate_pos_encoding: bool = False,
return_dict: Optional[bool] = None,
) -> Union[Tuple, BaseModelOutputWit... |
Examples:
```python
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, AltCLIPVisionModel
>>> model = AltCLIPVisionModel.from_pretrained("BAAI/AltCLIP")
>>> processor = AutoProcessor.from_pretrained("BAAI/AltCLIP")
... | forward | python | huggingface/transformers | src/transformers/models/altclip/modeling_altclip.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/altclip/modeling_altclip.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
Examples:
```python
>>> from transformers import AutoProcessor, AltCLIPTextModel
>>> model = AltCLIPTextModel.from_pretrained("BAAI/AltCLIP")
>>> processor = AutoProcessor.from_pretrained("BAAI/AltCLIP")
>>> texts = ["it's a cat", "it's a dog"]
>>> inputs = p... | forward | python | huggingface/transformers | src/transformers/models/altclip/modeling_altclip.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/altclip/modeling_altclip.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,
token_type_ids: Optional[torch.Tensor] = None,
return... |
return_loss (`bool`, *optional*):
Whether or not to return the contrastive loss.
Examples:
```python
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, AltCLIPModel
>>> model = AltCLIPModel.from_pretrained("BA... | forward | python | huggingface/transformers | src/transformers/models/altclip/modeling_altclip.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/altclip/modeling_altclip.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[AltClipProcessorKwargs],
) -> BatchEncoding:
"""
Main method to prepare... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to XLMRobertaTokenizerFast's [`~XLMRobertaTokenizerFast.__call__`] if `text` is not
`None` to encode the text. To prepare the image(s), this method forwards the ... | __call__ | python | huggingface/transformers | src/transformers/models/altclip/processing_altclip.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/altclip/processing_altclip.py | Apache-2.0 |
def divide_to_patches(image: np.array, patch_size: int, input_data_format) -> List[np.array]:
"""
Divides an image into patches of a specified size.
Args:
image (`np.array`):
The input image.
patch_size (`int`):
The size of each patch.
input_data_format (`Cha... |
Divides an image into patches of a specified size.
Args:
image (`np.array`):
The input image.
patch_size (`int`):
The size of each patch.
input_data_format (`ChannelDimension` or `str`):
The channel dimension format of the input image.
Returns:
... | divide_to_patches | python | huggingface/transformers | src/transformers/models/aria/image_processing_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/image_processing_aria.py | Apache-2.0 |
def preprocess(
self,
images: Union[ImageInput, List[ImageInput]],
image_mean: Optional[Union[float, List[float]]] = None,
image_std: Optional[Union[float, List[float]]] = None,
max_image_size: Optional[int] = None,
min_image_size: Optional[int] = None,
split_imag... |
Process a list of images.
Args:
images (ImageInput or list of ImageInput):
The input image or a list of images.
image_mean (`list`, *optional*, defaults to [0.5, 0.5, 0.5]):
Mean values for normalization.
image_std (`list`, *optional*... | preprocess | python | huggingface/transformers | src/transformers/models/aria/image_processing_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/image_processing_aria.py | Apache-2.0 |
def _resize_for_patching(
self, image: np.array, target_resolution: tuple, resample, input_data_format: ChannelDimension
) -> np.array:
"""
Resizes an image to a target resolution while maintaining aspect ratio.
Args:
image (np.array):
The input image.
... |
Resizes an image to a target resolution while maintaining aspect ratio.
Args:
image (np.array):
The input image.
target_resolution (tuple):
The target resolution (height, width) of the image.
resample (`PILImageResampling`):
... | _resize_for_patching | python | huggingface/transformers | src/transformers/models/aria/image_processing_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/image_processing_aria.py | Apache-2.0 |
def _pad_for_patching(
self, image: np.array, target_resolution: tuple, input_data_format: ChannelDimension
) -> np.array:
"""
Pad an image to a target resolution while maintaining aspect ratio.
"""
new_resolution = get_patch_output_size(image, target_resolution, input_data_f... |
Pad an image to a target resolution while maintaining aspect ratio.
| _pad_for_patching | python | huggingface/transformers | src/transformers/models/aria/image_processing_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/image_processing_aria.py | Apache-2.0 |
def pad(
self,
image: np.ndarray,
padding: Union[int, Tuple[int, int], Iterable[Tuple[int, int]]],
mode: PaddingMode = PaddingMode.CONSTANT,
constant_values: Union[float, Iterable[float]] = 0.0,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_dat... |
Pads the `image` with the specified `padding` and `mode`. Padding can be in the (`height`, `width`)
dimension of in the (`num_patches`) dimension. In the second case an iterable if tuples is expected
as input.
Args:
image (`np.ndarray`):
The image to pad.
... | pad | python | huggingface/transformers | src/transformers/models/aria/image_processing_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/image_processing_aria.py | Apache-2.0 |
def get_image_patches(
self,
image: np.array,
grid_pinpoints: List[Tuple[int, int]],
patch_size: int,
resample: PILImageResampling,
data_format: ChannelDimension,
input_data_format: ChannelDimension,
) -> List[np.array]:
"""
Process an image wi... |
Process an image with variable resolutions by dividing it into patches.
Args:
image (`np.array`):
The input image to be processed.
grid_pinpoints (List[Tuple[int, int]]):
A list of possible resolutions as tuples.
patch_size (`int`):
... | get_image_patches | python | huggingface/transformers | src/transformers/models/aria/image_processing_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/image_processing_aria.py | Apache-2.0 |
def get_number_of_image_patches(self, height: int, width: int, images_kwargs=None):
"""
A utility that returns number of image patches for a given image size.
Args:
height (`int`):
Height of the input image.
width (`int`):
Width of the inp... |
A utility that returns number of image patches for a given image size.
Args:
height (`int`):
Height of the input image.
width (`int`):
Width of the input image.
images_kwargs (`dict`, *optional*)
Any kwargs to override... | get_number_of_image_patches | python | huggingface/transformers | src/transformers/models/aria/image_processing_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/image_processing_aria.py | Apache-2.0 |
def forward(self, key_value_states, hidden_states, attn_mask=None):
"""
Forward pass of the AriaCrossAttention module.
Args:
key_value_states (`torch.Tensor`):
Input tensor for key and value.
hidden_states (`torch.Tensor`):
Input tensor fo... |
Forward pass of the AriaCrossAttention module.
Args:
key_value_states (`torch.Tensor`):
Input tensor for key and value.
hidden_states (`torch.Tensor`):
Input tensor for query.
attn_mask (`torch.Tensor`, *optional*, defaults to None):
... | forward | python | huggingface/transformers | src/transformers/models/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.py | Apache-2.0 |
def forward(self, key_value_states: torch.Tensor, attn_mask: Optional[torch.Tensor] = None):
"""
Forward pass of the Projector module.
Args:
key_value_states (`torch.Tensor`):
Input tensor of shape (batch_size, num_patches, kv_dim).
attn_mask (`torch.Tens... |
Forward pass of the Projector module.
Args:
key_value_states (`torch.Tensor`):
Input tensor of shape (batch_size, num_patches, kv_dim).
attn_mask (`torch.Tensor`, *optional*, default is None):
Attention mask.
Returns:
`torch.... | forward | python | huggingface/transformers | src/transformers/models/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.py | Apache-2.0 |
def sequential_experts_gemm(token_states, expert_weights, tokens_per_expert):
"""
Compute the matrix multiplication (GEMM) for each expert sequentially. This approach is computationally inefficient, especially when dealing with a large number of experts.
Args:
token_states (torch.Tensor): Input ten... |
Compute the matrix multiplication (GEMM) for each expert sequentially. This approach is computationally inefficient, especially when dealing with a large number of experts.
Args:
token_states (torch.Tensor): Input tensor of shape (num_tokens, in_features).
expert_weights (torch.Tensor): Weight... | sequential_experts_gemm | python | huggingface/transformers | src/transformers/models/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.py | Apache-2.0 |
def forward(self, input, tokens_per_expert):
"""
Perform grouped matrix multiplication.
Args:
input (`torch.Tensor`):
Input tensor of shape (num_tokens, in_features).
tokens_per_expert (`torch.Tensor`):
Number of tokens assigned to each ex... |
Perform grouped matrix multiplication.
Args:
input (`torch.Tensor`):
Input tensor of shape (num_tokens, in_features).
tokens_per_expert (`torch.Tensor`):
Number of tokens assigned to each expert.
Returns:
torch.Tensor: Output... | forward | python | huggingface/transformers | src/transformers/models/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.py | Apache-2.0 |
def forward(self, permuted_tokens, tokens_per_expert):
"""
Forward pass of the Grouped MLP.
Args:
permuted_tokens (torch.Tensor): Permuted input tokens.
tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
Returns:
torch.Tensor... |
Forward pass of the Grouped MLP.
Args:
permuted_tokens (torch.Tensor): Permuted input tokens.
tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
Returns:
torch.Tensor: Output tensor after passing through the MLP.
| forward | python | huggingface/transformers | src/transformers/models/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.py | Apache-2.0 |
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
"""
Forward pass of the MoE Layer.
Args:
hidden_states (`torch.Tensor`):
Input tensor of shape (batch_size, sequence_length, hidden_size).
Returns:
torch.Tensor: Output tensor after ... |
Forward pass of the MoE Layer.
Args:
hidden_states (`torch.Tensor`):
Input tensor of shape (batch_size, sequence_length, hidden_size).
Returns:
torch.Tensor: Output tensor after passing through the MoE layer.
Process:
1. Route tokens to... | forward | python | huggingface/transformers | src/transformers/models/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.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/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.py | Apache-2.0 |
def get_image_features(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.FloatTensor] = None,
vision_feature_layer: int = -1,
):
"""
Obtains image last hidden states from the vision tower and apply multimodal projection.
Args:
pix... |
Obtains image last hidden states from the vision tower and apply multimodal projection.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, channels, height, width)`):
The tensors corresponding to the input images.
pixel_mask (`torch.FloatTensor]`, *o... | get_image_features | python | huggingface/transformers | src/transformers/models/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
pixel_mask: torch.LongTensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[List[torch... |
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 `model.image_token_id` (where `model` is your instance of `AriaForConditionalGeneration`... | forward | python | huggingface/transformers | src/transformers/models/aria/modeling_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modeling_aria.py | Apache-2.0 |
def __call__(
self,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]],
images: Optional[ImageInput] = None,
audio=None,
videos=None,
**kwargs: Unpack[AriaProcessorKwargs],
) -> BatchFeature:
"""
Main method to prepare ... |
Main method to prepare for the model one or several sequences(s) and image(s).
Args:
text (`TextInput`, `PreTokenizedInput`, `List[TextInput]`, `List[PreTokenizedInput]`):
The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
... | __call__ | python | huggingface/transformers | src/transformers/models/aria/modular_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modular_aria.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[int]]`, *optional*):
The input sizes formatted as (height, width) per each ... |
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (`List[List[int]]`, *optional*):
The input sizes formatted as (height, width) per each image.
Returns:
`MultiModalData`: A `MultiModalData` obje... | _get_num_multimodal_tokens | python | huggingface/transformers | src/transformers/models/aria/modular_aria.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aria/modular_aria.py | Apache-2.0 |
def forward(
self,
input_values: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple, BaseModelOutputWithPo... |
input_values (`torch.FloatTensor` of shape `(batch_size, max_length, num_mel_bins)`):
Float values mel features extracted from the raw audio waveform. Raw audio waveform can be obtained by
loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a `numpy.ndarray`, *... | forward | python | huggingface/transformers | src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py | Apache-2.0 |
def forward(
self,
input_values: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = No... |
input_values (`torch.FloatTensor` of shape `(batch_size, max_length, num_mel_bins)`):
Float values mel features extracted from the raw audio waveform. Raw audio waveform can be obtained by
loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a `numpy.ndarray`, *... | forward | python | huggingface/transformers | src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py | Apache-2.0 |
def add_generation_mixin_to_remote_model(model_class):
"""
Adds `GenerationMixin` to the inheritance of `model_class`, if `model_class` is a PyTorch model.
This function is used for backwards compatibility purposes: in v4.45, we've started a deprecation cycle to make
`PreTrainedModel` stop inheriting f... |
Adds `GenerationMixin` to the inheritance of `model_class`, if `model_class` is a PyTorch model.
This function is used for backwards compatibility purposes: in v4.45, we've started a deprecation cycle to make
`PreTrainedModel` stop inheriting from `GenerationMixin`. Without this function, older models dyn... | add_generation_mixin_to_remote_model | python | huggingface/transformers | src/transformers/models/auto/auto_factory.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/auto/auto_factory.py | Apache-2.0 |
def register(
config_class,
image_processor_class=None,
slow_image_processor_class=None,
fast_image_processor_class=None,
exist_ok=False,
):
"""
Register a new image processor for this class.
Args:
config_class ([`PretrainedConfig`]):
... |
Register a new image processor for this class.
Args:
config_class ([`PretrainedConfig`]):
The configuration corresponding to the model to register.
image_processor_class ([`ImageProcessingMixin`]): The image processor to register.
| register | python | huggingface/transformers | src/transformers/models/auto/image_processing_auto.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/auto/image_processing_auto.py | Apache-2.0 |
def register(
config_class,
video_processor_class,
exist_ok=False,
):
"""
Register a new video processor for this class.
Args:
config_class ([`PretrainedConfig`]):
The configuration corresponding to the model to register.
video... |
Register a new video processor for this class.
Args:
config_class ([`PretrainedConfig`]):
The configuration corresponding to the model to register.
video_processor_class ([`BaseVideoProcessor`]):
The video processor to register.
| register | python | huggingface/transformers | src/transformers/models/auto/video_processing_auto.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/auto/video_processing_auto.py | Apache-2.0 |
def forward(
self, data: torch.Tensor, observed_indicator: torch.Tensor
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""
Parameters:
data (`torch.Tensor` of shape `(batch_size, sequence_length, num_input_channels)`):
input for Batch norm calculation
... |
Parameters:
data (`torch.Tensor` of shape `(batch_size, sequence_length, num_input_channels)`):
input for Batch norm calculation
observed_indicator (`torch.BoolTensor` of shape `(batch_size, sequence_length, num_input_channels)`):
Calculating the scale on... | forward | python | huggingface/transformers | src/transformers/models/autoformer/modeling_autoformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/autoformer/modeling_autoformer.py | Apache-2.0 |
def forward(
self, data: torch.Tensor, observed_indicator: Optional[torch.Tensor] = None
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""
Parameters:
data (`torch.Tensor` of shape `(batch_size, sequence_length, num_input_channels)`):
input for Batch norm ... |
Parameters:
data (`torch.Tensor` of shape `(batch_size, sequence_length, num_input_channels)`):
input for Batch norm calculation
Returns:
tuple of `torch.Tensor` of shapes
(`(batch_size, sequence_length, num_input_channels)`,`(batch_size, 1, num_i... | forward | python | huggingface/transformers | src/transformers/models/autoformer/modeling_autoformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/autoformer/modeling_autoformer.py | Apache-2.0 |
def forward(
self,
past_values: torch.Tensor,
past_time_features: torch.Tensor,
past_observed_mask: torch.Tensor,
static_categorical_features: Optional[torch.Tensor] = None,
static_real_features: Optional[torch.Tensor] = None,
future_values: Optional[torch.Tensor]... |
past_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
Past values of the time series, that serve as context in order to predict the future. These values may
contain lags, i.e. additional values from the past which are added in order to serve as "extra context".
... | forward | python | huggingface/transformers | src/transformers/models/autoformer/modeling_autoformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/autoformer/modeling_autoformer.py | Apache-2.0 |
def forward(
self,
past_values: torch.Tensor,
past_time_features: torch.Tensor,
past_observed_mask: torch.Tensor,
static_categorical_features: Optional[torch.Tensor] = None,
static_real_features: Optional[torch.Tensor] = None,
future_values: Optional[torch.Tensor]... |
past_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
Past values of the time series, that serve as context in order to predict the future. These values may
contain lags, i.e. additional values from the past which are added in order to serve as "extra context".
... | forward | python | huggingface/transformers | src/transformers/models/autoformer/modeling_autoformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/autoformer/modeling_autoformer.py | Apache-2.0 |
def get_image_features(
self,
pixel_values: torch.FloatTensor,
vision_feature_layer: Optional[Union[int, List[int]]] = None,
vision_feature_select_strategy: Optional[str] = None,
**kwargs,
):
"""
Obtains image last hidden states from the vision tower and apply... |
Obtains image last hidden states from the vision tower and apply multimodal projection.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, channels, height, width)`):
The tensors corresponding to the input images.
vision_feature_layer (`Union[int, Li... | get_image_features | python | huggingface/transformers | src/transformers/models/aya_vision/modeling_aya_vision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aya_vision/modeling_aya_vision.py | Apache-2.0 |
def _prompt_split_image(self, num_patches):
"""
Create a structured string representation of image tokens
Args:
num_patches: Number of patches in the image
Returns:
String with appropriate image tokens
"""
img_patches_per_tile = (self.img_size //... |
Create a structured string representation of image tokens
Args:
num_patches: Number of patches in the image
Returns:
String with appropriate image tokens
| _prompt_split_image | python | huggingface/transformers | src/transformers/models/aya_vision/processing_aya_vision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aya_vision/processing_aya_vision.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[AyaVisionProcessorKwargs],
) -> BatchFeature:
"""
M... |
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.
To prepare the vision inputs, this method forwards the `images` and `kwarg... | __call__ | python | huggingface/transformers | src/transformers/models/aya_vision/processing_aya_vision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aya_vision/processing_aya_vision.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[int]]`, *optional*):
The input sizes formatted as (height, width) per each... |
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (`List[List[int]]`, *optional*):
The input sizes formatted as (height, width) per each image.
Returns:
`MultiModalData`: A `MultiModalData` ob... | _get_num_multimodal_tokens | python | huggingface/transformers | src/transformers/models/aya_vision/processing_aya_vision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/aya_vision/processing_aya_vision.py | Apache-2.0 |
def convert_ssm_config_to_hf_config(
config_ssm: Dict,
**kwargs,
) -> BambaConfig:
"""Convert a config from mamba_ssm to a BambaConfig from here."""
hf_config: BambaConfig = BambaConfig(**kwargs)
hf_config.architectures = ["BambaForCausalLM"]
# Set important values from config and recalculate ... | Convert a config from mamba_ssm to a BambaConfig from here. | convert_ssm_config_to_hf_config | python | huggingface/transformers | src/transformers/models/bamba/convert_mamba_ssm_checkpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bamba/convert_mamba_ssm_checkpoint.py | Apache-2.0 |
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
"""Applies Rotary Position Embedding to the query and key tensors.
Removes the interleaving of cos and sin from GLM
Args:
q (`torch.Tensor`): The query tensor.
k (`torch.Tensor`): The key tensor.
cos (`to... | Applies Rotary Position Embedding to the query and key tensors.
Removes the interleaving of cos and sin from GLM
Args:
q (`torch.Tensor`): The query tensor.
k (`torch.Tensor`): The key tensor.
cos (`torch.Tensor`): The cosine part of the rotary embedding.
sin (`torch.Tensor`): ... | apply_rotary_pos_emb | python | huggingface/transformers | src/transformers/models/bamba/modeling_bamba.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bamba/modeling_bamba.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[HybridMambaAttentionDynamicCache] = None,
output_attentions: Optional[bool] = False,
use_cache:... |
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, sequence_length)` where padding elements are indicated by 0.
past_key_value ... | forward | python | huggingface/transformers | src/transformers/models/bamba/modeling_bamba.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bamba/modeling_bamba.py | Apache-2.0 |
def _update_mamba_mask(self, attention_mask, cache_position):
"""
No need for zeroing states when
1. Cached forward
2. Attending to all inputs
"""
mamba_mask = attention_mask
if cache_position[0] > 0 or (attention_mask is not None and torch.all(attention_m... |
No need for zeroing states when
1. Cached forward
2. Attending to all inputs
| _update_mamba_mask | python | huggingface/transformers | src/transformers/models/bamba/modeling_bamba.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bamba/modeling_bamba.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[HybridMambaAttentionDynamicCache] = None,
inputs_embeds: Optional[torch.FloatTensor] ... |
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/bamba/modeling_bamba.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bamba/modeling_bamba.py | Apache-2.0 |
def __init__(
self,
renormalize_logits=True,
output_scores=False,
return_dict_in_generate=False,
output_hidden_states=False,
output_attentions=False,
temperature=1.0,
do_sample=False,
coarse_semantic_pad_token=12_048,
coarse_rate_hz=75,
... | Class that holds a generation configuration for [`BarkCoarseModel`].
This configuration inherit from [`GenerationConfig`] and can be used to control the model generation. Read the
documentation from [`GenerationConfig`] for more information.
Args:
renormalize_logits (`bool`, *optio... | __init__ | python | huggingface/transformers | src/transformers/models/bark/generation_configuration_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/generation_configuration_bark.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
past_key_values: Optional[Tuple[torch.FloatTensor]] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
labels: O... |
input_embeds (`torch.FloatTensor` of shape `(batch_size, input_sequence_length, hidden_size)`, *optional*):
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
Here, due to `Bark` particularities, if `past_key_values` is used, `input_em... | forward | python | huggingface/transformers | src/transformers/models/bark/modeling_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/modeling_bark.py | Apache-2.0 |
def resize_token_embeddings(
self,
new_num_tokens: Optional[int] = None,
pad_to_multiple_of: Optional[int] = None,
mean_resizing: bool = True,
) -> nn.Embedding:
"""
Resizes input token embeddings matrix of the model if `new_num_tokens != config.vocab_size`.
... |
Resizes input token embeddings matrix of the model if `new_num_tokens != config.vocab_size`.
Takes care of tying weights embeddings afterwards if the model class has a `tie_weights()` method.
Arguments:
new_num_tokens (`int`, *optional*):
The number of new tokens i... | resize_token_embeddings | python | huggingface/transformers | src/transformers/models/bark/modeling_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/modeling_bark.py | Apache-2.0 |
def forward(
self,
codebook_idx: int, # an additional idx corresponding to the id of the codebook that will be predicted
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optio... |
codebook_idx (`int`):
Index of the codebook that will be predicted.
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
NOT IMPLEMENTED YET.
input_embeds (`torch.FloatTensor` of shape `(batch_size, input_sequence_length, hidden_size)`, *opti... | forward | python | huggingface/transformers | src/transformers/models/bark/modeling_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/modeling_bark.py | Apache-2.0 |
def enable_cpu_offload(
self,
accelerator_id: Optional[int] = 0,
**kwargs,
):
r"""
Offloads all sub-models to CPU using accelerate, reducing memory usage with a low impact on performance. This
method moves one whole sub-model at a time to the accelerator when it is us... |
Offloads all sub-models to CPU using accelerate, reducing memory usage with a low impact on performance. This
method moves one whole sub-model at a time to the accelerator when it is used, and the sub-model remains in accelerator until the next sub-model runs.
Args:
accelerator_id ... | enable_cpu_offload | python | huggingface/transformers | src/transformers/models/bark/modeling_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/modeling_bark.py | Apache-2.0 |
def _check_and_enable_flash_attn_2(
cls,
config,
torch_dtype: Optional[torch.dtype] = None,
device_map: Optional[Union[str, Dict[str, int]]] = None,
hard_check_only: bool = False,
check_device_map: bool = False,
):
"""
`_check_and_enable_flash_attn_2` ... |
`_check_and_enable_flash_attn_2` originally don't expand flash attention enabling to the model
sub-configurations. We override the original method to make sure that Bark sub-models are using Flash Attention
if necessary.
If you don't know about Flash Attention, check out the official r... | _check_and_enable_flash_attn_2 | python | huggingface/transformers | src/transformers/models/bark/modeling_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/modeling_bark.py | Apache-2.0 |
def from_pretrained(
cls, pretrained_processor_name_or_path, speaker_embeddings_dict_path="speaker_embeddings_path.json", **kwargs
):
r"""
Instantiate a Bark processor associated with a pretrained model.
Args:
pretrained_model_name_or_path (`str` or `os.PathLike`):
... |
Instantiate a Bark processor associated with a pretrained model.
Args:
pretrained_model_name_or_path (`str` or `os.PathLike`):
This can be either:
- a string, the *model id* of a pretrained [`BarkProcessor`] hosted inside a model repo on
h... | from_pretrained | python | huggingface/transformers | src/transformers/models/bark/processing_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/processing_bark.py | Apache-2.0 |
def save_pretrained(
self,
save_directory,
speaker_embeddings_dict_path="speaker_embeddings_path.json",
speaker_embeddings_directory="speaker_embeddings",
push_to_hub: bool = False,
**kwargs,
):
"""
Saves the attributes of this processor (tokenizer...)... |
Saves the attributes of this processor (tokenizer...) in the specified directory so that it can be reloaded
using the [`~BarkProcessor.from_pretrained`] method.
Args:
save_directory (`str` or `os.PathLike`):
Directory where the tokenizer files and the speaker embedd... | save_pretrained | python | huggingface/transformers | src/transformers/models/bark/processing_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/processing_bark.py | Apache-2.0 |
def __call__(
self,
text=None,
voice_preset=None,
return_tensors="pt",
max_length=256,
add_special_tokens=False,
return_attention_mask=True,
return_token_type_ids=False,
**kwargs,
):
"""
Main method to prepare for the model one ... |
Main method to prepare for the model one or several sequences(s). This method forwards the `text` and `kwargs`
arguments to the AutoTokenizer's [`~AutoTokenizer.__call__`] to encode the text. The method also proposes a
voice preset which is a dictionary of arrays that conditions `Bark`'s output... | __call__ | python | huggingface/transformers | src/transformers/models/bark/processing_bark.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bark/processing_bark.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
encoder_hidden_states: Optional[torch.Tensor] = None,
encoder_attention_mask: Optional[torch.Tensor] = None,
layer_head_mask: Optional[torch.Tensor] = None,
cross_attn_l... |
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
... | forward | python | huggingface/transformers | src/transformers/models/bart/modeling_bart.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bart/modeling_bart.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
encoder_hidden_states: Optional[torch.FloatTensor] = None,
encoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTra... | forward | python | huggingface/transformers | src/transformers/models/bart/modeling_bart.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bart/modeling_bart.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
Indices of decoder input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__ca... | forward | python | huggingface/transformers | src/transformers/models/bart/modeling_bart.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bart/modeling_bart.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
Indices of decoder input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__ca... | forward | python | huggingface/transformers | src/transformers/models/bart/modeling_bart.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bart/modeling_bart.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
Indices of decoder input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__ca... | forward | python | huggingface/transformers | src/transformers/models/bart/modeling_bart.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bart/modeling_bart.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
encoder_hidden_states: Optional[torch.FloatTensor] = None,
encoder_attention_mask: Optional[torch.FloatTensor] = None,
head_mask: Optional[torch.Tensor] = None,... |
cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
Mask to nullify selected heads of the cross-attention modules. Mask values selected in `[0, 1]`:
- 1 indicates the head is **not masked**,
- 0 indicates the head is **mas... | forward | python | huggingface/transformers | src/transformers/models/bart/modeling_bart.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bart/modeling_bart.py | Apache-2.0 |
def _concatenate_to_cache(self, key, value, query, attention_mask):
"""
This function takes projected key, value states from a single input token and concatenates the states to cached
states from previous steps. This function is slightly adapted from the official Flax repository:
https:/... |
This function takes projected key, value states from a single input token and concatenates the states to cached
states from previous steps. This function is slightly adapted from the official Flax repository:
https://github.com/google/flax/blob/491ce18759622506588784b4fca0e4bf05f8c8cd/flax/line... | _concatenate_to_cache | python | huggingface/transformers | src/transformers/models/bart/modeling_flax_bart.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bart/modeling_flax_bart.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
inputs_embeds: np.ndarray | tf.Tensor | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
position_ids: np.ndarray | tf.Tensor | None = None,
encoder_hidden_states: np.ndarray | tf.Tensor | None =... |
Args:
input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTok... | call | python | huggingface/transformers | src/transformers/models/bart/modeling_tf_bart.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bart/modeling_tf_bart.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 save support of deprecated `reduce_labels` in old configs
"""
image_processor_dict = image_processor_dict.copy()
if "reduce_labels" in image_processor_d... |
Overrides the `from_dict` method from the base class to save support of deprecated `reduce_labels` in old configs
| from_dict | python | huggingface/transformers | src/transformers/models/beit/image_processing_beit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/beit/image_processing_beit.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
segmentation_maps: Optional[ImageInput] = None,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_center_crop: Optional[bool] = None,
crop_size: Option... |
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
... | preprocess | python | huggingface/transformers | src/transformers/models/beit/image_processing_beit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/beit/image_processing_beit.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
segmentation_maps: Optional[ImageInput] = None,
**kwargs: Unpack[BeitFastImageProcessorKwargs],
) -> BatchFeature:
r"""
segmentation_maps (`ImageInput`, *optional*):
The segmentation maps to preprocess.
"""... |
segmentation_maps (`ImageInput`, *optional*):
The segmentation maps to preprocess.
| preprocess | python | huggingface/transformers | src/transformers/models/beit/image_processing_beit_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/beit/image_processing_beit_fast.py | Apache-2.0 |
def generate_relative_position_index(self, window_size: Tuple[int, int]) -> torch.Tensor:
"""
This method creates the relative position index, modified to support arbitrary window sizes,
as introduced in [MiDaS v3.1](https://arxiv.org/abs/2307.14460).
"""
num_relative_distance = ... |
This method creates the relative position index, modified to support arbitrary window sizes,
as introduced in [MiDaS v3.1](https://arxiv.org/abs/2307.14460).
| generate_relative_position_index | python | huggingface/transformers | src/transformers/models/beit/modeling_beit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/beit/modeling_beit.py | Apache-2.0 |
def forward(self, window_size, interpolate_pos_encoding: bool = False, dim_size=None) -> torch.Tensor:
"""
Modification of timm.models.beit.py: Attention._get_rel_pos_bias to support arbitrary window sizes.
"""
old_height = 2 * self.window_size[0] - 1
old_width = 2 * self.window_... |
Modification of timm.models.beit.py: Attention._get_rel_pos_bias to support arbitrary window sizes.
| forward | python | huggingface/transformers | src/transformers/models/beit/modeling_beit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/beit/modeling_beit.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
bool_masked_pos: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Opt... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the image classification/regre... | forward | python | huggingface/transformers | src/transformers/models/beit/modeling_beit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/beit/modeling_beit.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/beit/modeling_beit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/beit/modeling_beit.py | Apache-2.0 |
def forward(
self,
pixel_values: Tensor,
output_hidden_states: Optional[bool] = None,
output_attentions: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers import Auto... |
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/beit/modeling_beit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/beit/modeling_beit.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked),
... | forward | python | huggingface/transformers | src/transformers/models/bert/modeling_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/modeling_bert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the 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/bert/modeling_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/modeling_bert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the next sequence prediction (classification) loss. Input should be a sequence pair
(see `input_ids` docstring). Indices should be in `[0, 1]`:
- 0 indicates sequence B is a continuation ... | forward | python | huggingface/transformers | src/transformers/models/bert/modeling_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/modeling_bert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
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/bert/modeling_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/modeling_bert.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
token_type_ids: np.ndarray | tf.Tensor | None = None,
position_ids: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None = None,
... |
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
... | call | python | huggingface/transformers | src/transformers/models/bert/modeling_tf_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/modeling_tf_bert.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
token_type_ids: np.ndarray | tf.Tensor | None = None,
position_ids: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None = None,
... |
Return:
Examples:
```python
>>> import tensorflow as tf
>>> from transformers import AutoTokenizer, TFBertForNextSentencePrediction
>>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
>>> model = TFBertForNextSentencePrediction.from_... | call | python | huggingface/transformers | src/transformers/models/bert/modeling_tf_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/modeling_tf_bert.py | Apache-2.0 |
def tokenize(self, text):
"""
Tokenizes a piece of text into its word pieces. This uses a greedy longest-match-first algorithm to perform
tokenization using the given vocabulary.
For example, `input = "unaffable"` will return as output `["un", "##aff", "##able"]`.
Args:
... |
Tokenizes a piece of text into its word pieces. This uses a greedy longest-match-first algorithm to perform
tokenization using the given vocabulary.
For example, `input = "unaffable"` will return as output `["un", "##aff", "##able"]`.
Args:
text: A single token or whitespa... | tokenize | python | huggingface/transformers | src/transformers/models/bert/tokenization_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/tokenization_bert.py | Apache-2.0 |
def from_tokenizer(cls, tokenizer: "PreTrainedTokenizerBase", **kwargs): # noqa: F821
"""
Initialize a `TFBertTokenizer` from an existing `Tokenizer`.
Args:
tokenizer (`PreTrainedTokenizerBase`):
The tokenizer to use to initialize the `TFBertTokenizer`.
Exa... |
Initialize a `TFBertTokenizer` from an existing `Tokenizer`.
Args:
tokenizer (`PreTrainedTokenizerBase`):
The tokenizer to use to initialize the `TFBertTokenizer`.
Examples:
```python
from transformers import AutoTokenizer, TFBertTokenizer
... | from_tokenizer | python | huggingface/transformers | src/transformers/models/bert/tokenization_bert_tf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/tokenization_bert_tf.py | Apache-2.0 |
def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], *init_inputs, **kwargs):
"""
Instantiate a `TFBertTokenizer` from a pre-trained tokenizer.
Args:
pretrained_model_name_or_path (`str` or `os.PathLike`):
The name or path to the pre-train... |
Instantiate a `TFBertTokenizer` from a pre-trained tokenizer.
Args:
pretrained_model_name_or_path (`str` or `os.PathLike`):
The name or path to the pre-trained tokenizer.
Examples:
```python
from transformers import TFBertTokenizer
tf_toke... | from_pretrained | python | huggingface/transformers | src/transformers/models/bert/tokenization_bert_tf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert/tokenization_bert_tf.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,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
encoder_hidden_states: ... |
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/bert_generation/modeling_bert_generation.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert_generation/modeling_bert_generation.py | Apache-2.0 |
def __init__(
self,
do_lower_case=False,
never_split=None,
normalize_text=True,
trim_whitespace=False,
sudachi_split_mode="A",
sudachi_config_path=None,
sudachi_resource_dir=None,
sudachi_dict_type="core",
sudachi_projection=None,
):
... |
Constructs a SudachiTokenizer.
Args:
**do_lower_case**: (*optional*) boolean (default True)
Whether to lowercase the input.
**never_split**: (*optional*) list of str
Kept for backward compatibility purposes. Now implemented directly at the base c... | __init__ | python | huggingface/transformers | src/transformers/models/bert_japanese/tokenization_bert_japanese.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert_japanese/tokenization_bert_japanese.py | Apache-2.0 |
def tokenize(self, text):
"""
Tokenizes a piece of text into characters.
For example, `input = "apple""` will return as output `["a", "p", "p", "l", "e"]`.
Args:
text: A single token or whitespace separated tokens.
This should have already been passed throug... |
Tokenizes a piece of text into characters.
For example, `input = "apple""` will return as output `["a", "p", "p", "l", "e"]`.
Args:
text: A single token or whitespace separated tokens.
This should have already been passed through *BasicTokenizer*.
Returns:... | tokenize | python | huggingface/transformers | src/transformers/models/bert_japanese/tokenization_bert_japanese.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bert_japanese/tokenization_bert_japanese.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
encoder_hidden_states: Optional[torch.Tensor] = None,
encoder_attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
cross... |
Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTra... | forward | python | huggingface/transformers | src/transformers/models/bigbird_pegasus/modeling_bigbird_pegasus.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/bigbird_pegasus/modeling_bigbird_pegasus.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.