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 resize(
self,
image: "torch.Tensor",
size: SizeDict,
crop_pct: Optional[float] = None,
interpolation: "F.InterpolationMode" = None,
antialias: bool = True,
**kwargs,
) -> "torch.Tensor":
"""
Resize an image.
If crop_pct is unset:
... |
Resize an image.
If crop_pct is unset:
- size is `{"height": h, "width": w}`: the image is resized to `(h, w)`.
- size is `{"shortest_edge": s}`: the shortest edge of the image is resized to s whilst maintaining the
aspect ratio.
if crop_pct is set:
... | resize | python | huggingface/transformers | src/transformers/models/poolformer/image_processing_poolformer_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/poolformer/image_processing_poolformer_fast.py | Apache-2.0 |
def pad(
self,
inputs: BatchFeature,
is_batched: bool,
return_attention_mask: bool,
return_tensors: Optional[Union[str, TensorType]] = None,
):
"""
Pads the inputs to same length and returns attention_mask.
Args:
inputs (`BatchFeature`):
... |
Pads the inputs to same length and returns attention_mask.
Args:
inputs (`BatchFeature`):
Processed audio features.
is_batched (`bool`):
Whether inputs are batched or not.
return_attention_mask (`bool`):
Whether to ret... | pad | python | huggingface/transformers | src/transformers/models/pop2piano/feature_extraction_pop2piano.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/pop2piano/feature_extraction_pop2piano.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. Pop2Piano 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 using
... | forward | python | huggingface/transformers | src/transformers/models/pop2piano/modeling_pop2piano.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/pop2piano/modeling_pop2piano.py | Apache-2.0 |
def generate(
self,
input_features,
attention_mask=None,
composer="composer1",
generation_config=None,
**kwargs,
):
"""
Generates token ids for midi outputs.
<Tip warning={true}>
Most generation-controlling parameters are set in `gene... |
Generates token ids for midi outputs.
<Tip warning={true}>
Most generation-controlling parameters are set in `generation_config` which, if not passed, will be set to the
model's default generation configuration. You can override any `generation_config` by passing the corresponding
... | generate | python | huggingface/transformers | src/transformers/models/pop2piano/modeling_pop2piano.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/pop2piano/modeling_pop2piano.py | Apache-2.0 |
def convert_old_keys_to_new_keys(state_dict_keys: Optional[dict] = None):
"""
Convert old state dict keys to new keys using regex patterns.
"""
output_dict = {}
if state_dict_keys is not None:
for old_key in state_dict_keys:
new_key = old_key
for pattern, replacement ... |
Convert old state dict keys to new keys using regex patterns.
| convert_old_keys_to_new_keys | python | huggingface/transformers | src/transformers/models/prompt_depth_anything/convert_prompt_depth_anything_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prompt_depth_anything/convert_prompt_depth_anything_to_hf.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/prompt_depth_anything/image_processing_prompt_depth_anything.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prompt_depth_anything/image_processing_prompt_depth_anything.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
prompt_depth: 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: Optional[PILIma... |
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/prompt_depth_anything/image_processing_prompt_depth_anything.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prompt_depth_anything/image_processing_prompt_depth_anything.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
prompt_depth: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = No... |
prompt_depth (`torch.FloatTensor` of shape `(batch_size, 1, height, width)`, *optional*):
Prompt depth is the sparse or low-resolution depth obtained from multi-view geometry or a
low-resolution depth sensor. It generally has shape (height, width), where height
and width can... | forward | python | huggingface/transformers | src/transformers/models/prompt_depth_anything/modeling_prompt_depth_anything.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prompt_depth_anything/modeling_prompt_depth_anything.py | Apache-2.0 |
def __init__(self, config: ProphetNetConfig, word_embeddings: nn.Embedding = None):
r"""
word_embeddings (`torch.nn.Embeddings` of shape `(config.vocab_size, config.hidden_size)`, *optional*):
The word embedding parameters. This can be used to initialize [`ProphetNetEncoder`] with pre-define... |
word_embeddings (`torch.nn.Embeddings` of shape `(config.vocab_size, config.hidden_size)`, *optional*):
The word embedding parameters. This can be used to initialize [`ProphetNetEncoder`] with pre-defined word
embeddings instead of randomly initialized word embeddings.
| __init__ | python | huggingface/transformers | src/transformers/models/prophetnet/modeling_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prophetnet/modeling_prophetnet.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... |
Example:
```python
>>> from transformers import AutoTokenizer, ProphetNetEncoder
>>> import torch
>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/prophetnet-large-uncased")
>>> model = ProphetNetEncoder.from_pretrained("patrickvonplaten/prophetnet-large-uncase... | forward | python | huggingface/transformers | src/transformers/models/prophetnet/modeling_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prophetnet/modeling_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... |
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/prophetnet/modeling_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prophetnet/modeling_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... |
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/prophetnet/modeling_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prophetnet/modeling_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... |
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/prophetnet/modeling_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prophetnet/modeling_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... |
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/prophetnet/modeling_prophetnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/prophetnet/modeling_prophetnet.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers ... |
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/pvt_v2/modeling_pvt_v2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/pvt_v2/modeling_pvt_v2.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/qwen2/modeling_qwen2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2/modeling_qwen2.py | Apache-2.0 |
def _prepare_4d_causal_attention_mask_with_cache_position(
self,
attention_mask: torch.Tensor,
sequence_length: int,
target_length: int,
dtype: torch.dtype,
device: torch.device,
min_dtype: float,
cache_position: torch.Tensor,
batch_size: int,
... |
Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
`(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
Args:
attention_mask (`torch.Tensor`):
A 2D attention mask of sh... | _prepare_4d_causal_attention_mask_with_cache_position | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def get_chunked_index(
self, token_indices: torch.Tensor, tokens_per_chunk: int, remove_index: int
) -> list[tuple[int, int]]:
"""
Splits token index list into chunks based on token value ranges.
Given a list of token indices, returns a list of (start, end) index tuples representing... |
Splits token index list into chunks based on token value ranges.
Given a list of token indices, returns a list of (start, end) index tuples representing
slices of the list where the token values fall within successive ranges of `t_ntoken_per_chunk`.
For example, if `t_ntoken_per_chunk... | get_chunked_index | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def get_rope_index(
self,
input_ids: Optional[torch.LongTensor] = None,
image_grid_thw: Optional[torch.LongTensor] = None,
video_grid_thw: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
use_audio_in_video: bool = False,
audio_seq... |
Calculate the 3D rope index based on image and video's temporal, height and width in LLM.
Explanation:
Each embedding sequence contains vision embedding and text embedding or just contains text embedding.
For pure text embedding sequence, the rotary position embedding has no d... | get_rope_index | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def forward(
self,
input_features,
feature_lens=None,
aftercnn_lens=None,
):
r"""
input_features (`torch.LongTensor` of shape `(batch_size, feature_size, sequence_length)`):
Float values of mel features extracted from the raw speech waveform. Raw speech wa... |
input_features (`torch.LongTensor` of shape `(batch_size, feature_size, sequence_length)`):
Float values of mel features extracted from the raw speech waveform. Raw speech waveform can be
obtained by loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a
... | forward | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def padded_and_mask_function(self, tensor_list, tensor_len, padding_value=0, padding_side="right"):
"""
Pads a sequence of tensors to their maximum length on indicated `padding_side`.
Then prepares a mask so that pad tokens are not attended to.
"""
max_len = tensor_len.max()
... |
Pads a sequence of tensors to their maximum length on indicated `padding_side`.
Then prepares a mask so that pad tokens are not attended to.
| padded_and_mask_function | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def apply_multimodal_rotary_pos_emb(q, k, cos, sin, mrope_section, unsqueeze_dim=1):
"""Applies Rotary Position Embedding with Multimodal Sections to the query and key tensors (https://qwenlm.github.io/blog/qwen2-vl/).
Explanation:
Multimodal 3D rotary position embedding is an extension to 1D rotary po... | Applies Rotary Position Embedding with Multimodal Sections to the query and key tensors (https://qwenlm.github.io/blog/qwen2-vl/).
Explanation:
Multimodal 3D rotary position embedding is an extension to 1D rotary position embedding. The input embedding
sequence contains vision (images / videos) emb... | apply_multimodal_rotary_pos_emb | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def get_video_features(
self, pixel_values_videos: torch.FloatTensor, video_grid_thw: Optional[torch.LongTensor] = None
):
"""
Encodes videos into continuous embeddings that can be forwarded to the language model.
Args:
pixel_values_videos (`torch.FloatTensor` of shape `... |
Encodes videos into continuous embeddings that can be forwarded to the language model.
Args:
pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
The tensors corresponding to the input videos.
video_grid_thw (`... | get_video_features | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def get_image_features(self, pixel_values: torch.FloatTensor, image_grid_thw: Optional[torch.LongTensor] = None):
"""
Encodes images into continuous embeddings that can be forwarded to the language model.
Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, i... |
Encodes images into continuous embeddings that can be forwarded to the language model.
Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
The tensors corresponding to the input images.
image_grid_thw (`torch.L... | get_image_features | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def get_audio_features(
self,
input_features: torch.FloatTensor,
feature_attention_mask: Optional[torch.LongTensor] = None,
audio_feature_lengths: Optional[torch.LongTensor] = None,
):
"""
Encodes audios into continuous embeddings that can be forwarded to the language... |
Encodes audios into continuous embeddings that can be forwarded to the language model.
Args:
input_features (`torch.FloatTensor`):
The tensors corresponding to the input audios.
feature_attention_mask (`torch.LongTensor`, *optional*):
Mask to avo... | get_audio_features | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
input_features: Optional[torch.FloatTensor] = None,
pixel_values: Optional[torch.FloatTensor] = None,
pixel_values_videos: Optional[torch.FloatTensor] = None,
image_grid_thw: Optional[torch.LongTensor] = Non... |
input_features (`torch.FloatTensor` of shape `(batch_size, feature_size, feature_sequence_length)`):
Float values mel features extracted from the raw speech waveform. Raw speech waveform can be obtained by
loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a `... | forward | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.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[List[torch.FloatTensor]] = None,
thinker_reply_part: Optional[torch.FloatTensor] = None,
... |
rope_deltas (`torch.LongTensor` of shape `(batch_size, )`, *optional*):
The rope index difference between sequence length and multimodal rope.
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
The temporal, height and width of feature shape of each imag... | forward | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def _length_to_mask(self, length, max_len=None, dtype=None, device=None):
"""Creates a binary mask for each sequence.
Reference: https://discuss.pytorch.org/t/how-to-generate-variable-length-mask/23397/3
Arguments
---------
length : torch.LongTensor
Containing the l... | Creates a binary mask for each sequence.
Reference: https://discuss.pytorch.org/t/how-to-generate-variable-length-mask/23397/3
Arguments
---------
length : torch.LongTensor
Containing the length of each sequence in the batch. Must be 1D.
max_len : int
Ma... | _length_to_mask | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def kaiser_sinc_filter1d(cutoff, half_width, kernel_size):
"""Generates a 1D Kaiser-windowed sinc filter.
Args:
cutoff (float): Normalized cutoff frequency (0 to 0.5).
half_width (float): Transition bandwidth.
kernel_size (int): Number of filter taps.
Returns:
torch.Tensor:... | Generates a 1D Kaiser-windowed sinc filter.
Args:
cutoff (float): Normalized cutoff frequency (0 to 0.5).
half_width (float): Transition bandwidth.
kernel_size (int): Number of filter taps.
Returns:
torch.Tensor: A tensor of shape (1, 1, kernel_size) representing the filter.
... | kaiser_sinc_filter1d | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def forward(
self,
code,
conditioning,
reference_mel,
num_steps=10,
guidance_scale=0.5,
sway_coefficient=-1.0,
**kwargs,
):
"""Generates a waveform from input code and conditioning parameters."""
mel_spectrogram = self.code2wav_dit_mod... | Generates a waveform from input code and conditioning parameters. | forward | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def generate(
self,
input_ids: Optional[torch.Tensor] = None,
speaker: str = "Chelsie",
use_audio_in_video: bool = False,
return_audio: Optional[bool] = None,
thinker_max_new_tokens: int = 1024,
talker_max_new_tokens: int = 4096,
talker_do_sample: bool = T... |
Generate text response and audio from input.
Args:
input_ids (`Optional[torch.Tensor]`, *optional*):
Input ids, should obtain from processor.
speaker (`str` , defaults to "Chelsie"):
Which speaker should be used in audio response.
use... | generate | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py | Apache-2.0 |
def __call__(
self,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
images: ImageInput = None,
videos: VideoInput = None,
audio: AudioInput = None,
**kwargs: Unpack[Qwen2_5OmniProcessorKwargs],
) -> BatchFeature:
"""... |
Main method to prepare for the model one or several sequences(s) and audio(s). This method forwards the `text`
and `kwargs` arguments to Qwen2TokenizerFast's [`~Qwen2TokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the audio(s), this method forwards the `audio` an... | __call__ | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/processing_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/processing_qwen2_5_omni.py | Apache-2.0 |
def get_chunked_index(self, token_indices: np.ndarray, tokens_per_chunk: int) -> list[tuple[int, int]]:
"""
Splits token index list into chunks based on token value ranges.
Given a list of token indices, returns a list of (start, end) index tuples representing
slices of the list where t... |
Splits token index list into chunks based on token value ranges.
Given a list of token indices, returns a list of (start, end) index tuples representing
slices of the list where the token values fall within successive ranges of `t_ntoken_per_chunk`.
For example, if `t_ntoken_per_chunk... | get_chunked_index | python | huggingface/transformers | src/transformers/models/qwen2_5_omni/processing_qwen2_5_omni.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_omni/processing_qwen2_5_omni.py | Apache-2.0 |
def get_rope_index(
self,
input_ids: Optional[torch.LongTensor] = None,
image_grid_thw: Optional[torch.LongTensor] = None,
video_grid_thw: Optional[torch.LongTensor] = None,
second_per_grid_ts: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
... |
Calculate the 3D rope index based on image and video's temporal, height and width in LLM.
Explanation:
Each embedding sequence contains vision embedding and text embedding or just contains text embedding.
For pure text embedding sequence, the rotary position embedding has no d... | get_rope_index | python | huggingface/transformers | src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.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[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
use... |
pixel_values_videos (`torch.FloatTensor` of shape `(seq_length, num_channels * temporal_size * image_size * image_size)):
The tensors corresponding to the input videos. Pixel values can be obtained using
[`AutoImageProcessor`]. See [`Qwen2_5_VLImageProcessor.__call__`] for details. [`Qw... | forward | python | huggingface/transformers | src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.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[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
lab... |
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/qwen2_5_vl/modeling_qwen2_5_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py | Apache-2.0 |
def _get_image_nums_and_video_nums(
self,
input_ids: Optional[torch.LongTensor],
) -> Tuple[torch.Tensor, torch.Tensor]:
"""
Get the number of images and videos for each sample to calculate the separation length of the sample tensor.
These parameters are not passed through th... |
Get the number of images and videos for each sample to calculate the separation length of the sample tensor.
These parameters are not passed through the processor to avoid unpredictable impacts from interface modifications.
Args:
input_ids (`torch.LongTensor` of shape `(batch_size,... | _get_image_nums_and_video_nums | python | huggingface/transformers | src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py | Apache-2.0 |
def _get_num_multimodal_tokens(self, image_sizes=None, video_sizes=None, **kwargs):
"""
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (`List[List[int]]`, *optional*):
The input sizes formatted as (height... |
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (`List[List[int]]`, *optional*):
The input sizes formatted as (height, width) per each image.
video_sizes (`List[List[int]]`, *optional*):
... | _get_num_multimodal_tokens | python | huggingface/transformers | src/transformers/models/qwen2_5_vl/modular_qwen2_5_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_5_vl/modular_qwen2_5_vl.py | Apache-2.0 |
def forward(
self,
input_features,
attention_mask=None,
head_mask=None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
):
r"""
Args:
input_features (`torch.LongTensor` of shape `(batch_size, feature_size, seque... |
Args:
input_features (`torch.LongTensor` of shape `(batch_size, feature_size, sequence_length)`):
Float values of mel features extracted from the raw speech waveform. Raw speech waveform can be
obtained by loading a `.flac` or `.wav` audio file into an array of type ... | forward | python | huggingface/transformers | src/transformers/models/qwen2_audio/modeling_qwen2_audio.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_audio/modeling_qwen2_audio.py | Apache-2.0 |
def _merge_input_ids_with_audio_features(
self, audio_features, num_audio_tokens, inputs_embeds, input_ids, attention_mask, labels
):
"""
Merge input_ids with with audio features into final embeddings
Args:
audio_features (`torch.Tensor` of shape `(num_audios, max_audio_... |
Merge input_ids with with audio features into final embeddings
Args:
audio_features (`torch.Tensor` of shape `(num_audios, max_audio_tokens, embed_dim)`):
All audio vectors of all audios in the batch
num_audio_tokens (`torch.LongTensor` of shape `(num_audios)`):... | _merge_input_ids_with_audio_features | python | huggingface/transformers | src/transformers/models/qwen2_audio/modeling_qwen2_audio.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_audio/modeling_qwen2_audio.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
input_features: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
feature_attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
... |
input_features (`torch.FloatTensor` of shape `(batch_size, feature_size, feature_sequence_length)`):
Float values mel features extracted from the raw speech waveform. Raw speech waveform can be obtained by
loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a `... | forward | python | huggingface/transformers | src/transformers/models/qwen2_audio/modeling_qwen2_audio.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_audio/modeling_qwen2_audio.py | Apache-2.0 |
def __call__(
self,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
audio: Union[np.ndarray, List[np.ndarray]] = None,
audios=None, # kept for BC
**kwargs: Unpack[Qwen2AudioProcessorKwargs],
) -> BatchFeature:
"""
M... |
Main method to prepare for the model one or several sequences(s) and audio(s). This method forwards the `text`
and `kwargs` arguments to Qwen2TokenizerFast's [`~Qwen2TokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the audio(s), this method forwards the `audios` a... | __call__ | python | huggingface/transformers | src/transformers/models/qwen2_audio/processing_qwen2_audio.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_audio/processing_qwen2_audio.py | Apache-2.0 |
def default_chat_template(self):
"""
This default vicuna template formats inputs in the form of a chat history. For each message in the chat history:
* the template will output the role of the speaker followed by the content of the message.
* content is a list of strings and audios.
... |
This default vicuna template formats inputs in the form of a chat history. For each message in the chat history:
* the template will output the role of the speaker followed by the content of the message.
* content is a list of strings and audios.
* If the content element is an audio, th... | default_chat_template | python | huggingface/transformers | src/transformers/models/qwen2_audio/processing_qwen2_audio.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_audio/processing_qwen2_audio.py | Apache-2.0 |
def _prepare_4d_causal_attention_mask_with_cache_position(
attention_mask: torch.Tensor,
sequence_length: int,
target_length: int,
dtype: torch.dtype,
cache_position: torch.Tensor,
batch_size: int,
config: Qwen2MoeConfig,
past_key_values: Cache,
):
... |
Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
`(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
Args:
attention_mask (`torch.Tensor`):
A 2D attention mask of sh... | _prepare_4d_causal_attention_mask_with_cache_position | python | huggingface/transformers | src/transformers/models/qwen2_moe/modeling_qwen2_moe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_moe/modeling_qwen2_moe.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/qwen2_moe/modeling_qwen2_moe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_moe/modeling_qwen2_moe.py | Apache-2.0 |
def _preprocess(
self,
images: Union[ImageInput, VideoInput],
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_normal... |
Preprocess an image or batch of images. Copy of the `preprocess` method from `CLIPImageProcessor`.
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`.
... | _preprocess | python | huggingface/transformers | src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
videos: VideoInput = None,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
min_pixels: Optional[int] = None,
max_pixels: Optional[int] = None,
resample: PILImageResampling = None,
d... |
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`.
videos (`VideoInput`):
Video to ... | preprocess | python | huggingface/transformers | src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py | Apache-2.0 |
def get_number_of_image_patches(self, height: int, width: int, images_kwargs=None):
"""
A utility that returns number of image patches for a given image size.
Args:
height (`int`):
Height of the input image.
width (`int`):
Width of the inp... |
A utility that returns number of image patches for a given image size.
Args:
height (`int`):
Height of the input image.
width (`int`):
Width of the input image.
images_kwargs (`dict`, *optional*)
Any kwargs to override... | get_number_of_image_patches | python | huggingface/transformers | src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py | Apache-2.0 |
def _preprocess(
self,
images: List["torch.Tensor"],
do_resize: bool,
size: SizeDict,
interpolation: Optional["F.InterpolationMode"],
do_rescale: bool,
rescale_factor: float,
do_normalize: bool,
image_mean: Optional[Union[float, List[float]]],
... |
Preprocess an image or batch of images. Copy of the `preprocess` method from `CLIPImageProcessor`.
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`.
... | _preprocess | python | huggingface/transformers | src/transformers/models/qwen2_vl/image_processing_qwen2_vl_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/image_processing_qwen2_vl_fast.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
videos: VideoInput = None,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: Optional[Union["PILImageResampling", "F.InterpolationMode"]] = None,
do_rescale: Optional[bool] = None,
... |
min_pixels (`int`, *optional*, defaults to `56 * 56`):
The min pixels of the image to resize the image.
max_pixels (`int`, *optional*, defaults to `28 * 28 * 1280`):
The max pixels of the image to resize the image.
patch_size (`int`, *optional*, defaults to 14):
... | preprocess | python | huggingface/transformers | src/transformers/models/qwen2_vl/image_processing_qwen2_vl_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/image_processing_qwen2_vl_fast.py | Apache-2.0 |
def forward(self, hidden_states: torch.Tensor, grid_thw: torch.Tensor) -> torch.Tensor:
r"""
grid_thw (`torch.LongTensor` of shape `(num_images, 3)`):
The temporal, height and width dimensions of feature shape for each image. Each row contains [t, h, w] values.
"""
hidden_sta... |
grid_thw (`torch.LongTensor` of shape `(num_images, 3)`):
The temporal, height and width dimensions of feature shape for each image. Each row contains [t, h, w] values.
| forward | python | huggingface/transformers | src/transformers/models/qwen2_vl/modeling_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py | Apache-2.0 |
def get_rope_index(
self,
input_ids: Optional[torch.LongTensor] = None,
image_grid_thw: Optional[torch.LongTensor] = None,
video_grid_thw: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
) -> Tuple[torch.Tensor, torch.Tensor]:
"""
... |
Calculate the 3D rope index based on image and video's temporal, height and width in LLM.
Explanation:
Each embedding sequence contains vision embedding and text embedding or just contains text embedding.
For pure text embedding sequence, the rotary position embedding has no d... | get_rope_index | python | huggingface/transformers | src/transformers/models/qwen2_vl/modeling_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/modeling_qwen2_vl.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[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
use... |
pixel_values_videos (`torch.FloatTensor` of shape `(seq_length, num_channels * temporal_size * image_size * image_size)):
The tensors corresponding to the input videos. Pixel values can be obtained using
[`AutoImageProcessor`]. See [`Qwen2VLImageProcessor.__call__`] for details. [`Qwen2... | forward | python | huggingface/transformers | src/transformers/models/qwen2_vl/modeling_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/modeling_qwen2_vl.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[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
lab... |
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/qwen2_vl/modeling_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py | Apache-2.0 |
def __call__(
self,
images: ImageInput = None,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
videos: VideoInput = None,
**kwargs: Unpack[Qwen2VLProcessorKwargs],
) -> BatchFeature:
"""
Main method to prepare for th... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to Qwen2TokenizerFast's [`~Qwen2TokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the vision inputs, this method forwards the `visi... | __call__ | python | huggingface/transformers | src/transformers/models/qwen2_vl/processing_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/processing_qwen2_vl.py | Apache-2.0 |
def get_num_of_video_patches(self, num_frames: int, height: int, width: int, videos_kwargs=None):
"""
A utility that returns number of video patches a given video size.
Args:
num_frames (`int`):
Number of frames in the input video.
height (`int`):
... |
A utility that returns number of video patches a given video size.
Args:
num_frames (`int`):
Number of frames in the input video.
height (`int`):
Height of the input video.
width (`int`):
Width of the input video.
... | get_num_of_video_patches | python | huggingface/transformers | src/transformers/models/qwen2_vl/video_processing_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen2_vl/video_processing_qwen2_vl.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/qwen3/modeling_qwen3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen3/modeling_qwen3.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/qwen3_moe/modeling_qwen3_moe.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/qwen3_moe/modeling_qwen3_moe.py | Apache-2.0 |
def from_pretrained_question_encoder_generator(
cls,
question_encoder_pretrained_model_name_or_path: Optional[str] = None,
generator_pretrained_model_name_or_path: Optional[str] = None,
retriever: RagRetriever = None,
**kwargs,
) -> PreTrainedModel:
r"""
Insta... |
Instantiates an question encoder and a generator 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 tr... | from_pretrained_question_encoder_generator | python | huggingface/transformers | src/transformers/models/rag/modeling_rag.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rag/modeling_rag.py | Apache-2.0 |
def __init__(
self,
config: Optional[PretrainedConfig] = None,
question_encoder: Optional[PreTrainedModel] = None,
generator: Optional[PreTrainedModel] = None,
retriever: Optional[RagRetriever] = None, # or maybe just use a `set_retriever(...)` method
**kwargs,
):
... |
question_encoder (`PreTrainedModel`, *optional*):
The model responsible for encoding the question into hidden states for retrieval.
generator (`PreTrainedModel`, *optional*):
The model responsible for generating text based on retrieved documents.
retriever (`RagRetriever... | __init__ | python | huggingface/transformers | src/transformers/models/rag/modeling_rag.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rag/modeling_rag.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
encoder_outputs: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. [`RagConfig`], used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
... | forward | python | huggingface/transformers | src/transformers/models/rag/modeling_rag.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rag/modeling_rag.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
encoder_outputs: Optional[Tuple[Tuple[torch.Tensor]]] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolT... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. [`RagConfig`], used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
... | forward | python | huggingface/transformers | src/transformers/models/rag/modeling_rag.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rag/modeling_rag.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[Tuple[Tuple[torch.Tensor]]] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. [`RagConfig`], used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
... | forward | python | huggingface/transformers | src/transformers/models/rag/modeling_rag.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rag/modeling_rag.py | Apache-2.0 |
def from_pretrained_question_encoder_generator(
cls,
question_encoder_pretrained_model_name_or_path: Optional[str] = None,
generator_pretrained_model_name_or_path: Optional[str] = None,
retriever: RagRetriever = None,
*model_args,
**kwargs,
) -> TFPreTrainedModel:
... |
Instantiates an question encoder and a generator from one or two base classes of the library from pretrained
model checkpoints.
Params:
question_encoder_pretrained_model_name_or_path (`str`, *optional*):
Information necessary to initiate the question encoder. Can be... | from_pretrained_question_encoder_generator | python | huggingface/transformers | src/transformers/models/rag/modeling_tf_rag.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rag/modeling_tf_rag.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
decoder_input_ids: np.ndarray | tf.Tensor | None = None,
decoder_attention_mask: np.ndarray | tf.Tensor | None = None,
encoder_outputs: np.ndarray | tf.Tensor ... |
do_marginalize (`bool`, *optional*):
If `True`, the logits are marginalized over all documents by making use of
`torch.nn.functional.log_softmax`.
labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the cros... | call | python | huggingface/transformers | src/transformers/models/rag/modeling_tf_rag.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rag/modeling_tf_rag.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
decoder_input_ids: np.ndarray | tf.Tensor | None = None,
decoder_attention_mask: np.ndarray | tf.Tensor | None = None,
encoder_outputs: np.ndarray | tf.Tensor ... |
exclude_bos_score (`bool`, *optional*):
Only relevant if `labels` is passed. If `True`, the score of the BOS token is disregarded when computing
the loss.
labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing ... | call | python | huggingface/transformers | src/transformers/models/rag/modeling_tf_rag.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rag/modeling_tf_rag.py | Apache-2.0 |
def _update_cache(self, key_states, value_states, **cache_kwargs):
"""
torch.compile compatible sliding window.
Computes the `indices` based on `cache_position >= self.config.attention_window_size - 1`.
The `to_shift` is only true once we are above attention_window_size. Thus with `atten... |
torch.compile compatible sliding window.
Computes the `indices` based on `cache_position >= self.config.attention_window_size - 1`.
The `to_shift` is only true once we are above attention_window_size. Thus with `attention_window_size==64`:
indices = (slicing + to_shift[-1].int()-1) % s... | _update_cache | python | huggingface/transformers | src/transformers/models/recurrent_gemma/modeling_recurrent_gemma.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/recurrent_gemma/modeling_recurrent_gemma.py | Apache-2.0 |
def _rnn_scan(
self,
hidden_states: torch.Tensor,
recurrent_gate: torch.Tensor,
reset: torch.Tensor,
recurrent_states: Union[torch.Tensor, None],
acc_dtype: torch.dtype = torch.float32,
) -> Tuple[torch.Tensor, torch.Tensor]:
"""Runs the recurrence of a linear... | Runs the recurrence of a linear RNN.
Args:
hidden_states: The input sequence.
recurrent_gate: The diagonal of the recurrence matrix `A`.
reset: Indicator of document boundaries, e.g. when to reset the hidden state
of the RNN.
recurrent_states: The initial hidden stat... | _rnn_scan | python | huggingface/transformers | src/transformers/models/recurrent_gemma/modeling_recurrent_gemma.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/recurrent_gemma/modeling_recurrent_gemma.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
cache_position: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
l... |
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/recurrent_gemma/modeling_recurrent_gemma.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/recurrent_gemma/modeling_recurrent_gemma.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
num_hashes: Optional[in... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. During training the input_ids sequence_length has to be
a multiple of the relevant model's chunk lengths (lsh's, local's or both). During evaluation, the indices
... | forward | python | huggingface/transformers | src/transformers/models/reformer/modeling_reformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/reformer/modeling_reformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
num_hashes: Optional[in... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. During training the input_ids sequence_length has to be
a multiple of the relevant model's chunk lengths (lsh's, local's or both). During evaluation, the indices
... | forward | python | huggingface/transformers | src/transformers/models/reformer/modeling_reformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/reformer/modeling_reformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
num_hashes: Optional[in... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. During training the input_ids sequence_length has to be
a multiple of the relevant model's chunk lengths (lsh's, local's or both). During evaluation, the indices
... | forward | python | huggingface/transformers | src/transformers/models/reformer/modeling_reformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/reformer/modeling_reformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
num_hashes: Optional[in... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. During training the input_ids sequence_length has to be
a multiple of the relevant model's chunk lengths (lsh's, local's or both). During evaluation, the indices
... | forward | python | huggingface/transformers | src/transformers/models/reformer/modeling_reformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/reformer/modeling_reformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
num_hashes: Optional[in... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. During training the input_ids sequence_length has to be
a multiple of the relevant model's chunk lengths (lsh's, local's or both). During evaluation, the indices
... | forward | python | huggingface/transformers | src/transformers/models/reformer/modeling_reformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/reformer/modeling_reformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.LongTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
i... |
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/rembert/modeling_rembert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rembert/modeling_rembert.py | Apache-2.0 |
def forward(
self, pixel_values: Tensor, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> import torch
>>> from PIL ... |
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/resnet/modeling_resnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/resnet/modeling_resnet.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,
... |
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:
- 0 corresponds to a *sentence A* token,
- 1 corresponds to a *sentence B* t... | forward | python | huggingface/transformers | src/transformers/models/roberta/modeling_roberta.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/roberta/modeling_roberta.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,
... |
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:
- 0 corresponds to a *sentence A* token,
- 1 corresponds to a *sentence B* t... | forward | python | huggingface/transformers | src/transformers/models/roberta_prelayernorm/modeling_roberta_prelayernorm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/roberta_prelayernorm/modeling_roberta_prelayernorm.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
input_shape_ids: Optional[torch.Tensor] = None,
input_pronunciation_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
posit... |
input_shape_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the shape vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/roc_bert/modeling_roc_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/roc_bert/modeling_roc_bert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
input_shape_ids: Optional[torch.Tensor] = None,
input_pronunciation_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
posit... |
input_shape_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the shape vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/roc_bert/modeling_roc_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/roc_bert/modeling_roc_bert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
input_shape_ids: Optional[torch.Tensor] = None,
input_pronunciation_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
posit... |
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/roc_bert/modeling_roc_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/roc_bert/modeling_roc_bert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
input_shape_ids: Optional[torch.Tensor] = None,
input_pronunciation_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
posit... |
input_shape_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the shape vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/roc_bert/modeling_roc_bert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/roc_bert/modeling_roc_bert.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,
head_mask: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/roformer/modeling_roformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/roformer/modeling_roformer.py | Apache-2.0 |
def from_backbone_configs(cls, backbone_config: PretrainedConfig, **kwargs):
"""Instantiate a [`RTDetrConfig`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.
Args:
backbone_config ([`PretrainedConfig`]):
... | Instantiate a [`RTDetrConfig`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.
Args:
backbone_config ([`PretrainedConfig`]):
The backbone configuration.
Returns:
[`RTDetrConfig`]: An ... | from_backbone_configs | python | huggingface/transformers | src/transformers/models/rt_detr/configuration_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/configuration_rt_detr.py | Apache-2.0 |
def convert_rt_detr_checkpoint(model_name, pytorch_dump_folder_path, push_to_hub, repo_id):
"""
Copy/paste/tweak model's weights to our RTDETR structure.
"""
# load default config
config = get_rt_detr_config(model_name)
# load original model from torch hub
model_name_to_checkpoint_url = {
... |
Copy/paste/tweak model's weights to our RTDETR structure.
| convert_rt_detr_checkpoint | python | huggingface/transformers | src/transformers/models/rt_detr/convert_rt_detr_original_pytorch_checkpoint_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/convert_rt_detr_original_pytorch_checkpoint_to_hf.py | Apache-2.0 |
def get_image_size_for_max_height_width(
input_image: np.ndarray,
max_height: int,
max_width: int,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
) -> Tuple[int, int]:
"""
Computes the output image size given the input image and the maximum allowed height and width. Keep aspec... |
Computes the output image size given the input image and the maximum allowed height and width. Keep aspect ratio.
Important, even if image_height < max_height and image_width < max_width, the image will be resized
to at least one of the edges be equal to max_height or max_width.
For example:
- ... | get_image_size_for_max_height_width | python | huggingface/transformers | src/transformers/models/rt_detr/image_processing_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/image_processing_rt_detr.py | Apache-2.0 |
def prepare_coco_detection_annotation(
image,
target,
return_segmentation_masks: bool = False,
input_data_format: Optional[Union[ChannelDimension, str]] = None,
):
"""
Convert the target in COCO format into the format expected by RTDETR.
"""
image_height, image_width = get_image_size(ima... |
Convert the target in COCO format into the format expected by RTDETR.
| prepare_coco_detection_annotation | python | huggingface/transformers | src/transformers/models/rt_detr/image_processing_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/image_processing_rt_detr.py | Apache-2.0 |
def prepare_annotation(
self,
image: np.ndarray,
target: Dict,
format: Optional[AnnotationFormat] = None,
return_segmentation_masks: Optional[bool] = None,
masks_path: Optional[Union[str, pathlib.Path]] = None,
input_data_format: Optional[Union[str, ChannelDimensi... |
Prepare an annotation for feeding into RTDETR model.
| prepare_annotation | python | huggingface/transformers | src/transformers/models/rt_detr/image_processing_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/image_processing_rt_detr.py | Apache-2.0 |
def post_process_object_detection(
self,
outputs,
threshold: float = 0.5,
target_sizes: Union[TensorType, List[Tuple]] = None,
use_focal_loss: bool = True,
):
"""
Converts the raw output of [`DetrForObjectDetection`] into final bounding boxes in (top_left_x, t... |
Converts the raw output of [`DetrForObjectDetection`] into final bounding boxes in (top_left_x, top_left_y,
bottom_right_x, bottom_right_y) format. Only supports PyTorch.
Args:
outputs ([`DetrObjectDetectionOutput`]):
Raw outputs of the model.
threshold ... | post_process_object_detection | python | huggingface/transformers | src/transformers/models/rt_detr/image_processing_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/image_processing_rt_detr.py | Apache-2.0 |
def prepare_coco_detection_annotation(
image,
target,
return_segmentation_masks: bool = False,
input_data_format: Optional[Union[ChannelDimension, str]] = None,
):
"""
Convert the target in COCO format into the format expected by RT-DETR.
"""
image_height, image_width = image.size()[-2:]... |
Convert the target in COCO format into the format expected by RT-DETR.
| prepare_coco_detection_annotation | python | huggingface/transformers | src/transformers/models/rt_detr/image_processing_rt_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/image_processing_rt_detr_fast.py | Apache-2.0 |
def prepare_annotation(
self,
image: torch.Tensor,
target: Dict,
format: Optional[AnnotationFormat] = None,
return_segmentation_masks: Optional[bool] = None,
masks_path: Optional[Union[str, pathlib.Path]] = None,
input_data_format: Optional[Union[str, ChannelDimen... |
Prepare an annotation for feeding into RT_DETR model.
| prepare_annotation | python | huggingface/transformers | src/transformers/models/rt_detr/image_processing_rt_detr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/image_processing_rt_detr_fast.py | Apache-2.0 |
def replace_batch_norm(model):
r"""
Recursively replace all `torch.nn.BatchNorm2d` with `RTDetrFrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
"""
for name, module in model.named_children():
if isinstance(module, nn.BatchNorm2d):
new_module = R... |
Recursively replace all `torch.nn.BatchNorm2d` with `RTDetrFrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
| replace_batch_norm | python | huggingface/transformers | src/transformers/models/rt_detr/modeling_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/modeling_rt_detr.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/rt_detr/modeling_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/modeling_rt_detr.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/rt_detr/modeling_rt_detr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr/modeling_rt_detr.py | Apache-2.0 |
def from_backbone_configs(cls, backbone_config: PretrainedConfig, **kwargs):
"""Instantiate a [`RTDetrV2Config`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.
Args:
backbone_config ([`PretrainedConfig`]):
... | Instantiate a [`RTDetrV2Config`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.
Args:
backbone_config ([`PretrainedConfig`]):
The backbone configuration.
Returns:
[`RTDetrV2Config`]:... | from_backbone_configs | python | huggingface/transformers | src/transformers/models/rt_detr_v2/configuration_rt_detr_v2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr_v2/configuration_rt_detr_v2.py | Apache-2.0 |
def replace_batch_norm(model):
r"""
Recursively replace all `torch.nn.BatchNorm2d` with `RTDetrV2FrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
"""
for name, module in model.named_children():
if isinstance(module, nn.BatchNorm2d):
new_module =... |
Recursively replace all `torch.nn.BatchNorm2d` with `RTDetrV2FrozenBatchNorm2d`.
Args:
model (torch.nn.Module):
input model
| replace_batch_norm | python | huggingface/transformers | src/transformers/models/rt_detr_v2/modeling_rt_detr_v2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr_v2/modeling_rt_detr_v2.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/rt_detr_v2/modeling_rt_detr_v2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr_v2/modeling_rt_detr_v2.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/rt_detr_v2/modeling_rt_detr_v2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rt_detr_v2/modeling_rt_detr_v2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.LongTensor] = None, # noqa
inputs_embeds: Optional[torch.FloatTensor] = None,
state: Optional[List[torch.FloatTensor]] = None,
use_cache: Optional[bool] = None,
output... |
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else
`past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the ... | forward | python | huggingface/transformers | src/transformers/models/rwkv/modeling_rwkv.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rwkv/modeling_rwkv.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.LongTensor] = None, # noqa
inputs_embeds: Optional[torch.FloatTensor] = None,
state: Optional[List[torch.FloatTensor]] = None,
labels: Optional[torch.LongTensor] = None,
... |
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
`input_ids_length` = `sequence_length` if `past_key_values` is `None` else
`past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
sequence tokens in the ... | forward | python | huggingface/transformers | src/transformers/models/rwkv/modeling_rwkv.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/rwkv/modeling_rwkv.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.