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 __init__(self, config: DeiTConfig, add_pooling_layer: bool = True, use_mask_token: bool = False) -> None:
r"""
add_pooling_layer (bool, *optional*, defaults to `True`):
Whether to add a pooling layer
use_mask_token (`bool`, *optional*, defaults to `False`):
Whether to... |
add_pooling_layer (bool, *optional*, defaults to `True`):
Whether to add a pooling layer
use_mask_token (`bool`, *optional*, defaults to `False`):
Whether to use a mask token for masked image modeling.
| __init__ | python | huggingface/transformers | src/transformers/models/deit/modeling_deit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deit/modeling_deit.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
bool_masked_pos: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Option... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
Examples:
```python
>>> from transformers import AutoImageProcessor, DeiTForMaskedImageModeling
>>> impo... | forward | python | huggingface/transformers | src/transformers/models/deit/modeling_deit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deit/modeling_deit.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = No... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
`config.n... | forward | python | huggingface/transformers | src/transformers/models/deit/modeling_deit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deit/modeling_deit.py | Apache-2.0 |
def call(
self,
pixel_values: tf.Tensor | None = None,
head_mask: tf.Tensor | None = None,
labels: tf.Tensor | None = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
interpola... |
labels (`tf.Tensor` of shape `(batch_size,)`, *optional*):
Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
`config.num_labe... | call | python | huggingface/transformers | src/transformers/models/deit/modeling_tf_deit.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deit/modeling_tf_deit.py | Apache-2.0 |
def resize(
self,
image: np.ndarray,
size: Dict[str, int],
resample: PILImageResampling = PILImageResampling.BILINEAR,
data_format: Optional[ChannelDimension] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> np.ndarray:
... |
Resize the image to the given size. Size can be `min_size` (scalar) or `(height, width)` tuple. If size is an
int, smaller edge of the image will be matched to this number.
Args:
image (`np.ndarray`):
Image to resize.
size (`Dict[str, int]`):
... | resize | python | huggingface/transformers | src/transformers/models/deprecated/deta/image_processing_deta.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/deta/image_processing_deta.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
annotations: Optional[Union[List[Dict], List[List[Dict]]]] = None,
return_segmentation_masks: Optional[bool] = None,
masks_path: Optional[Union[str, pathlib.Path]] = None,
do_resize: Optional[bool] = None,
size: Optional[D... |
Preprocess an image or a batch of images so that it can be used by the model.
Args:
images (`ImageInput`):
Image or batch of images to preprocess. Expects a single or batch of images with pixel values ranging
from 0 to 255. If passing in images with pixel va... | preprocess | python | huggingface/transformers | src/transformers/models/deprecated/deta/image_processing_deta.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/deta/image_processing_deta.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
d... |
labels (`List[Dict]` of len `(batch_size,)`, *optional*):
Labels for computing the bipartite matching loss. List of dicts, each dictionary containing at least the
following 2 keys: 'class_labels' and 'boxes' (the class labels and bounding boxes of an image in the batch
respe... | forward | python | huggingface/transformers | src/transformers/models/deprecated/deta/modeling_deta.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/deta/modeling_deta.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.FloatTensor] = None,
spout: Optional[torch.FloatTensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] =... |
num_precontext (`torch.LongTensor` of shape `(batch_size,1)`):
length of `hybrid` input tokens in the input. Tokens up to this length refer to both front and back like
BERT, tokens after that refer only to front like GPT. see also:
https://github.com/tanreinama/GPTSAN/blob/m... | forward | python | huggingface/transformers | src/transformers/models/deprecated/gptsan_japanese/modeling_gptsan_japanese.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/gptsan_japanese/modeling_gptsan_japanese.py | Apache-2.0 |
def __init__(
self,
config,
n_ctx=None,
embed_dim=None,
audio_conditioning=False,
metadata_conditioning=False,
is_encoder=False,
):
"""
Autoregressive model on either lyric tokens or music tokens, or both. The attention pattern should be proper... |
Autoregressive model on either lyric tokens or music tokens, or both. The attention pattern should be properly
set for each configuration.
Args:
config (`JukeboxPriorConfig`):
Model configuration class with all the parameters of the model. Initializing with a config... | __init__ | python | huggingface/transformers | src/transformers/models/deprecated/jukebox/modeling_jukebox.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/jukebox/modeling_jukebox.py | Apache-2.0 |
def forward(self, music_tokens, raw_audio_conditioning=None):
"""
Args:
music_tokens (`torch.LongTensor`):
Music tokens form the upper level in range(nb_discrete_codes)
raw_audio_conditioning (`torch.LongTensor`, *optional*):
Audio used when primed... |
Args:
music_tokens (`torch.LongTensor`):
Music tokens form the upper level in range(nb_discrete_codes)
raw_audio_conditioning (`torch.LongTensor`, *optional*):
Audio used when primed sampling, raw audio information that conditions the generation
| forward | python | huggingface/transformers | src/transformers/models/deprecated/jukebox/modeling_jukebox.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/jukebox/modeling_jukebox.py | Apache-2.0 |
def set_metadata_lyric_tokens(self, labels):
"""
Processes the full labels to only retrieve the relevant lyric tokens and keep the metadata conditioning tokens.
"""
if self.nb_relevant_lyric_tokens > 0:
tokens_list = torch.zeros(
(labels.shape[0], self.nb_rele... |
Processes the full labels to only retrieve the relevant lyric tokens and keep the metadata conditioning tokens.
| set_metadata_lyric_tokens | python | huggingface/transformers | src/transformers/models/deprecated/jukebox/modeling_jukebox.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/jukebox/modeling_jukebox.py | Apache-2.0 |
def sample(
self,
n_samples,
music_tokens=None,
music_tokens_conds=None,
metadata=None,
temp=1.0,
top_k=0,
top_p=0.0,
chunk_size=None,
sample_tokens=None,
):
"""
Ancestral/Prime sampling a window of tokens using the prov... |
Ancestral/Prime sampling a window of tokens using the provided conditioning and metadatas.
Args:
n_samples (`int`):
Number of samples to generate.
music_tokens (`List[torch.LongTensor]`, *optional*):
Previously generated tokens at the current lev... | sample | python | huggingface/transformers | src/transformers/models/deprecated/jukebox/modeling_jukebox.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/jukebox/modeling_jukebox.py | Apache-2.0 |
def get_encoder_states(self, lyric_tokens, sample=False):
"""
Retrieve the last hidden_states of the lyric encoder that will be attended to by the decoder. Forwards through
the lyric encoder.
"""
if self.nb_relevant_lyric_tokens != 0 and self.lyric_conditioning:
if sa... |
Retrieve the last hidden_states of the lyric encoder that will be attended to by the decoder. Forwards through
the lyric encoder.
| get_encoder_states | python | huggingface/transformers | src/transformers/models/deprecated/jukebox/modeling_jukebox.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/jukebox/modeling_jukebox.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
metadata: Optional[List[torch.LongTensor]],
decode: Optional[bool] = False,
get_preds: Optional[bool] = False,
) -> List[torch.Tensor]:
"""
Encode the hidden states using the `vqvae` encoder, and then predicts th... |
Encode the hidden states using the `vqvae` encoder, and then predicts the next token in the `forward_tokens`
function. The loss is the sum of the `encoder` loss and the `decoder` loss.
Args:
hidden_states (`torch.Tensor`):
Hidden states which should be raw audio
... | forward | python | huggingface/transformers | src/transformers/models/deprecated/jukebox/modeling_jukebox.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/jukebox/modeling_jukebox.py | Apache-2.0 |
def _sample(
self,
music_tokens,
labels,
sample_levels,
metas=None,
chunk_size=32,
sampling_temperature=0.98,
lower_batch_size=16,
max_batch_size=16,
sample_length_in_seconds=24,
compute_alignments=False,
sample_tokens=None,... |
Core sampling function used to generate music tokens. Iterates over the provided list of levels, while saving
the generated raw audio at each step.
Args:
music_tokens (`List[torch.LongTensor]`):
A sequence of music tokens of length `self.levels` which will be used a... | _sample | python | huggingface/transformers | src/transformers/models/deprecated/jukebox/modeling_jukebox.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/jukebox/modeling_jukebox.py | Apache-2.0 |
def __call__(self, *args, **kwargs):
"""
When used in normal mode, this method forwards all its arguments to MCTCTFeatureExtractor's
[`~MCTCTFeatureExtractor.__call__`] and returns its output. If used in the context
[`~MCTCTProcessor.as_target_processor`] this method forwards all its arg... |
When used in normal mode, this method forwards all its arguments to MCTCTFeatureExtractor's
[`~MCTCTFeatureExtractor.__call__`] and returns its output. If used in the context
[`~MCTCTProcessor.as_target_processor`] this method forwards all its arguments to AutoTokenizer's
[`~AutoTokeniz... | __call__ | python | huggingface/transformers | src/transformers/models/deprecated/mctct/processing_mctct.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/mctct/processing_mctct.py | Apache-2.0 |
def forward(
self,
inputs,
attention_mask: Optional[torch.Tensor] = None,
prev_state: Optional[torch.Tensor] = None,
use_cache: bool = False,
) -> torch.Tensor:
"""
Mega's exponential moving average (EMA) sub-layer applied prior to single-headed (traditional) ... |
Mega's exponential moving average (EMA) sub-layer applied prior to single-headed (traditional) self-attention
Args:
inputs (`torch.Tensor` of shape `(sequence_length, batch_size, hidden_size)`):
Hidden state / embedding input to update via EMA based on FFT convolution
... | forward | python | huggingface/transformers | src/transformers/models/deprecated/mega/modeling_mega.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/mega/modeling_mega.py | Apache-2.0 |
def forward(
self,
query,
key: Optional[torch.Tensor],
value: Optional[torch.Tensor],
key_padding_mask: Optional[torch.Tensor] = None,
past_key_values: Optional[Tuple[torch.Tensor]] = None,
output_attentions: bool = False,
use_cache: bool = False,
) ->... |
Gated cross-attention used in Mega
Args:
query (`torch.Tensor` of shape `(target_sequence_length, batch_size, hidden_size)`):
The self (or target) sequence input used as query inputs for cross-attention
key (`torch.Tensor` of shape `(source_sequence_length, batc... | forward | python | huggingface/transformers | src/transformers/models/deprecated/mega/modeling_mega.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/mega/modeling_mega.py | Apache-2.0 |
def forward(
self,
input,
padding_mask: Optional[torch.Tensor] = None,
causal_mask: Optional[torch.Tensor] = None,
past_key_values: Optional[Tuple[torch.Tensor]] = None,
output_attentions=False,
use_cache=False,
):
"""
Mega's self-attention blo... |
Mega's self-attention block, which combines multi-headed EMA with traditional self-attention
Args:
input (`torch.Tensor` of shape `(sequence_length, batch_size, hidden_size)`):
Hidden states to be updated by Mega's self-attention
padding_mask (`torch.LongTensor`... | forward | python | huggingface/transformers | src/transformers/models/deprecated/mega/modeling_mega.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/mega/modeling_mega.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.LongTensor] = None,
causal_mask: Optional[torch.LongTensor] = None,
encoder_hidden_states: Optional[torch.FloatTensor] = None,
encoder_attention_mask: Optional[torch.FloatTensor] = None,
... |
A single Mega layer: either encoder or decoder, with optional cross-attention and optional normalized
feed-forward layer
Args:
hidden_states (`torch.Tensor` of shape `(target_sequence_length, batch_size, hidden_size)`):
Hidden states to be updated by the Mega block
... | forward | python | huggingface/transformers | src/transformers/models/deprecated/mega/modeling_mega.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/mega/modeling_mega.py | Apache-2.0 |
def forward(
self,
input_modal,
input_ids=None,
modal_start_tokens=None,
modal_end_tokens=None,
attention_mask=None,
token_type_ids=None,
modal_token_type_ids=None,
position_ids=None,
modal_position_ids=None,
head_mask=None,
... |
Returns:
Examples:
```python
# For example purposes. Not runnable.
transformer = BertModel.from_pretrained("google-bert/bert-base-uncased")
encoder = ImageEncoder(args)
mmbt = MMBTModel(config, transformer, encoder)
``` | forward | python | huggingface/transformers | src/transformers/models/deprecated/mmbt/modeling_mmbt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/mmbt/modeling_mmbt.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are igno... | forward | python | huggingface/transformers | src/transformers/models/deprecated/open_llama/modeling_open_llama.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/open_llama/modeling_open_llama.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_emb... |
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
the model is configured as a decoder.
encoder_attention_mask (... | forward | python | huggingface/transformers | src/transformers/models/deprecated/qdqbert/modeling_qdqbert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/qdqbert/modeling_qdqbert.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,)`, *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/deprecated/qdqbert/modeling_qdqbert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/qdqbert/modeling_qdqbert.py | Apache-2.0 |
def forward(
self,
input_ids=None,
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_cache=None,
output_attentions=... |
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 [`Speech2Text2Tokenizer`]. See ... | forward | python | huggingface/transformers | src/transformers/models/deprecated/speech_to_text_2/modeling_speech_to_text_2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/speech_to_text_2/modeling_speech_to_text_2.py | Apache-2.0 |
def __call__(self, *args, **kwargs):
"""
When used in normal mode, this method forwards all its arguments to AutoFeatureExtractor's
[`~AutoFeatureExtractor.__call__`] and returns its output. If used in the context
[`~Speech2Text2Processor.as_target_processor`] this method forwards all it... |
When used in normal mode, this method forwards all its arguments to AutoFeatureExtractor's
[`~AutoFeatureExtractor.__call__`] and returns its output. If used in the context
[`~Speech2Text2Processor.as_target_processor`] this method forwards all its arguments to
Speech2Text2Tokenizer's [... | __call__ | python | huggingface/transformers | src/transformers/models/deprecated/speech_to_text_2/processing_speech_to_text_2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/speech_to_text_2/processing_speech_to_text_2.py | Apache-2.0 |
def moses_pipeline(self, text: str) -> List[str]:
"""
Does basic tokenization using [`sacremoses.MosesPunctNormalizer`] and [`sacremoses.MosesTokenizer`] with
*aggressive_dash_splits=True* (see [`sacremoses.tokenize.MosesTokenizer.tokenize`]). Additionally, large
comma-separated numbers ... |
Does basic tokenization using [`sacremoses.MosesPunctNormalizer`] and [`sacremoses.MosesTokenizer`] with
*aggressive_dash_splits=True* (see [`sacremoses.tokenize.MosesTokenizer.tokenize`]). Additionally, large
comma-separated numbers and floating point values are split. E.g. "23,000 people are ... | moses_pipeline | python | huggingface/transformers | src/transformers/models/deprecated/transfo_xl/tokenization_transfo_xl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/transfo_xl/tokenization_transfo_xl.py | Apache-2.0 |
def __call__(
self,
raw_speech: Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]],
return_tensors: Optional[Union[str, TensorType]] = None,
return_attention_mask: Optional[bool] = True,
sampling_rate: Optional[int] = None,
resample: bool = False,
... |
Main method to prepare one or several audio(s) for the model.
Args:
raw_speech (`np.ndarray`, `List[float]`, `List[np.ndarray]`, `List[List[float]]`):
The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float
values... | __call__ | python | huggingface/transformers | src/transformers/models/deprecated/tvlt/feature_extraction_tvlt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/tvlt/feature_extraction_tvlt.py | Apache-2.0 |
def preprocess(
self,
videos: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
patch_size: Optional[List[int]] = None,
num_frames: Optional[int] = None,
resample: PILImageResampling = None,
do_center_crop: Optional[bool]... |
Preprocess an videos or image or batch of videos or images.
Args:
videos (`ImageInput`):
Images or videos to preprocess. Expects a single or batch of frames with pixel values ranging from 0 to
255. If passing in frames with pixel values between 0 and 1, set ... | preprocess | python | huggingface/transformers | src/transformers/models/deprecated/tvlt/image_processing_tvlt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/tvlt/image_processing_tvlt.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... |
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
the model is configured as a decoder.
encoder_attention_mask (... | forward | python | huggingface/transformers | src/transformers/models/deprecated/xlm_prophetnet/modeling_xlm_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/xlm_prophetnet/modeling_xlm_prophetnet.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
decoder_input_ids: Optional[torch.Tensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.Tensor] = None,
decod... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the sequence classification/regression loss. Indices should be in `[-100, 0, ...,
config.vocab_size - 1]`. All labels set to `-100` are ignored (masked), the loss is only computed for
labe... | forward | python | huggingface/transformers | src/transformers/models/deprecated/xlm_prophetnet/modeling_xlm_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/xlm_prophetnet/modeling_xlm_prophetnet.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... |
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
the model is configured as a decoder.
encoder_attention_mask (`... | forward | python | huggingface/transformers | src/transformers/models/deprecated/xlm_prophetnet/modeling_xlm_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/deprecated/xlm_prophetnet/modeling_xlm_prophetnet.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple[torch.Tensor], DepthEstimatorOutp... |
labels (`torch.LongTensor` of shape `(batch_size, height, width)`, *optional*):
Ground truth depth estimation maps for computing the loss.
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoModelForDepthEstimation
>>> import torch
>>> i... | forward | python | huggingface/transformers | src/transformers/models/depth_anything/modeling_depth_anything.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_anything/modeling_depth_anything.py | Apache-2.0 |
def get_qkv_state_dict(key, parameter):
"""
new key which looks like this
xxxx.(q|k|v).xxx (m, n)
is converted to
xxxx.q.xxxx (m//3, n)
xxxx.k.xxxx (m//3, n)
xxxx.v.xxxx (m//3, n)
"""
qkv_state_dict = {}
placeholder = re.search(r"(\(.*?\))", key).group... |
new key which looks like this
xxxx.(q|k|v).xxx (m, n)
is converted to
xxxx.q.xxxx (m//3, n)
xxxx.k.xxxx (m//3, n)
xxxx.v.xxxx (m//3, n)
| get_qkv_state_dict | python | huggingface/transformers | src/transformers/models/depth_pro/convert_depth_pro_weights_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/convert_depth_pro_weights_to_hf.py | Apache-2.0 |
def resize(
self,
image: np.ndarray,
size: Dict[str, int],
resample: PILImageResampling = PILImageResampling.BILINEAR,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> ... |
Resize an image to `(size["height"], size["width"])`.
Args:
image (`np.ndarray`):
Image to resize.
size (`Dict[str, int]`):
Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
resample (`P... | resize | python | huggingface/transformers | src/transformers/models/depth_pro/image_processing_depth_pro.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/image_processing_depth_pro.py | Apache-2.0 |
def post_process_depth_estimation(
self,
outputs: "DepthProDepthEstimatorOutput",
target_sizes: Optional[Union[TensorType, List[Tuple[int, int]], None]] = None,
) -> Dict[str, List[TensorType]]:
"""
Post-processes the raw depth predictions from the model to generate
f... |
Post-processes the raw depth predictions from the model to generate
final depth predictions which is caliberated using the field of view if provided
and resized to specified target sizes if provided.
Args:
outputs ([`DepthProDepthEstimatorOutput`]):
Raw outp... | post_process_depth_estimation | python | huggingface/transformers | src/transformers/models/depth_pro/image_processing_depth_pro.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/image_processing_depth_pro.py | Apache-2.0 |
def reshape_features(hidden_states: torch.Tensor) -> torch.Tensor:
"""Discard class token and reshape 1D feature map to a 2D grid."""
n_samples, seq_len, hidden_size = hidden_states.shape
size = torch_int(seq_len**0.5)
hidden_states = hidden_states[:, -(size**2) :, :] # remove special tokens if there ... | Discard class token and reshape 1D feature map to a 2D grid. | reshape_features | python | huggingface/transformers | src/transformers/models/depth_pro/modeling_depth_pro.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/modeling_depth_pro.py | Apache-2.0 |
def merge_patches(patches: torch.Tensor, batch_size: int, padding: int) -> torch.Tensor:
"""Merges smaller patches into image-like feature map."""
n_patches, hidden_size, out_size, out_size = patches.shape
n_patches_per_batch = n_patches // batch_size
sqrt_n_patches_per_batch = torch_int(n_patches_per_b... | Merges smaller patches into image-like feature map. | merge_patches | python | huggingface/transformers | src/transformers/models/depth_pro/modeling_depth_pro.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/modeling_depth_pro.py | Apache-2.0 |
def reconstruct_feature_maps(
hidden_state: torch.Tensor, batch_size: int, padding: int, output_size: Tuple[float, float]
) -> torch.Tensor:
"""
Reconstructs feature maps from the hidden state produced by any of the encoder. Converts the hidden state of shape
`(n_patches_per_batch * batch_size, seq_len,... |
Reconstructs feature maps from the hidden state produced by any of the encoder. Converts the hidden state of shape
`(n_patches_per_batch * batch_size, seq_len, hidden_size)` to feature maps of shape
`(batch_size, hidden_size, output_size[0], output_size[1])`.
Args:
hidden_state (torch.Tensor):... | reconstruct_feature_maps | python | huggingface/transformers | src/transformers/models/depth_pro/modeling_depth_pro.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/modeling_depth_pro.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
head_mask: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple, DepthProOutput]:
r""... |
Examples:
```python
>>> import torch
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, DepthProModel
>>> url = "https://www.ilankelman.org/stopsigns/australia.jpg"
>>> image = Image.open(requests.get(url, stream=T... | forward | python | huggingface/transformers | src/transformers/models/depth_pro/modeling_depth_pro.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/modeling_depth_pro.py | Apache-2.0 |
def __init__(self, config, use_fov_model=None):
r"""
use_fov_model (bool, *optional*):
Whether to use the field of view model.
"""
super().__init__(config)
self.config = config
self.use_fov_model = use_fov_model if use_fov_model is not None else self.config.us... |
use_fov_model (bool, *optional*):
Whether to use the field of view model.
| __init__ | python | huggingface/transformers | src/transformers/models/depth_pro/modeling_depth_pro.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/modeling_depth_pro.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
head_mask: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,... |
labels (`torch.LongTensor` of shape `(batch_size, height, width)`, *optional*):
Ground truth depth estimation maps for computing the loss.
Examples:
```python
>>> from transformers import AutoImageProcessor, DepthProForDepthEstimation
>>> import torch
>>> f... | forward | python | huggingface/transformers | src/transformers/models/depth_pro/modeling_depth_pro.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/depth_pro/modeling_depth_pro.py | Apache-2.0 |
def from_dict(cls, image_processor_dict: Dict[str, Any], **kwargs):
"""
Overrides the `from_dict` method from the base class to make sure parameters are updated if image processor is
created using from_dict and kwargs e.g. `DetrImageProcessorFast.from_pretrained(checkpoint, size=600,
max... |
Overrides the `from_dict` method from the base class to make sure parameters are updated if image processor is
created using from_dict and kwargs e.g. `DetrImageProcessorFast.from_pretrained(checkpoint, size=600,
max_size=800)`
| from_dict | python | huggingface/transformers | src/transformers/models/detr/image_processing_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/detr/image_processing_detr_fast.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
d... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/detr/modeling_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/detr/modeling_detr.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
d... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/detr/modeling_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/detr/modeling_detr.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
d... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/detr/modeling_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/detr/modeling_detr.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/diffllama/modeling_diffllama.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/diffllama/modeling_diffllama.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.Tensor,
output_hidden_states: Optional[bool] = None,
output_attentions: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers impor... |
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/dinat/modeling_dinat.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dinat/modeling_dinat.py | Apache-2.0 |
def interpolate_pos_encoding(self, embeddings: torch.Tensor, height: int, width: int) -> torch.Tensor:
"""
This method allows to interpolate the pre-trained position encodings, to be able to use the model on higher resolution
images. This method is also adapted to support torch.jit tracing and i... |
This method allows to interpolate the pre-trained position encodings, to be able to use the model on higher resolution
images. This method is also adapted to support torch.jit tracing and interpolation at torch.float32 precision.
Adapted from:
- https://github.com/facebookresearch/dino... | interpolate_pos_encoding | python | huggingface/transformers | src/transformers/models/dinov2/modeling_dinov2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dinov2/modeling_dinov2.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
bool_masked_pos: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[b... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, sequence_length)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0). Only relevant for
pre-training.
| forward | python | huggingface/transformers | src/transformers/models/dinov2/modeling_dinov2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dinov2/modeling_dinov2.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.Tensor,
output_hidden_states: Optional[bool] = None,
output_attentions: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers impor... |
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/dinov2/modeling_dinov2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dinov2/modeling_dinov2.py | Apache-2.0 |
def convert_dinov2_with_registers_checkpoint(model_name, pytorch_dump_folder_path, push_to_hub=False):
"""
Copy/paste/tweak model's weights to our Dinov2WithRegisters structure.
"""
# define default Dinov2WithRegisters configuration
image_classifier = "1layer" in model_name
config = get_dinov2_... |
Copy/paste/tweak model's weights to our Dinov2WithRegisters structure.
| convert_dinov2_with_registers_checkpoint | python | huggingface/transformers | src/transformers/models/dinov2_with_registers/convert_dinov2_with_registers_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dinov2_with_registers/convert_dinov2_with_registers_to_hf.py | Apache-2.0 |
def interpolate_pos_encoding(self, embeddings: torch.Tensor, height: int, width: int) -> torch.Tensor:
"""
This method allows to interpolate the pre-trained position encodings, to be able to use the model on higher
resolution images. This implementation supports torch.jit tracing while maintaini... |
This method allows to interpolate the pre-trained position encodings, to be able to use the model on higher
resolution images. This implementation supports torch.jit tracing while maintaining backwards compatibility
with the original implementation.
Adapted from:
- https://gith... | interpolate_pos_encoding | python | huggingface/transformers | src/transformers/models/dinov2_with_registers/modeling_dinov2_with_registers.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dinov2_with_registers/modeling_dinov2_with_registers.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.Tensor,
output_hidden_states: Optional[bool] = None,
output_attentions: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers impor... |
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/dinov2_with_registers/modeling_dinov2_with_registers.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dinov2_with_registers/modeling_dinov2_with_registers.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Opti... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
[What ... | forward | python | huggingface/transformers | src/transformers/models/distilbert/modeling_distilbert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/distilbert/modeling_distilbert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
labels: Optional[torch.LongTensor] = None,
output_attentions: Option... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
[What ... | forward | python | huggingface/transformers | src/transformers/models/distilbert/modeling_distilbert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/distilbert/modeling_distilbert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
labels: Optional[torch.LongTensor] = None,
output_attentions: Option... |
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/distilbert/modeling_distilbert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/distilbert/modeling_distilbert.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_thumbnail: Optional[bool] = None,
do_align_long_axis: Optional[bool] = None,
do_pad: Optional[bool] =... |
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/donut/image_processing_donut.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/donut/image_processing_donut.py | Apache-2.0 |
def align_long_axis(
self,
image: "torch.Tensor",
size: SizeDict,
) -> "torch.Tensor":
"""
Align the long axis of the image to the longest axis of the specified size.
Args:
image (`torch.Tensor`):
The image to be aligned.
size ... |
Align the long axis of the image to the longest axis of the specified size.
Args:
image (`torch.Tensor`):
The image to be aligned.
size (`Dict[str, int]`):
The size `{"height": h, "width": w}` to align the long axis to.
Returns:
... | align_long_axis | python | huggingface/transformers | src/transformers/models/donut/image_processing_donut_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/donut/image_processing_donut_fast.py | Apache-2.0 |
def pad_image(
self,
image: "torch.Tensor",
size: SizeDict,
random_padding: bool = False,
) -> "torch.Tensor":
"""
Pad the image to the specified size.
Args:
image (`torch.Tensor`):
The image to be padded.
size (`Dict[s... |
Pad the image to the specified size.
Args:
image (`torch.Tensor`):
The image to be padded.
size (`Dict[str, int]`):
The size `{"height": h, "width": w}` to pad the image to.
random_padding (`bool`, *optional*, defaults to `False`):
... | pad_image | python | huggingface/transformers | src/transformers/models/donut/image_processing_donut_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/donut/image_processing_donut_fast.py | Apache-2.0 |
def thumbnail(
self,
image: "torch.Tensor",
size: SizeDict,
) -> "torch.Tensor":
"""
Resize the image to make a thumbnail. The image is resized so that no dimension is larger than any
corresponding dimension of the specified size.
Args:
image (`to... |
Resize the image to make a thumbnail. The image is resized so that no dimension is larger than any
corresponding dimension of the specified size.
Args:
image (`torch.Tensor`):
The image to be resized.
size (`Dict[str, int]`):
The size `{"... | thumbnail | python | huggingface/transformers | src/transformers/models/donut/image_processing_donut_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/donut/image_processing_donut_fast.py | Apache-2.0 |
def __call__(
self,
images: ImageInput = None,
text: Optional[Union[str, List[str], TextInput, PreTokenizedInput]] = None,
audio=None,
videos=None,
**kwargs: Unpack[DonutProcessorKwargs],
):
"""
When used in normal mode, this method forwards all its ar... |
When used in normal mode, this method forwards all its arguments to AutoImageProcessor's
[`~AutoImageProcessor.__call__`] and returns its output. If used in the context
[`~DonutProcessor.as_target_processor`] this method forwards all its arguments to DonutTokenizer's
[`~DonutTokenizer._... | __call__ | python | huggingface/transformers | src/transformers/models/donut/processing_donut.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/donut/processing_donut.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[Tensor] = None,
attention_mask: Optional[Tensor] = None,
token_type_ids: Optional[Tensor] = None,
inputs_embeds: Optional[Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. To match pretraining, DPR input sequence should be
formatted with [CLS] and [SEP] tokens as follows:
(a) For sequence pairs (for a pair title+text fo... | forward | python | huggingface/transformers | src/transformers/models/dpr/modeling_dpr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dpr/modeling_dpr.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[Tensor] = None,
attention_mask: Optional[Tensor] = None,
token_type_ids: Optional[Tensor] = None,
inputs_embeds: Optional[Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. To match pretraining, DPR input sequence should be
formatted with [CLS] and [SEP] tokens as follows:
(a) For sequence pairs (for a pair title+text fo... | forward | python | huggingface/transformers | src/transformers/models/dpr/modeling_dpr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dpr/modeling_dpr.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[Tensor] = None,
attention_mask: Optional[Tensor] = None,
inputs_embeds: Optional[Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
)... |
input_ids (`Tuple[torch.LongTensor]` of shapes `(n_passages, sequence_length)`):
Indices of input sequence tokens in the vocabulary. It has to be a sequence triplet with 1) the question
and 2) the passages titles and 3) the passages texts To match pretraining, DPR `input_ids` sequence s... | forward | python | huggingface/transformers | src/transformers/models/dpr/modeling_dpr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dpr/modeling_dpr.py | Apache-2.0 |
def resize(
self,
image: np.ndarray,
size: Dict[str, int],
keep_aspect_ratio: bool = False,
ensure_multiple_of: int = 1,
resample: PILImageResampling = PILImageResampling.BICUBIC,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_forma... |
Resize an image to target size `(size["height"], size["width"])`. If `keep_aspect_ratio` is `True`, the image
is resized to the largest possible size such that the aspect ratio is preserved. If `ensure_multiple_of` is
set, the image is resized to a size that is a multiple of this value.
... | resize | python | huggingface/transformers | src/transformers/models/dpt/image_processing_dpt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dpt/image_processing_dpt.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
segmentation_maps: Optional[ImageInput] = None,
do_resize: Optional[bool] = None,
size: Optional[int] = None,
keep_aspect_ratio: Optional[bool] = None,
ensure_multiple_of: Optional[int] = None,
resample: PILImageRe... |
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/dpt/image_processing_dpt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dpt/image_processing_dpt.py | Apache-2.0 |
def post_process_depth_estimation(
self,
outputs: "DepthEstimatorOutput",
target_sizes: Optional[Union[TensorType, List[Tuple[int, int]], None]] = None,
) -> List[Dict[str, TensorType]]:
"""
Converts the raw output of [`DepthEstimatorOutput`] into final depth predictions and ... |
Converts the raw output of [`DepthEstimatorOutput`] into final depth predictions and depth PIL images.
Only supports PyTorch.
Args:
outputs ([`DepthEstimatorOutput`]):
Raw outputs of the model.
target_sizes (`TensorType` or `List[Tuple[int, int]]`, *opti... | post_process_depth_estimation | python | huggingface/transformers | src/transformers/models/dpt/image_processing_dpt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dpt/image_processing_dpt.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
head_mask: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,... |
labels (`torch.LongTensor` of shape `(batch_size, height, width)`, *optional*):
Ground truth depth estimation maps for computing the loss.
Examples:
```python
>>> from transformers import AutoImageProcessor, DPTForDepthEstimation
>>> import torch
>>> import ... | forward | python | huggingface/transformers | src/transformers/models/dpt/modeling_dpt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dpt/modeling_dpt.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optio... |
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/dpt/modeling_dpt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/dpt/modeling_dpt.py | Apache-2.0 |
def from_backbone_configs(cls, backbone_config: PretrainedConfig, **kwargs):
"""Instantiate a [`DFineConfig`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.
Args:
backbone_config ([`PretrainedConfig`]):
... | Instantiate a [`DFineConfig`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.
Args:
backbone_config ([`PretrainedConfig`]):
The backbone configuration.
Returns:
[`DFineConfig`]: An in... | from_backbone_configs | python | huggingface/transformers | src/transformers/models/d_fine/configuration_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/configuration_d_fine.py | Apache-2.0 |
def convert_d_fine_checkpoint(model_name, pytorch_dump_folder_path, push_to_hub, repo_id):
"""
Copy/paste/tweak model's weights to our D-FINE structure.
"""
# load default config
config = get_d_fine_config(model_name)
state_dict = load_original_state_dict(repo_id, model_name)
state_dict.pop... |
Copy/paste/tweak model's weights to our D-FINE structure.
| convert_d_fine_checkpoint | python | huggingface/transformers | src/transformers/models/d_fine/convert_d_fine_original_pytorch_checkpoint_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/convert_d_fine_original_pytorch_checkpoint_to_hf.py | Apache-2.0 |
def __init__(self, config: DFineConfig):
"""
D-Fine version of multiscale deformable attention
"""
super().__init__()
self.d_model = config.d_model
self.n_heads = config.decoder_attention_heads
self.n_levels = config.num_feature_levels
self.offset_scale = ... |
D-Fine version of multiscale deformable attention
| __init__ | python | huggingface/transformers | src/transformers/models/d_fine/modeling_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/modeling_d_fine.py | Apache-2.0 |
def replace_batch_norm(model):
r"""
Recursively replace all `torch.nn.BatchNorm2d` with `DFineFrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
"""
for name, module in model.named_children():
if isinstance(module, nn.BatchNorm2d):
new_module = DF... |
Recursively replace all `torch.nn.BatchNorm2d` with `DFineFrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
| replace_batch_norm | python | huggingface/transformers | src/transformers/models/d_fine/modeling_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/modeling_d_fine.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: torch.Tensor,
position_embeddings: Optional[torch.Tensor] = None,
output_attentions: bool = False,
**kwargs,
):
"""
Args:
hidden_states (`torch.FloatTensor`): input to the laye... |
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, target_len, source_len)` where padding elements are indicated by very large negative
... | forward | python | huggingface/transformers | src/transformers/models/d_fine/modeling_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/modeling_d_fine.py | Apache-2.0 |
def get_contrastive_denoising_training_group(
targets,
num_classes,
num_queries,
class_embed,
num_denoising_queries=100,
label_noise_ratio=0.5,
box_noise_scale=1.0,
):
"""
Creates a contrastive denoising training group using ground-truth samples. It adds noise to labels and boxes.
... |
Creates a contrastive denoising training group using ground-truth samples. It adds noise to labels and boxes.
Args:
targets (`List[dict]`):
The target objects, each containing 'class_labels' and 'boxes' for objects in an image.
num_classes (`int`):
Total number of class... | get_contrastive_denoising_training_group | python | huggingface/transformers | src/transformers/models/d_fine/modeling_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/modeling_d_fine.py | Apache-2.0 |
def distance2bbox(points, distance: torch.Tensor, reg_scale: float) -> torch.Tensor:
"""
Decodes edge-distances into bounding box coordinates.
Args:
points (`torch.Tensor`):
(batch_size, num_boxes, 4) or (num_boxes, 4) format, representing [x_center, y_center, width, height]
dis... |
Decodes edge-distances into bounding box coordinates.
Args:
points (`torch.Tensor`):
(batch_size, num_boxes, 4) or (num_boxes, 4) format, representing [x_center, y_center, width, height]
distance (`torch.Tensor`):
(batch_size, num_boxes, 4) or (num_boxes, 4), representi... | distance2bbox | python | huggingface/transformers | src/transformers/models/d_fine/modeling_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/modeling_d_fine.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
decoder_inputs_embeds: Optional[torch.FloatTensor] = None,
la... |
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of passing the flattened feature map (output of the backbone + projection layer), you
can choose to directly pass a flattened representation of an image.
de... | forward | python | huggingface/transformers | src/transformers/models/d_fine/modeling_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/modeling_d_fine.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
decoder_inputs_embeds: Optional[torch.FloatTensor] = None,
la... |
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of passing the flattened feature map (output of the backbone + projection layer), you
can choose to directly pass a flattened representation of an image.
de... | forward | python | huggingface/transformers | src/transformers/models/d_fine/modeling_d_fine.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/d_fine/modeling_d_fine.py | Apache-2.0 |
def rescale(
self,
image: "torch.Tensor",
scale: float,
offset: Optional[bool] = True,
**kwargs,
) -> "torch.Tensor":
"""
Rescale an image by a scale factor.
If `offset` is `True`, the image has its values rescaled by `scale` and then offset by 1. If ... |
Rescale an image by a scale factor.
If `offset` is `True`, the image has its values rescaled by `scale` and then offset by 1. If `scale` is
1/127.5, the image is rescaled between [-1, 1].
image = image * scale - 1
If `offset` is `False`, and `scale` is 1/255, the image is ... | rescale | python | huggingface/transformers | src/transformers/models/efficientnet/image_processing_efficientnet_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/efficientnet/image_processing_efficientnet_fast.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the ELECTRA loss. Input should be a sequence of tokens (see `input_ids` docstring)
Indices should be in `[0, 1]`:
- 0 indicates the token is an original token,
... | forward | python | huggingface/transformers | src/transformers/models/electra/modeling_electra.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/electra/modeling_electra.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
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/electra/modeling_electra.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/electra/modeling_electra.py | Apache-2.0 |
def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A Electra sequence
pair mask has the following format:
... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A Electra sequence
pair mask has the following format:
```
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
```
If `token_ids_1` is `No... | create_token_type_ids_from_sequences | python | huggingface/transformers | src/transformers/models/electra/tokenization_electra.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/electra/tokenization_electra.py | Apache-2.0 |
def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A ELECTRA sequence
pair mask has the following format:
... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A ELECTRA sequence
pair mask has the following format:
```
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
```
If `token_ids_1` is `No... | create_token_type_ids_from_sequences | python | huggingface/transformers | src/transformers/models/electra/tokenization_electra_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/electra/tokenization_electra_fast.py | Apache-2.0 |
def _preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
resample: PILImageResampling = None,
do_rescale: Optional[bool] = None,
rescale_factor: Optional[float] = None,
do_normalize: Optional[bool] = None,
image_mean: Optional[Union[flo... |
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
Image or batch of images to preprocess. Expects pixel values ranging from 0 to 255. If pixel values range from 0 to 1, set `do_rescale=False`.
vision_info (`List[Dict]`, *optional*):
... | _preprocess | python | huggingface/transformers | src/transformers/models/emu3/image_processing_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/image_processing_emu3.py | Apache-2.0 |
def _pad_for_batching(
self,
pixel_values: List[np.ndarray],
image_sizes: List[List[int]],
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
):
"""
Pads images on the `num_of_patches` ... |
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`)
image_sizes (`List[List[int... | _pad_for_batching | python | huggingface/transformers | src/transformers/models/emu3/image_processing_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/image_processing_emu3.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`):
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/emu3/image_processing_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/image_processing_emu3.py | Apache-2.0 |
def postprocess(
self,
images: ImageInput,
do_rescale: Optional[bool] = None,
rescale_factor: Optional[float] = None,
do_normalize: Optional[bool] = None,
image_mean: Optional[Union[float, List[float]]] = None,
image_std: Optional[Union[float, List[float]]] = None... |
Postprocess an image or batch of images tensor. Postprocess is the reverse process of preprocess.
The parameters should be same as in preprocess.
Args:
images (`ImageInput`):
Image to postprocess. Expects a single or batch of images with pixel values ranging from -1 ... | postprocess | python | huggingface/transformers | src/transformers/models/emu3/image_processing_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/image_processing_emu3.py | Apache-2.0 |
def unnormalize(
self,
image: np.array,
image_mean: Union[float, Iterable[float]],
image_std: Union[float, Iterable[float]],
input_data_format: Optional[Union[str, ChannelDimension]] = None,
) -> np.array:
"""
Unnormalizes `image` using the mean and standard d... |
Unnormalizes `image` using the mean and standard deviation specified by `mean` and `std`.
image = (image * image_std) + image_mean
Args:
image (`torch.Tensor` of shape `(batch_size, num_channels, image_size, image_size)` or `(num_channels, image_size, image_size)`):
... | unnormalize | python | huggingface/transformers | src/transformers/models/emu3/image_processing_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/image_processing_emu3.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/emu3/modeling_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/modeling_emu3.py | Apache-2.0 |
def get_image_tokens(self, pixel_values: torch.FloatTensor, image_sizes: torch.LongTensor):
"""
Tokenizes images into discrete tokens with VQGAN module. Converts
obtained image tokens into BPE tokens and wraps with "boi" and "eoi"
special tokens.
Args:
pixel_values (... |
Tokenizes images into discrete tokens with VQGAN module. Converts
obtained image tokens into BPE tokens and wraps with "boi" and "eoi"
special tokens.
Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
The... | get_image_tokens | python | huggingface/transformers | src/transformers/models/emu3/modeling_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/modeling_emu3.py | Apache-2.0 |
def decode_image_tokens(self, image_tokens: torch.LongTensor, height: int, width: int):
"""
Decodes generated image tokens from language model to continuous pixel values
with VQGAN module via upsampling.
Args:
image_tokens (`torch.LongTensor` of shape `(batch_size, num_of_to... |
Decodes generated image tokens from language model to continuous pixel values
with VQGAN module via upsampling.
Args:
image_tokens (`torch.LongTensor` of shape `(batch_size, num_of_tokens)`):
The tensors corresponding to the input images.
height (`int`):... | decode_image_tokens | python | huggingface/transformers | src/transformers/models/emu3/modeling_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/modeling_emu3.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
image_sizes: torch.Tensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None... |
image_sizes (`torch.LongTensor` of shape `(batch_size, 2)`):
The sizes of the images in the batch, being (height, width) for each image. Image sizes can be obtained using
[`AutoImageProcessor`]. See [`Emu3ImageProcessor.__call__`] for details ([]`Emu3Processor`] uses
[`Emu3I... | forward | python | huggingface/transformers | src/transformers/models/emu3/modeling_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/modeling_emu3.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
image_sizes: torch.Tensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None... |
image_sizes (`torch.LongTensor` of shape `(batch_size, 2)`):
The sizes of the images in the batch, being (height, width) for each image. Image sizes can be obtained using
[`AutoImageProcessor`]. See [`Emu3ImageProcessor.__call__`] for details ([]`Emu3Processor`] uses
[`Emu3I... | forward | python | huggingface/transformers | src/transformers/models/emu3/modeling_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/modeling_emu3.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[Emu3ProcessorKwargs],
) -> BatchFeature:
"""
Main 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 Emu3TokenizerFast's [`~Emu3TokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` and... | __call__ | python | huggingface/transformers | src/transformers/models/emu3/processing_emu3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/emu3/processing_emu3.py | Apache-2.0 |
def decode(
self,
audio_codes: torch.Tensor,
audio_scales: torch.Tensor,
padding_mask: Optional[torch.Tensor] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple[torch.Tensor, torch.Tensor], EncodecDecoderOutput]:
"""
Decodes the given frames into an ... |
Decodes the given frames into an output audio waveform.
Note that the output might be a bit bigger than the input. In that case, any extra steps at the end can be
trimmed.
Args:
audio_codes (`torch.LongTensor` of shape `(batch_size, nb_chunks, chunk_length)`, *optional*):... | decode | python | huggingface/transformers | src/transformers/models/encodec/modeling_encodec.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encodec/modeling_encodec.py | Apache-2.0 |
def forward(
self,
input_values: torch.Tensor,
padding_mask: Optional[torch.Tensor] = None,
bandwidth: Optional[float] = None,
audio_codes: Optional[torch.Tensor] = None,
audio_scales: Optional[torch.Tensor] = None,
return_dict: Optional[bool] = None,
) -> Uni... |
input_values (`torch.FloatTensor` of shape `(batch_size, channels, sequence_length)`, *optional*):
Raw audio input converted to Float and padded to the appropriate length in order to be encoded using chunks
of length self.chunk_length and a stride of `config.chunk_stride`.
paddi... | forward | python | huggingface/transformers | src/transformers/models/encodec/modeling_encodec.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encodec/modeling_encodec.py | Apache-2.0 |
def __init__(
self,
config: Optional[PretrainedConfig] = None,
encoder: Optional[PreTrainedModel] = None,
decoder: Optional[PreTrainedModel] = None,
):
r"""
encoder (`PreTrainedModel`, *optional*):
The encoder model to use.
decoder (`PreTrainedMode... |
encoder (`PreTrainedModel`, *optional*):
The encoder model to use.
decoder (`PreTrainedModel`, *optional*):
The decoder model to use.
| __init__ | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | Apache-2.0 |
def from_encoder_decoder_pretrained(
cls,
encoder_pretrained_model_name_or_path: Optional[str] = None,
decoder_pretrained_model_name_or_path: Optional[str] = None,
*model_args,
**kwargs,
) -> PreTrainedModel:
r"""
Instantiate an encoder and a decoder from one ... |
Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.
The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train
the model, you need to first set it back in training mode... | from_encoder_decoder_pretrained | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
encoder_outputs: Optional[Tuple[torch.Floa... |
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 [`PreTrainedTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenize... | forward | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.