code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
bbox: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_m... |
input_ids (`torch.LongTensor` of shape `(batch_size, token_sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for [CLS]
token. See `pixel_values` for `patch_seq... | forward | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
bbox: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_m... |
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
Bounding boxes of each input sequence tokens. Selected in the range `[0,
config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
format, whe... | forward | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_layoutlmv3.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,
... |
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
Bounding boxes of each input sequence tokens. Selected in the range `[0,
config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
format, whe... | forward | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_layoutlmv3.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,
... |
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
Bounding boxes of each input sequence tokens. Selected in the range `[0,
config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
format, whe... | forward | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_layoutlmv3.py | Apache-2.0 |
def cogview_attention(self, attention_scores: tf.Tensor, alpha: Union[float, int] = 32):
"""
https://arxiv.org/abs/2105.13290 Section 2.4 Stabilization of training: Precision Bottleneck Relaxation
(PB-Relax). A replacement of the original keras.layers.Softmax(axis=-1)(attention_scores). Seems th... | ERROR: type should be string, got "\n https://arxiv.org/abs/2105.13290 Section 2.4 Stabilization of training: Precision Bottleneck Relaxation\n (PB-Relax). A replacement of the original keras.layers.Softmax(axis=-1)(attention_scores). Seems the new\n attention_probs will result in a slower speed and a little bias. Can use\n tf.debugging.assert_near(standard_attention_probs, cogview_attention_probs, atol=1e-08) for comparison. The\n smaller atol (e.g., 1e-08), the better.\n " | cogview_attention | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | Apache-2.0 |
def call(
self,
input_ids: tf.Tensor | None = None,
bbox: tf.Tensor | None = None,
attention_mask: tf.Tensor | None = None,
token_type_ids: tf.Tensor | None = None,
position_ids: tf.Tensor | None = None,
head_mask: tf.Tensor | None = None,
inputs_embeds: t... |
Returns:
Examples:
```python
>>> from transformers import AutoProcessor, TFAutoModel
>>> from datasets import load_dataset
>>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False)
>>> model = TFAutoModel.from_pretrained("micr... | call | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | Apache-2.0 |
def call(
self,
input_ids: tf.Tensor | None = None,
attention_mask: tf.Tensor | None = None,
token_type_ids: tf.Tensor | None = None,
position_ids: tf.Tensor | None = None,
head_mask: tf.Tensor | None = None,
inputs_embeds: tf.Tensor | None = None,
labels:... |
Returns:
Examples:
```python
>>> from transformers import AutoProcessor, TFAutoModelForSequenceClassification
>>> from datasets import load_dataset
>>> import tensorflow as tf
>>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr... | call | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | Apache-2.0 |
def call(
self,
input_ids: tf.Tensor | None = None,
bbox: tf.Tensor | None = None,
attention_mask: tf.Tensor | None = None,
token_type_ids: tf.Tensor | None = None,
position_ids: tf.Tensor | None = None,
head_mask: tf.Tensor | None = None,
inputs_embeds: t... |
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
Returns:
Examples:
```python
>>> from transformers import AutoProcessor, TFAutoMo... | call | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | Apache-2.0 |
def call(
self,
input_ids: tf.Tensor | None = None,
attention_mask: tf.Tensor | None = None,
token_type_ids: tf.Tensor | None = None,
position_ids: tf.Tensor | None = None,
head_mask: tf.Tensor | None = None,
inputs_embeds: tf.Tensor | None = None,
start_p... |
start_positions (`tf.Tensor` of shape `(batch_size,)`, *optional*):
Labels for position (index) of the start of the labelled span for computing the token classification loss.
Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
... | call | python | huggingface/transformers | src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/layoutlmv3/modeling_tf_layoutlmv3.py | Apache-2.0 |
def forward(
self,
input_ids=None,
attention_mask=None,
global_attention_mask=None,
encoder_hidden_states=None,
encoder_attention_mask=None,
head_mask=None,
cross_attn_head_mask=None,
past_key_values=None,
inputs_embeds=None,
use_ca... |
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/led/modeling_led.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/led/modeling_led.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 [`LedTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__cal... | forward | python | huggingface/transformers | src/transformers/models/led/modeling_led.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/led/modeling_led.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 [`LedTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__cal... | forward | python | huggingface/transformers | src/transformers/models/led/modeling_led.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/led/modeling_led.py | Apache-2.0 |
def resize(
self,
image: torch.Tensor,
size: SizeDict,
interpolation: "F.InterpolationMode" = None,
**kwargs,
) -> torch.Tensor:
"""
Resize an image.
If size is a dict with keys "width" and "height", the image will be resized to `(size["height"],
... |
Resize an image.
If size is a dict with keys "width" and "height", the image will be resized to `(size["height"],
size["width"])`.
If size is a dict with key "shortest_edge", the shortest edge value `c` is rescaled to `int(c * (256/224))`.
The smaller edge of the image will be... | resize | python | huggingface/transformers | src/transformers/models/levit/image_processing_levit_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/levit/image_processing_levit_fast.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
bbox: 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.T... |
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
Bounding boxes of each input sequence tokens. Selected in the range `[0,
config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
format, whe... | forward | python | huggingface/transformers | src/transformers/models/lilt/modeling_lilt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/lilt/modeling_lilt.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
bbox: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_mask:... |
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
Bounding boxes of each input sequence tokens. Selected in the range `[0,
config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
format, whe... | forward | python | huggingface/transformers | src/transformers/models/lilt/modeling_lilt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/lilt/modeling_lilt.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
bbox: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_m... |
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
Bounding boxes of each input sequence tokens. Selected in the range `[0,
config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
format, whe... | forward | python | huggingface/transformers | src/transformers/models/lilt/modeling_lilt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/lilt/modeling_lilt.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
bbox: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_m... |
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
Bounding boxes of each input sequence tokens. Selected in the range `[0,
config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
format, whe... | forward | python | huggingface/transformers | src/transformers/models/lilt/modeling_lilt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/lilt/modeling_lilt.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/llama/modeling_llama.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama/modeling_llama.py | Apache-2.0 |
def is_param_same_across_shards(key):
"""
Return `False` if the parameter is different across checkpoint shards
and needs to be concatenated.
"""
patterns = [
r"language_model.layers.(\d+).(.*)layernorm.weight",
r"language_model.norm.weight",
r"router.weight",
r"feed_... |
Return `False` if the parameter is different across checkpoint shards
and needs to be concatenated.
| is_param_same_across_shards | python | huggingface/transformers | src/transformers/models/llama4/convert_llama4_weights_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/convert_llama4_weights_to_hf.py | Apache-2.0 |
def get_concat_dim(key):
"""
Return the dimension to concatenate the weights on.
"""
concat_dim_1 = [
# language dim 1 sharded weights
"feed_forward.router.weight",
"self_attn.o_proj",
"experts.gate_proj",
"experts.up_proj",
"expert.down_proj",
# "... |
Return the dimension to concatenate the weights on.
| get_concat_dim | python | huggingface/transformers | src/transformers/models/llama4/convert_llama4_weights_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/convert_llama4_weights_to_hf.py | Apache-2.0 |
def max_context_length(model_path, instruct=False):
"""256K for base, 1M for 128E instruct, 10M for 16E instruct."""
if not instruct:
return 256 * 1024
with open(os.path.join(model_path, "params.json"), "r") as f:
params = json.load(f)
params = params.get("model", params)
if params.... | 256K for base, 1M for 128E instruct, 10M for 16E instruct. | max_context_length | python | huggingface/transformers | src/transformers/models/llama4/convert_llama4_weights_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/convert_llama4_weights_to_hf.py | Apache-2.0 |
def get_factors(dividend: int) -> Set[int]:
"""
Calculate all factors of a given number, i.e. a divisor that leaves
no remainder. For example, if dividend=12, it will return {1, 2, 3, 4, 6, 12}.
Args:
dividend (int): The number to find factors for.
Returns:
set: A set containing al... |
Calculate all factors of a given number, i.e. a divisor that leaves
no remainder. For example, if dividend=12, it will return {1, 2, 3, 4, 6, 12}.
Args:
dividend (int): The number to find factors for.
Returns:
set: A set containing all factors of the number.
| get_factors | python | huggingface/transformers | src/transformers/models/llama4/image_processing_llama4_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/image_processing_llama4_fast.py | Apache-2.0 |
def get_max_res_without_distortion(
image_size: Tuple[int, int],
target_size: Tuple[int, int],
) -> Tuple[int, int]:
"""
Determines the maximum resolution to which an image can be resized to without distorting its
aspect ratio, based on the target resolution.
Args:
image_size (Tuple[int... |
Determines the maximum resolution to which an image can be resized to without distorting its
aspect ratio, based on the target resolution.
Args:
image_size (Tuple[int, int]): The original resolution of the image (height, width).
target_resolution (Tuple[int, int]): The desired resolution t... | get_max_res_without_distortion | python | huggingface/transformers | src/transformers/models/llama4/image_processing_llama4_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/image_processing_llama4_fast.py | Apache-2.0 |
def find_supported_resolutions(max_num_chunks: int, patch_size: SizeDict) -> torch.Tensor:
"""
Computes all of the allowed resolutions for a fixed number of chunks
and patch_size. Useful for when dividing an image into chunks.
Args:
max_num_chunks (int): Maximum number of chunks for processing.... |
Computes all of the allowed resolutions for a fixed number of chunks
and patch_size. Useful for when dividing an image into chunks.
Args:
max_num_chunks (int): Maximum number of chunks for processing.
patch_size (int): Size of the side of the patch.
Returns:
torch.Tensor: List... | find_supported_resolutions | python | huggingface/transformers | src/transformers/models/llama4/image_processing_llama4_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/image_processing_llama4_fast.py | Apache-2.0 |
def pad_to_best_fit(
images: "torch.Tensor",
target_size: Tuple[int, int],
background_color: Union[int, Tuple[int, int, int]] = 0,
) -> "torch.Tensor":
"""
Pads an image to fit the target size.
Args:
images (`np.ndarray`):
The images to pad.
background_color (`int` o... |
Pads an image to fit the target size.
Args:
images (`np.ndarray`):
The images to pad.
background_color (`int` or `Tuple[int, int, int]`, *optional*, defaults to 0):
The color to use for the padding. Can be an integer for single channel or a
tuple of integers... | pad_to_best_fit | python | huggingface/transformers | src/transformers/models/llama4/image_processing_llama4_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/image_processing_llama4_fast.py | Apache-2.0 |
def rescale_and_normalize(
self,
images: "torch.Tensor",
do_rescale: bool,
rescale_factor: float,
do_normalize: bool,
image_mean: Union[float, List[float]],
image_std: Union[float, List[float]],
) -> "torch.Tensor":
"""
Rescale and normalize im... |
Rescale and normalize images.
Override to rescale and normalize the images in torch.bfloat16 as in the original implementation
| rescale_and_normalize | python | huggingface/transformers | src/transformers/models/llama4/image_processing_llama4_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/image_processing_llama4_fast.py | Apache-2.0 |
def forward(
self,
input_ids: 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.FloatTensor] = Non... |
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/llama4/modeling_llama4.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/modeling_llama4.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[BaseModelOutput, Tuple[torch.Tensor, ...... |
Example:
```python
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, MllamaVisionModel
>>> checkpoint = "meta-llama/Llama-3.2-11B-Vision"
>>> model = MllamaVisionModel.from_pretrained(checkpoint)
>>> processor = ... | forward | python | huggingface/transformers | src/transformers/models/llama4/modeling_llama4.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/modeling_llama4.py | Apache-2.0 |
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/llama4/modeling_llama4.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/modeling_llama4.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[Llama4ProcessorKwargs],
) -> BatchFeature:
"""
Main... |
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/llama4/processing_llama4.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llama4/processing_llama4.py | Apache-2.0 |
def pad_to_square(
self,
image: np.ndarray,
background_color: Union[int, Tuple[int, int, int]] = 0,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
) -> np.array:
"""
Pads an image t... |
Pads an image to a square based on the longest edge.
Args:
image (`np.ndarray`):
The image to pad.
background_color (`int` or `Tuple[int, int, int]`, *optional*, defaults to 0):
The color to use for the padding. Can be an integer for single chann... | pad_to_square | python | huggingface/transformers | src/transformers/models/llava/image_processing_llava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava/image_processing_llava.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
do_pad: Optional[bool] = None,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: Optional[PILImageResampling] = None,
do_center_crop: Optional[bool] = None,
crop_size: Optional[int]... |
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/llava/image_processing_llava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava/image_processing_llava.py | Apache-2.0 |
def pad_to_square(
self,
images: "torch.Tensor",
background_color: Union[int, Tuple[int, int, int]] = 0,
) -> "torch.Tensor":
"""
Pads an image to a square based on the longest edge.
Args:
images (`np.ndarray`):
The images to pad.
... |
Pads an image to a square based on the longest edge.
Args:
images (`np.ndarray`):
The images to pad.
background_color (`int` or `Tuple[int, int, int]`, *optional*, defaults to 0):
The color to use for the padding. Can be an integer for single cha... | pad_to_square | python | huggingface/transformers | src/transformers/models/llava/image_processing_llava_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava/image_processing_llava_fast.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[LlavaProcessorKwargs],
) -> BatchFeature:
"""
Main method to prepare fo... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` a... | __call__ | python | huggingface/transformers | src/transformers/models/llava/processing_llava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava/processing_llava.py | Apache-2.0 |
def expand_to_square(image: np.array, background_color, input_data_format) -> np.array:
"""
Expands an image to a square by adding a background color.
"""
height, width = get_image_size(image, channel_dim=input_data_format)
if width == height:
return image
elif width > height:
r... |
Expands an image to a square by adding a background color.
| expand_to_square | python | huggingface/transformers | src/transformers/models/llava_next/image_processing_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/image_processing_llava_next.py | Apache-2.0 |
def _preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_center_crop: Optional[bool] = None,
crop_size: Optional[int] = None,
do_rescale: Optional[bool] = No... |
Preprocess an image or batch of images. Copy of the `preprocess` method from `CLIPImageProcessor`.
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 ... | _preprocess | python | huggingface/transformers | src/transformers/models/llava_next/image_processing_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/image_processing_llava_next.py | Apache-2.0 |
def get_image_patches(
self,
image: np.array,
grid_pinpoints,
size: tuple,
patch_size: int,
resample: PILImageResampling,
data_format: ChannelDimension,
input_data_format: ChannelDimension,
) -> List[np.array]:
"""
Process an image with... |
Process an image with variable resolutions by dividing it into patches.
Args:
image (np.array):
The input image to be processed.
grid_pinpoints (List):
A string representation of a list of possible resolutions.
size (`tuple`):
... | get_image_patches | python | huggingface/transformers | src/transformers/models/llava_next/image_processing_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/image_processing_llava_next.py | Apache-2.0 |
def _pad_for_batching(
self,
pixel_values: List[np.ndarray],
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
):
"""
Pads images on the `num_of_patches` dimension with zeros to form a batch o... |
Pads images on the `num_of_patches` dimension with zeros to form a batch of same number of patches.
Args:
pixel_values (`List[np.ndarray]`):
An array of pixel values of each images of shape (`batch_size`, `num_patches`, `image_in_3D`)
data_format (`str` or `Chan... | _pad_for_batching | python | huggingface/transformers | src/transformers/models/llava_next/image_processing_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/image_processing_llava_next.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
image_grid_pinpoints: Optional[List] = None,
resample: PILImageResampling = None,
do_center_crop: Optional[bool] = None,
crop_size: Optional[... |
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`.
do_resize (`bool`, *optional*, defaults to `self... | preprocess | python | huggingface/transformers | src/transformers/models/llava_next/image_processing_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/image_processing_llava_next.py | Apache-2.0 |
def _resize_for_patching(
self,
image: "torch.Tensor",
target_resolution: tuple,
interpolation: "F.InterpolationMode",
input_data_format: ChannelDimension,
) -> "torch.Tensor":
"""
Resizes an image to a target resolution while maintaining aspect ratio.
... |
Resizes an image to a target resolution while maintaining aspect ratio.
Args:
image ("torch.Tensor"):
The input image.
target_resolution (tuple):
The target resolution (height, width) of the image.
interpolation (`InterpolationMode`):... | _resize_for_patching | python | huggingface/transformers | src/transformers/models/llava_next/image_processing_llava_next_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/image_processing_llava_next_fast.py | Apache-2.0 |
def _get_image_patches(
self,
image: "torch.Tensor",
grid_pinpoints,
size: tuple,
patch_size: int,
interpolation: "F.InterpolationMode",
) -> List["torch.Tensor"]:
"""
Process an image with variable resolutions by dividing it into patches.
Arg... |
Process an image with variable resolutions by dividing it into patches.
Args:
image ("torch.Tensor"):
The input image to be processed.
grid_pinpoints (List):
A string representation of a list of possible resolutions.
size (`tuple`):
... | _get_image_patches | python | huggingface/transformers | src/transformers/models/llava_next/image_processing_llava_next_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/image_processing_llava_next_fast.py | Apache-2.0 |
def _pad_for_batching(
self,
pixel_values: List["torch.Tensor"],
) -> List["torch.Tensor"]:
"""
Pads images on the `num_of_patches` dimension with zeros to form a batch of same number of patches.
Args:
pixel_values (`List[torch.Tensor]`):
An array... |
Pads images on the `num_of_patches` dimension with zeros to form a batch of same number of patches.
Args:
pixel_values (`List[torch.Tensor]`):
An array of pixel values of each images of shape (`batch_size`, `num_patches`, `image_in_3D`)
Returns:
List[`t... | _pad_for_batching | python | huggingface/transformers | src/transformers/models/llava_next/image_processing_llava_next_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/image_processing_llava_next_fast.py | Apache-2.0 |
def get_image_features(
self,
pixel_values: torch.FloatTensor,
image_sizes: torch.Tensor,
vision_feature_layer: Optional[Union[int, List[int]]] = None,
vision_feature_select_strategy: Optional[str] = None,
):
"""
Obtains image last hidden states from the visio... |
Obtains image last hidden states from the vision tower and apply multimodal projection.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, num_patches, channels, height, width)`)
The tensors corresponding to the input images.
image_sizes (`torch.Tens... | get_image_features | python | huggingface/transformers | src/transformers/models/llava_next/modeling_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/modeling_llava_next.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
image_sizes: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional... |
vision_feature_select_strategy (`str`, *optional*, defaults to `"default"`):
The feature selection strategy used to select the vision feature from the vision backbone.
Can be one of `"default"` or `"full"`. If `"default"`, the CLS token is removed from the vision features.
I... | forward | python | huggingface/transformers | src/transformers/models/llava_next/modeling_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/modeling_llava_next.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
image_sizes: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional... |
vision_feature_select_strategy (`str`, *optional*, defaults to `"default"`):
The feature selection strategy used to select the vision feature from the vision backbone.
Can be one of `"default"` or `"full"`. If `"default"`, the CLS token is removed from the vision features.
I... | forward | python | huggingface/transformers | src/transformers/models/llava_next/modeling_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/modeling_llava_next.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[LlavaNextProcessorKwargs],
) -> BatchFeature:
"""
Main method to prepar... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` a... | __call__ | python | huggingface/transformers | src/transformers/models/llava_next/processing_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/processing_llava_next.py | Apache-2.0 |
def _get_unpadded_features(self, height, width, patches_height, patches_width, scale_height, scale_width):
"""
Get number of features for a given image with height/width. LLaVA-NeXT is different from LLaVA
because it divided each image into patches depending on its resolution. Therefore we need ... |
Get number of features for a given image with height/width. LLaVA-NeXT is different from LLaVA
because it divided each image into patches depending on its resolution. Therefore we need to calculate how many
patches an image is divided into and get the number of features from that.
| _get_unpadded_features | python | huggingface/transformers | src/transformers/models/llava_next/processing_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/processing_llava_next.py | Apache-2.0 |
def _get_num_multimodal_tokens(self, image_sizes=None, **kwargs):
"""
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (List[List[str]], *optional*):
The input sizes formatted as (height, width) per each im... |
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (List[List[str]], *optional*):
The input sizes formatted as (height, width) per each image.
video_sizes (List[List[str]], *optional*):
T... | _get_num_multimodal_tokens | python | huggingface/transformers | src/transformers/models/llava_next/processing_llava_next.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next/processing_llava_next.py | Apache-2.0 |
def _preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_center_crop: Optional[bool] = None,
crop_size: Optional[int] = None,
do_rescale: Optional[bool] = No... |
Preprocess an image or batch of images. Copy of the `preprocess` method from `CLIPImageProcessor`.
Args:
images (`ImageInput`):
Batch of frames (one video) to preprocess. Expects a batch of frames with pixel values ranging from 0 to 255. If
passing in images... | _preprocess | python | huggingface/transformers | src/transformers/models/llava_next_video/image_processing_llava_next_video.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next_video/image_processing_llava_next_video.py | Apache-2.0 |
def preprocess(
self,
images: VideoInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_center_crop: Optional[bool] = None,
crop_size: Optional[int] = None,
do_rescale: Optional[bool] = Non... |
Args:
images (`VideoInput`):
Videos to preprocess. Expects a single or batch of videos with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
do_resize (`bool`, *optional*, defaults to `sel... | preprocess | python | huggingface/transformers | src/transformers/models/llava_next_video/image_processing_llava_next_video.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next_video/image_processing_llava_next_video.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
pixel_values_videos: torch.FloatTensor = None,
image_sizes: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torc... |
pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, num_frames, num_channels, image_size, image_size)):
The tensors corresponding to the input videos. Pixel values can be obtained using
[`AutoImageProcessor`]. See [`LlavaNextVideoVideoProcessor.__call__`] for details. [`Llav... | forward | python | huggingface/transformers | src/transformers/models/llava_next_video/modeling_llava_next_video.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next_video/modeling_llava_next_video.py | Apache-2.0 |
def get_video_features(
self,
pixel_values: torch.FloatTensor,
vision_feature_layer: Optional[Union[int, List[int]]] = None,
vision_feature_select_strategy: Optional[str] = None,
):
"""
Obtains video last hidden states from the vision tower and apply multimodal projec... |
Obtains video last hidden states from the vision tower and apply multimodal projection.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, num_frames, channels, height, width)`)
The tensors corresponding to the input video.
vision_feature_layer (`Uni... | get_video_features | python | huggingface/transformers | src/transformers/models/llava_next_video/modeling_llava_next_video.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next_video/modeling_llava_next_video.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
pixel_values_videos: torch.FloatTensor = None,
image_sizes: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torc... |
pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, num_frames, num_channels, image_size, image_size)):
The tensors corresponding to the input videos. Pixel values can be obtained using
[`AutoImageProcessor`]. See [`LlavaNextVideoVideoProcessor.__call__`] for details. [`Llav... | forward | python | huggingface/transformers | src/transformers/models/llava_next_video/modeling_llava_next_video.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next_video/modeling_llava_next_video.py | Apache-2.0 |
def __call__(
self,
images: ImageInput = None,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
audio=None,
videos: VideoInput = None,
**kwargs: Unpack[LlavaNextVideoProcessorKwargs],
) -> BatchFeature:
"""
Ma... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` a... | __call__ | python | huggingface/transformers | src/transformers/models/llava_next_video/processing_llava_next_video.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_next_video/processing_llava_next_video.py | Apache-2.0 |
def _preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_rescale: Optional[bool] = None,
rescale_factor: Optional[float] = None,
do_normalize: Optional[bool]... |
Args:
images (`ImageInput`):
Batch of frames (one video) to preprocess. Expects a batch of frames with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
do_resize (`bool`, *optional*, defau... | _preprocess | python | huggingface/transformers | src/transformers/models/llava_onevision/image_processing_llava_onevision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_onevision/image_processing_llava_onevision.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
image_grid_pinpoints: Optional[List] = None,
resample: PILImageResampling = None,
do_rescale: Optional[bool] = None,
rescale_factor: Optional... |
Args:
images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
tensor. Both channels-first and chann... | preprocess | python | huggingface/transformers | src/transformers/models/llava_onevision/image_processing_llava_onevision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_onevision/image_processing_llava_onevision.py | Apache-2.0 |
def pack_image_features(self, image_features, image_sizes, image_newline=None, vision_aspect_ratio="anyres_max_9"):
"""
Reshape, unpad and then pack each image_feature into a single image_features tensor containing all visual vectors.
Args:
image_features (`List[torch.Tensor]` of le... |
Reshape, unpad and then pack each image_feature into a single image_features tensor containing all visual vectors.
Args:
image_features (`List[torch.Tensor]` of length num_images, each of shape `(num_patches, image_length, embed_dim)`)
List of image feature tensor, each con... | pack_image_features | python | huggingface/transformers | src/transformers/models/llava_onevision/modeling_llava_onevision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_onevision/modeling_llava_onevision.py | Apache-2.0 |
def get_image_features(
self,
pixel_values: torch.FloatTensor,
image_sizes: torch.Tensor,
vision_feature_layer: Optional[Union[int, List[int]]] = None,
vision_feature_select_strategy: Optional[str] = None,
vision_aspect_ratio: Optional[str] = None,
batch_num_image... |
Obtains image last hidden states from the vision tower and apply multimodal projection.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, num_patches, channels, height, width)`)
The tensors corresponding to the input images.
image_sizes (`torch.Tens... | get_image_features | python | huggingface/transformers | src/transformers/models/llava_onevision/modeling_llava_onevision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_onevision/modeling_llava_onevision.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
image_sizes: Optional[torch.LongTensor] = None,
pixel_values_videos: torch.FloatTensor = None,
image_sizes_videos: Optional[torch.LongTensor] = None,
attention_mask: Opt... |
pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, frames, num_channels, image_size, image_size)):
The tensors corresponding to the input videos. Pixel values can be obtained using
[`LlavaNextVideoProcessor`]. See [`LlavaNextVideoProcessor.__call__`] for details. [`LlavaPro... | forward | python | huggingface/transformers | src/transformers/models/llava_onevision/modeling_llava_onevision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_onevision/modeling_llava_onevision.py | Apache-2.0 |
def get_video_features(
self,
pixel_values: torch.FloatTensor,
vision_feature_layer: Union[int, List[int]],
vision_feature_select_strategy: str,
):
"""
Obtains video last hidden states from the vision tower, apply multimodal projection and pooling.
Args:
... |
Obtains video last hidden states from the vision tower, apply multimodal projection and pooling.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, num_frames, channels, height, width)`)
The tensors corresponding to the input video.
vision_feature_la... | get_video_features | python | huggingface/transformers | src/transformers/models/llava_onevision/modeling_llava_onevision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_onevision/modeling_llava_onevision.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
image_sizes: Optional[torch.LongTensor] = None,
pixel_values_videos: torch.FloatTensor = None,
image_sizes_videos: Optional[torch.LongTensor] = None,
attention_mask: Opt... |
pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, frames, num_channels, image_size, image_size)):
The tensors corresponding to the input videos. Pixel values can be obtained using
[`LlavaNextVideoProcessor`]. See [`LlavaNextVideoProcessor.__call__`] for details. [`LlavaPro... | forward | python | huggingface/transformers | src/transformers/models/llava_onevision/modeling_llava_onevision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_onevision/modeling_llava_onevision.py | Apache-2.0 |
def __call__(
self,
images: ImageInput = None,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
audio=None,
videos: VideoInput = None,
**kwargs: Unpack[LlavaOnevisionProcessorKwargs],
) -> BatchFeature:
"""
Ma... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` a... | __call__ | python | huggingface/transformers | src/transformers/models/llava_onevision/processing_llava_onevision.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/llava_onevision/processing_llava_onevision.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
global_attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids:... |
global_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
Mask to decide the attention given on each token, local attention or global attention. Tokens with global
attention attends to all other tokens, and all other tokens attend to them. This is... | forward | python | huggingface/transformers | src/transformers/models/longformer/modeling_longformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longformer/modeling_longformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
global_attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids:... |
global_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
Mask to decide the attention given on each token, local attention or global attention. Tokens with global
attention attends to all other tokens, and all other tokens attend to them. This is... | forward | python | huggingface/transformers | src/transformers/models/longformer/modeling_longformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longformer/modeling_longformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
global_attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids:... |
global_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
Mask to decide the attention given on each token, local attention or global attention. Tokens with global
attention attends to all other tokens, and all other tokens attend to them. This is... | forward | python | huggingface/transformers | src/transformers/models/longformer/modeling_longformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longformer/modeling_longformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
global_attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids:... |
global_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
Mask to decide the attention given on each token, local attention or global attention. Tokens with global
attention attends to all other tokens, and all other tokens attend to them. This is... | forward | python | huggingface/transformers | src/transformers/models/longformer/modeling_longformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longformer/modeling_longformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
global_attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids:... |
global_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
Mask to decide the attention given on each token, local attention or global attention. Tokens with global
attention attends to all other tokens, and all other tokens attend to them. This is... | forward | python | huggingface/transformers | src/transformers/models/longformer/modeling_longformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longformer/modeling_longformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
global_attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
labels: Optio... |
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/longformer/modeling_longformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longformer/modeling_longformer.py | Apache-2.0 |
def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task. Longformer does not
make use of token type ids, therefore... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. Longformer does not
make use of token type ids, therefore a list of zeros is returned.
Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, ... | create_token_type_ids_from_sequences | python | huggingface/transformers | src/transformers/models/longformer/tokenization_longformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longformer/tokenization_longformer.py | Apache-2.0 |
def mask_token(self) -> str:
"""
`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not
having been set.
Longformer tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily
comp... |
`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not
having been set.
Longformer tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily
comprise the space before the *<mask>*.
... | mask_token | python | huggingface/transformers | src/transformers/models/longformer/tokenization_longformer_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longformer/tokenization_longformer_fast.py | Apache-2.0 |
def _make_global_fixed_block_ids(attention_mask: np.ndarray, global_block_size: int) -> Tuple[jnp.ndarray, np.ndarray]:
"""Obtain the "fixed block" global id corresponding to each input token.
This implementation is a simplified version of the original Flaxformr implementation adopted from:
https://github.... | Obtain the "fixed block" global id corresponding to each input token.
This implementation is a simplified version of the original Flaxformr implementation adopted from:
https://github.com/google/flaxformer/blob/main/flaxformer/architectures/longt5/long_attention.py.
In our scenario, as we use this strateg... | _make_global_fixed_block_ids | python | huggingface/transformers | src/transformers/models/longt5/modeling_flax_longt5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longt5/modeling_flax_longt5.py | Apache-2.0 |
def encode(
self,
input_ids: jnp.ndarray,
attention_mask: Optional[jnp.ndarray] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
train: bool = False,
params: Optional[dict] =... |
Returns:
Example:
```python
>>> from transformers import AutoTokenizer, FlaxLongT5ForConditionalGeneration
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-base")
>>> model = FlaxLongT5ForConditionalGeneration.from_pretrained("google/long-t5-local-base")
... | encode | python | huggingface/transformers | src/transformers/models/longt5/modeling_flax_longt5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longt5/modeling_flax_longt5.py | Apache-2.0 |
def decode(
self,
decoder_input_ids,
encoder_outputs,
encoder_attention_mask: Optional[jnp.ndarray] = None,
decoder_attention_mask: Optional[jnp.ndarray] = None,
past_key_values: Optional[dict] = None,
output_attentions: Optional[bool] = None,
output_hidde... |
Returns:
Example:
```python
>>> from transformers import AutoTokenizer, FlaxLongT5ForConditionalGeneration
>>> import jax.numpy as jnp
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-base")
>>> model = FlaxLongT5ForConditionalGeneration.from_pretra... | decode | python | huggingface/transformers | src/transformers/models/longt5/modeling_flax_longt5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longt5/modeling_flax_longt5.py | Apache-2.0 |
def decode(
self,
decoder_input_ids,
encoder_outputs,
encoder_attention_mask: Optional[jnp.ndarray] = None,
decoder_attention_mask: Optional[jnp.ndarray] = None,
past_key_values: Optional[dict] = None,
output_attentions: Optional[bool] = None,
output_hidde... |
Returns:
Example:
```python
>>> from transformers import AutoTokenizer, FlaxLongT5ForConditionalGeneration
>>> import jax.numpy as jnp
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-base")
>>> model = FlaxLongT5ForConditionalGeneration.from_pretra... | decode | python | huggingface/transformers | src/transformers/models/longt5/modeling_flax_longt5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longt5/modeling_flax_longt5.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.FloatTensor] = N... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. LongT5 is a model with relative position embeddings so
you should be able to pad the inputs on both the right and the left.
Indices can be obtained u... | forward | python | huggingface/transformers | src/transformers/models/longt5/modeling_longt5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longt5/modeling_longt5.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.FloatTensor] = N... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. LongT5 is a model with relative position embeddings so
you should be able to pad the inputs on both the right and the left.
Indices can be obtained u... | forward | python | huggingface/transformers | src/transformers/models/longt5/modeling_longt5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longt5/modeling_longt5.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. LongT5 is a model with relative position embeddings so
you should be able to pad the inputs on both the right and the left.
Indices can be obtained u... | forward | python | huggingface/transformers | src/transformers/models/longt5/modeling_longt5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/longt5/modeling_longt5.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,
entity_ids: Optional[torch.LongTensor] = None,
... |
entity_ids (`torch.LongTensor` of shape `(batch_size, entity_length)`):
Indices of entity tokens in the entity vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
entity_at... | forward | python | huggingface/transformers | src/transformers/models/luke/modeling_luke.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/luke/modeling_luke.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,
entity_ids: Optional[torch.LongTensor] = None,
... |
entity_ids (`torch.LongTensor` of shape `(batch_size, entity_length)`):
Indices of entity tokens in the entity vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
entity_at... | forward | python | huggingface/transformers | src/transformers/models/luke/modeling_luke.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/luke/modeling_luke.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,
entity_ids: Optional[torch.LongTensor] = None,
... |
entity_ids (`torch.LongTensor` of shape `(batch_size, entity_length)`):
Indices of entity tokens in the entity vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
entity_at... | forward | python | huggingface/transformers | src/transformers/models/luke/modeling_luke.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/luke/modeling_luke.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.FloatTensor] = None,
entity_ids: Optional[torch.LongTensor] = None,
... |
entity_ids (`torch.LongTensor` of shape `(batch_size, entity_length)`):
Indices of entity tokens in the entity vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
entity_at... | forward | python | huggingface/transformers | src/transformers/models/luke/modeling_luke.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/luke/modeling_luke.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,
entity_ids: Optional[torch.LongTensor] = None,
... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/luke/modeling_luke.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/luke/modeling_luke.py | Apache-2.0 |
def pad(
self,
encoded_inputs: Union[
BatchEncoding,
List[BatchEncoding],
Dict[str, EncodedInput],
Dict[str, List[EncodedInput]],
List[Dict[str, EncodedInput]],
],
padding: Union[bool, str, PaddingStrategy] = True,
max_l... |
Pad a single encoded input or a batch of encoded inputs up to predefined length or to the max sequence length
in the batch. Padding side (left/right) padding token ids are defined at the tokenizer level (with
`self.padding_side`, `self.pad_token_id` and `self.pad_token_type_id`) .. note:: If th... | pad | python | huggingface/transformers | src/transformers/models/luke/tokenization_luke.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/luke/tokenization_luke.py | Apache-2.0 |
def _pad(
self,
encoded_inputs: Union[Dict[str, EncodedInput], BatchEncoding],
max_length: Optional[int] = None,
max_entity_length: Optional[int] = None,
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
pad_to_multiple_of: Optional[int] = None,
padd... |
Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
Args:
encoded_inputs:
Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
max_length: maximum length of the returned list and op... | _pad | python | huggingface/transformers | src/transformers/models/luke/tokenization_luke.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/luke/tokenization_luke.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
visual_feats: Optional[torch.FloatTensor] = None,
visual_pos: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
visual_attention_mask: Optional[torch.FloatTensor] = None... |
visual_feats (`torch.FloatTensor` of shape `(batch_size, num_visual_features, visual_feat_dim)`):
This input represents visual features. They ROI pooled object features from bounding boxes using a
faster-RCNN model)
These are currently not provided by the transformers libra... | forward | python | huggingface/transformers | src/transformers/models/lxmert/modeling_lxmert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/lxmert/modeling_lxmert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
visual_feats: Optional[torch.FloatTensor] = None,
visual_pos: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
visual_attention_mask: Optional[torch.FloatTensor] = None... |
visual_feats (`torch.FloatTensor` of shape `(batch_size, num_visual_features, visual_feat_dim)`):
This input represents visual features. They ROI pooled object features from bounding boxes using a
faster-RCNN model)
These are currently not provided by the transformers libra... | forward | python | huggingface/transformers | src/transformers/models/lxmert/modeling_lxmert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/lxmert/modeling_lxmert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
visual_feats: Optional[torch.FloatTensor] = None,
visual_pos: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
visual_attention_mask: Optional[torch.FloatTensor] = None... |
visual_feats (`torch.FloatTensor` of shape `(batch_size, num_visual_features, visual_feat_dim)`):
This input represents visual features. They ROI pooled object features from bounding boxes using a
faster-RCNN model)
These are currently not provided by the transformers libra... | forward | python | huggingface/transformers | src/transformers/models/lxmert/modeling_lxmert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/lxmert/modeling_lxmert.py | Apache-2.0 |
def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A Lxmert sequence
pair mask has the following format:
... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A Lxmert sequence
pair mask has the following format:
```
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
```
If `token_ids_1` is `Non... | create_token_type_ids_from_sequences | python | huggingface/transformers | src/transformers/models/lxmert/tokenization_lxmert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/lxmert/tokenization_lxmert.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/m2m_100/modeling_m2m_100.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/m2m_100/modeling_m2m_100.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/m2m_100/modeling_m2m_100.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/m2m_100/modeling_m2m_100.py | Apache-2.0 |
def convert_ssm_config_to_hf_config(config_ssm: MambaConfigSSM) -> MambaConfig:
"""Convert a MambaConfig from mamba_ssm to a MambaConfig from transformers."""
hf_config = MambaConfig()
# Set config hidden size, num hidden layers, and vocab size directly from the original config
hf_config... | Convert a MambaConfig from mamba_ssm to a MambaConfig from transformers. | convert_ssm_config_to_hf_config | python | huggingface/transformers | src/transformers/models/mamba/convert_mamba_ssm_checkpoint_to_pytorch.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/mamba/convert_mamba_ssm_checkpoint_to_pytorch.py | Apache-2.0 |
def validate_converted_model(
original_state_dict: dict, original_ssm_config_dict: dict, hf_model: MambaForCausalLM, tokenizer: AutoTokenizer
) -> None:
"""Validate the converted model returns the same output as the original model."""
torch_device = "cuda"
original_config = MambaConfigSSM(**original_ss... | Validate the converted model returns the same output as the original model. | validate_converted_model | python | huggingface/transformers | src/transformers/models/mamba/convert_mamba_ssm_checkpoint_to_pytorch.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/mamba/convert_mamba_ssm_checkpoint_to_pytorch.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.LongTensor] = None,
cache_params: Optional[Mamba2Cache] = None,
use_cache: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool... |
cache_params (`Mamba2Cache`, *optional*):
If passed along, the model uses the previous state in all the blocks (which will give the output for the
`input_ids` provided as if the model add `state_input_ids + input_ids` as context).
use_cache (`bool`, *optional*):
If s... | forward | python | huggingface/transformers | src/transformers/models/mamba2/modeling_mamba2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/mamba2/modeling_mamba2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
cache_params: Optional[Mamba2Cache] = None,
labels: Optional[torch.LongTensor] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Opt... |
cache_params (`Mamba2Cache`, *optional*):
If passed along, the model uses the previous state in all the blocks (which will give the output for the
`input_ids` provided as if the model add `state_input_ids + input_ids` as context).
labels (`torch.LongTensor` of shape `(batch_size... | forward | python | huggingface/transformers | src/transformers/models/mamba2/modeling_mamba2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/mamba2/modeling_mamba2.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.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
d... |
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/marian/modeling_marian.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/marian/modeling_marian.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/marian/modeling_marian.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/marian/modeling_marian.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
xpath_tags_seq: Optional[torch.LongTensor] = None,
xpath_subs_seq: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
... |
xpath_tags_seq (`torch.LongTensor` of shape `(batch_size, sequence_length, config.max_depth)`, *optional*):
Tag IDs for each token in the input sequence, padded up to config.max_depth.
xpath_subs_seq (`torch.LongTensor` of shape `(batch_size, sequence_length, config.max_depth)`, *optional*)... | forward | python | huggingface/transformers | src/transformers/models/markuplm/modeling_markuplm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/markuplm/modeling_markuplm.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
xpath_tags_seq: Optional[torch.Tensor] = None,
xpath_subs_seq: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: O... |
xpath_tags_seq (`torch.LongTensor` of shape `(batch_size, sequence_length, config.max_depth)`, *optional*):
Tag IDs for each token in the input sequence, padded up to config.max_depth.
xpath_subs_seq (`torch.LongTensor` of shape `(batch_size, sequence_length, config.max_depth)`, *optional*)... | forward | python | huggingface/transformers | src/transformers/models/markuplm/modeling_markuplm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/markuplm/modeling_markuplm.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
xpath_tags_seq: Optional[torch.Tensor] = None,
xpath_subs_seq: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: O... |
xpath_tags_seq (`torch.LongTensor` of shape `(batch_size, sequence_length, config.max_depth)`, *optional*):
Tag IDs for each token in the input sequence, padded up to config.max_depth.
xpath_subs_seq (`torch.LongTensor` of shape `(batch_size, sequence_length, config.max_depth)`, *optional*)... | forward | python | huggingface/transformers | src/transformers/models/markuplm/modeling_markuplm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/markuplm/modeling_markuplm.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
xpath_tags_seq: Optional[torch.Tensor] = None,
xpath_subs_seq: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: O... |
xpath_tags_seq (`torch.LongTensor` of shape `(batch_size, sequence_length, config.max_depth)`, *optional*):
Tag IDs for each token in the input sequence, padded up to config.max_depth.
xpath_subs_seq (`torch.LongTensor` of shape `(batch_size, sequence_length, config.max_depth)`, *optional*)... | forward | python | huggingface/transformers | src/transformers/models/markuplm/modeling_markuplm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/markuplm/modeling_markuplm.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.