text
stringlengths
31
243k
type
stringclasses
1 value
start
int64
36
275k
end
int64
286
280k
depth
int64
0
1
filepath
stringlengths
85
188
parent_class
stringclasses
3 values
class_index
int64
0
10.8k
class SpeechT5ForSpeechToSpeech(SpeechT5PreTrainedModel): def __init__(self, config: SpeechT5Config): super().__init__(config) speech_encoder = SpeechT5EncoderWithSpeechPrenet(config) speech_decoder = SpeechT5DecoderWithSpeechPrenet(config) self.speecht5 = SpeechT5Model(config, spee...
class_definition
134,225
146,417
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/speecht5/modeling_speecht5.py
null
8,500
class HifiGanResidualBlock(nn.Module): def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5), leaky_relu_slope=0.1): super().__init__() self.leaky_relu_slope = leaky_relu_slope self.convs1 = nn.ModuleList( [ nn.Conv1d( channels, ...
class_definition
147,308
149,437
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/speecht5/modeling_speecht5.py
null
8,501
class SpeechT5HifiGan(PreTrainedModel): config_class = SpeechT5HifiGanConfig main_input_name = "spectrogram" def __init__(self, config: SpeechT5HifiGanConfig): super().__init__(config) self.num_kernels = len(config.resblock_kernel_sizes) self.num_upsamples = len(config.upsample_rate...
class_definition
149,523
154,466
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/speecht5/modeling_speecht5.py
null
8,502
class SpeechT5Tokenizer(PreTrainedTokenizer): """ Construct a SpeechT5 tokenizer. Based on [SentencePiece](https://github.com/google/sentencepiece). This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to this superclass for more information r...
class_definition
1,042
8,911
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/speecht5/tokenization_speecht5.py
null
8,503
class SpeechT5Config(PretrainedConfig): r""" This is the configuration class to store the configuration of a [`SpeechT5Model`]. It is used to instantiate a SpeechT5 model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a s...
class_definition
864
18,967
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/speecht5/configuration_speecht5.py
null
8,504
class SpeechT5HifiGanConfig(PretrainedConfig): r""" This is the configuration class to store the configuration of a [`SpeechT5HifiGanModel`]. It is used to instantiate a SpeechT5 HiFi-GAN vocoder model according to the specified arguments, defining the model architecture. Instantiating a configuration w...
class_definition
18,970
23,377
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/speecht5/configuration_speecht5.py
null
8,505
class Qwen2VLCausalLMOutputWithPast(ModelOutput): """ Base class for Qwen2VL causal language model (or autoregressive) outputs. Args: loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Language modeling loss (for next-token prediction). l...
class_definition
2,180
4,642
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,506
class Qwen2VLRotaryEmbedding(nn.Module): def __init__( self, dim=None, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0, rope_type="default", config: Optional[Qwen2VLConfig] = None, ): super().__init__() # T...
class_definition
4,645
8,807
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,507
class VisionRotaryEmbedding(nn.Module): def __init__(self, dim: int, theta: float = 10000.0) -> None: super().__init__() inv_freq = 1.0 / (theta ** (torch.arange(0, dim, 2, dtype=torch.float) / dim)) self.register_buffer("inv_freq", inv_freq, persistent=False) def forward(self, seqlen: ...
class_definition
12,401
12,902
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,508
class PatchEmbed(nn.Module): def __init__( self, patch_size: int = 14, temporal_patch_size: int = 2, in_channels: int = 3, embed_dim: int = 1152, ) -> None: super().__init__() self.patch_size = patch_size self.temporal_patch_size = temporal_patch_s...
class_definition
12,905
13,870
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,509
class PatchMerger(nn.Module): def __init__(self, dim: int, context_dim: int, spatial_merge_size: int = 2) -> None: super().__init__() self.hidden_size = context_dim * (spatial_merge_size**2) self.ln_q = LayerNorm(context_dim, eps=1e-6) self.mlp = nn.Sequential( nn.Linear(...
class_definition
13,873
14,444
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,510
class VisionMlp(nn.Module): def __init__(self, dim: int, hidden_dim: int, hidden_act: str) -> None: super().__init__() self.fc1 = nn.Linear(dim, hidden_dim) self.act = ACT2FN[hidden_act] self.fc2 = nn.Linear(hidden_dim, dim) def forward(self, x) -> torch.Tensor: return s...
class_definition
14,447
14,797
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,511
class VisionAttention(nn.Module): def __init__(self, dim: int, num_heads: int = 16) -> None: super().__init__() self.num_heads = num_heads self.head_dim = dim // num_heads self.qkv = nn.Linear(dim, dim * 3, bias=True) self.proj = nn.Linear(dim, dim) def forward( ...
class_definition
14,800
16,421
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,512
class VisionFlashAttention2(nn.Module): def __init__(self, dim: int, num_heads: int = 16) -> None: super().__init__() self.num_heads = num_heads self.qkv = nn.Linear(dim, dim * 3, bias=True) self.proj = nn.Linear(dim, dim) def forward( self, hidden_states: torch.Tensor, ...
class_definition
16,424
17,443
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,513
class VisionSdpaAttention(nn.Module): def __init__(self, dim: int, num_heads: int = 16) -> None: super().__init__() self.num_heads = num_heads self.qkv = nn.Linear(dim, dim * 3, bias=True) self.proj = nn.Linear(dim, dim) def forward( self, hidden_states: torch.Tensor, cu...
class_definition
17,446
18,791
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,514
class Qwen2VLVisionBlock(nn.Module): def __init__(self, config, attn_implementation: str = "sdpa") -> None: super().__init__() self.norm1 = LayerNorm(config.embed_dim, eps=1e-6) self.norm2 = LayerNorm(config.embed_dim, eps=1e-6) mlp_hidden_dim = int(config.embed_dim * config.mlp_rati...
class_definition
18,947
19,862
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,515
class Qwen2RMSNorm(nn.Module): def __init__(self, hidden_size, eps=1e-6): """ Qwen2RMSNorm is equivalent to T5LayerNorm """ super().__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.variance_epsilon = eps def forward(self, hidden_states): ...
class_definition
19,933
20,653
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,516
class Qwen2MLP(nn.Module): def __init__(self, config): super().__init__() self.config = config self.hidden_size = config.hidden_size self.intermediate_size = config.intermediate_size self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False) self...
class_definition
20,720
21,388
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,517
class Qwen2VLAttention(nn.Module): """ Multi-headed attention from 'Attention Is All You Need' paper. Modified to use sliding window attention: Longformer and "Generating Long Sequences with Sparse Transformers". """ def __init__(self, config: Qwen2VLConfig, layer_idx: Optional[int] = None): ...
class_definition
22,065
27,413
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,518
class Qwen2VLFlashAttention2(Qwen2VLAttention): """ Qwen2VL flash attention module, following Qwen2VL attention module. This module inherits from `Qwen2VLAttention` as the weights of the module stays untouched. The only required change would be on the forward pass where it needs to correctly call the pu...
class_definition
27,416
32,776
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,519
class Qwen2VLSdpaAttention(Qwen2VLAttention): """ Qwen2 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from `Qwen2Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to SDPA API. """ # Adapted ...
class_definition
32,779
37,491
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,520
class Qwen2VLDecoderLayer(nn.Module): def __init__(self, config: Qwen2VLConfig, layer_idx: int): super().__init__() self.hidden_size = config.hidden_size if config.use_sliding_window and config._attn_implementation != "flash_attention_2": logger.warning_once( f"S...
class_definition
37,643
41,599
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,521
class Qwen2VLPreTrainedModel(PreTrainedModel): config_class = Qwen2VLConfig base_model_prefix = "model" supports_gradient_checkpointing = True _no_split_modules = ["Qwen2VLDecoderLayer", "Qwen2VLVisionBlock"] _skip_keys_device_placement = "past_key_values" _supports_flash_attn_2 = True _supp...
class_definition
42,629
43,523
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,522
class Qwen2VisionTransformerPretrainedModel(Qwen2VLPreTrainedModel): config_class = Qwen2VLVisionConfig _no_split_modules = ["Qwen2VLVisionBlock"] def __init__(self, config) -> None: super().__init__(config) self.spatial_merge_size = config.spatial_merge_size self.patch_embed = Pat...
class_definition
43,526
47,118
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,523
class Qwen2VLModel(Qwen2VLPreTrainedModel): def __init__(self, config: Qwen2VLConfig): super().__init__(config) self.padding_idx = config.pad_token_id self.vocab_size = config.vocab_size self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx) ...
class_definition
47,268
61,041
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,524
class Qwen2VLForConditionalGeneration(Qwen2VLPreTrainedModel, GenerationMixin): _tied_weights_keys = ["lm_head.weight"] def __init__(self, config): super().__init__(config) self.visual = Qwen2VisionTransformerPretrainedModel._from_config(config.vision_config) self.model = Qwen2VLModel(c...
class_definition
66,265
87,175
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
null
8,525
class Qwen2VLVisionConfig(PretrainedConfig): model_type = "qwen2_vl" base_config_key = "vision_config" def __init__( self, depth=32, embed_dim=1280, hidden_size=3584, hidden_act="quick_gelu", mlp_ratio=4, num_heads=16, in_channels=3, p...
class_definition
875
1,722
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/configuration_qwen2_vl.py
null
8,526
class Qwen2VLConfig(PretrainedConfig): r""" This is the configuration class to store the configuration of a [`Qwen2VLModel`]. It is used to instantiate a Qwen2-VL model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a sim...
class_definition
1,725
12,149
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/configuration_qwen2_vl.py
null
8,527
class Qwen2VLProcessorKwargs(ProcessingKwargs, total=False): _defaults = { "text_kwargs": { "padding": False, }, }
class_definition
1,335
1,485
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/processing_qwen2_vl.py
null
8,528
class Qwen2VLProcessor(ProcessorMixin): r""" Constructs a Qwen2-VL processor which wraps a Qwen2-VL image processor and a Qwen2 tokenizer into a single processor. [`Qwen2VLProcessor`] offers all the functionalities of [`Qwen2VLImageProcessor`] and [`Qwen2TokenizerFast`]. See the [`~Qwen2VLProcessor.__ca...
class_definition
1,488
9,482
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/processing_qwen2_vl.py
null
8,529
class Qwen2VLImageProcessor(BaseImageProcessor): r""" Constructs a Qwen2-VL image processor that dynamically resizes images based on the original images. Args: do_resize (`bool`, *optional*, defaults to `True`): Whether to resize the image's (height, width) dimensions. resample ...
class_definition
4,508
22,359
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py
null
8,530
class GPTSw3Tokenizer(PreTrainedTokenizer): """ Construct an GPTSw3 tokenizer. Based on [SentencePiece](https://github.com/google/sentencepiece). This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to this superclass for more information rega...
class_definition
445
12,469
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/gpt_sw3/tokenization_gpt_sw3.py
null
8,531
class TFSwiftFormerPatchEmbeddingSequential(keras.layers.Layer): """ The sequential component of the patch embedding layer. Input: tensor of shape `[batch_size, in_channels, height, width]` Output: tensor of shape `[batch_size, out_channels, height/4, width/4]` """ def __init__(self, config: ...
class_definition
1,530
3,687
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,532
class TFSwiftFormerPatchEmbedding(keras.layers.Layer): """ Patch Embedding Layer constructed of two 2D convolutional layers. Input: tensor of shape `[batch_size, in_channels, height, width]` Output: tensor of shape `[batch_size, out_channels, height/4, width/4]` """ def __init__(self, config:...
class_definition
3,690
4,585
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,533
class TFSwiftFormerDropPath(keras.layers.Layer): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).""" def __init__(self, config: SwiftFormerConfig, **kwargs) -> None: super().__init__(**kwargs) raise NotImplementedError("Drop path is not implemented in ...
class_definition
4,588
5,078
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,534
class TFSwiftFormerEmbeddings(keras.layers.Layer): """ Embeddings layer consisting of a single 2D convolutional and batch normalization layer. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height/stride, width/stride]` """ def _...
class_definition
5,081
6,939
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,535
class TFSwiftFormerConvEncoder(keras.layers.Layer): """ `SwiftFormerConvEncoder` with 3*3 and 1*1 convolutions. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height, width]` """ def __init__(self, config: SwiftFormerConfig, dim:...
class_definition
6,942
9,572
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,536
class TFSwiftFormerMlp(keras.layers.Layer): """ MLP layer with 1*1 convolutions. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height, width]` """ def __init__(self, config: SwiftFormerConfig, in_features: int, **kwargs): ...
class_definition
9,575
11,389
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,537
class TFSwiftFormerEfficientAdditiveAttention(keras.layers.Layer): """ Efficient Additive Attention module for SwiftFormer. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height, width]` """ def __init__(self, config: SwiftFormer...
class_definition
11,392
13,657
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,538
class TFSwiftFormerLocalRepresentation(keras.layers.Layer): """ Local Representation module for SwiftFormer that is implemented by 3*3 depth-wise and point-wise convolutions. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height, width]` ...
class_definition
13,660
16,237
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,539
class TFSwiftFormerEncoderBlock(keras.layers.Layer): """ SwiftFormer Encoder Block for SwiftFormer. It consists of (1) Local representation module, (2) SwiftFormerEfficientAdditiveAttention, and (3) MLP block. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `...
class_definition
16,240
19,125
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,540
class TFSwiftFormerStage(keras.layers.Layer): """ A Swiftformer stage consisting of a series of `SwiftFormerConvEncoder` blocks and a final `SwiftFormerEncoderBlock`. Input: tensor in shape `[batch_size, channels, height, width]` Output: tensor in shape `[batch_size, channels, height, width]` ...
class_definition
19,128
20,543
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,541
class TFSwiftFormerEncoder(keras.layers.Layer): def __init__(self, config: SwiftFormerConfig, **kwargs) -> None: super().__init__(**kwargs) self.config = config embed_dims = config.embed_dims downsamples = config.downsamples layer_depths = config.depths # Transforme...
class_definition
20,546
22,896
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,542
class TFSwiftFormerPreTrainedModel(TFPreTrainedModel): """ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. """ config_class = SwiftFormerConfig base_model_prefix = "swiftformer" main_input_name = "pixel_values"
class_definition
22,899
23,211
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,543
class TFSwiftFormerMainLayer(keras.layers.Layer): config_class = SwiftFormerConfig def __init__(self, config: SwiftFormerConfig, **kwargs): super().__init__(**kwargs) self.config = config self.patch_embed = TFSwiftFormerPatchEmbedding(config, name="patch_embed") self.encoder = ...
class_definition
25,871
28,187
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,544
class TFSwiftFormerModel(TFSwiftFormerPreTrainedModel): def __init__(self, config: SwiftFormerConfig, *inputs, **kwargs): super().__init__(config, *inputs, **kwargs) self.swiftformer = TFSwiftFormerMainLayer(config, name="swiftformer") @unpack_inputs @add_start_docstrings_to_model_forward(...
class_definition
28,361
29,485
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,545
class TFSwiftFormerForImageClassification(TFSwiftFormerPreTrainedModel): def __init__(self, config: SwiftFormerConfig, **kwargs) -> None: super().__init__(config, **kwargs) self.num_labels = config.num_labels self.swiftformer = TFSwiftFormerMainLayer(config, name="swiftformer") # C...
class_definition
29,663
34,859
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_tf_swiftformer.py
null
8,546
class SwiftFormerConfig(PretrainedConfig): r""" This is the configuration class to store the configuration of a [`SwiftFormerModel`]. It is used to instantiate an SwiftFormer model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will...
class_definition
925
5,391
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/configuration_swiftformer.py
null
8,547
class SwiftFormerOnnxConfig(OnnxConfig): torch_onnx_minimum_version = version.parse("1.11") @property def inputs(self) -> Mapping[str, Mapping[int, str]]: return OrderedDict( [ ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}), ] ...
class_definition
5,394
5,798
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/configuration_swiftformer.py
null
8,548
class SwiftFormerPatchEmbedding(nn.Module): """ Patch Embedding Layer constructed of two 2D convolutional layers. Input: tensor of shape `[batch_size, in_channels, height, width]` Output: tensor of shape `[batch_size, out_channels, height/4, width/4]` """ def __init__(self, config: SwiftForme...
class_definition
1,598
2,495
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,549
class SwiftFormerDropPath(nn.Module): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).""" def __init__(self, config: SwiftFormerConfig) -> None: super().__init__() self.drop_prob = config.drop_path_rate def forward(self, hidden_states: torch.Tenso...
class_definition
3,653
4,142
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,550
class SwiftFormerEmbeddings(nn.Module): """ Embeddings layer consisting of a single 2D convolutional and batch normalization layer. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height/stride, width/stride]` """ def __init__(sel...
class_definition
4,145
5,351
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,551
class SwiftFormerConvEncoder(nn.Module): """ `SwiftFormerConvEncoder` with 3*3 and 1*1 convolutions. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height, width]` """ def __init__(self, config: SwiftFormerConfig, dim: int): ...
class_definition
5,354
6,531
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,552
class SwiftFormerMlp(nn.Module): """ MLP layer with 1*1 convolutions. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height, width]` """ def __init__(self, config: SwiftFormerConfig, in_features: int): super().__init__() ...
class_definition
6,534
7,440
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,553
class SwiftFormerEfficientAdditiveAttention(nn.Module): """ Efficient Additive Attention module for SwiftFormer. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height, width]` """ def __init__(self, config: SwiftFormerConfig, dim...
class_definition
7,443
8,698
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,554
class SwiftFormerLocalRepresentation(nn.Module): """ Local Representation module for SwiftFormer that is implemented by 3*3 depth-wise and point-wise convolutions. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size, channels, height, width]` """ ...
class_definition
8,701
9,848
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,555
class SwiftFormerEncoderBlock(nn.Module): """ SwiftFormer Encoder Block for SwiftFormer. It consists of (1) Local representation module, (2) SwiftFormerEfficientAdditiveAttention, and (3) MLP block. Input: tensor of shape `[batch_size, channels, height, width]` Output: tensor of shape `[batch_size...
class_definition
9,851
11,745
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,556
class SwiftFormerStage(nn.Module): """ A Swiftformer stage consisting of a series of `SwiftFormerConvEncoder` blocks and a final `SwiftFormerEncoderBlock`. Input: tensor in shape `[batch_size, channels, height, width]` Output: tensor in shape `[batch_size, channels, height, width]` """ de...
class_definition
11,748
12,832
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,557
class SwiftFormerEncoder(nn.Module): def __init__(self, config: SwiftFormerConfig) -> None: super().__init__() self.config = config embed_dims = config.embed_dims downsamples = config.downsamples layer_depths = config.depths # Transformer model network = [] ...
class_definition
12,835
14,644
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,558
class SwiftFormerPreTrainedModel(PreTrainedModel): """ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. """ config_class = SwiftFormerConfig base_model_prefix = "swiftformer" main_input_name = "pixel_values" support...
class_definition
14,647
15,525
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,559
class SwiftFormerModel(SwiftFormerPreTrainedModel): def __init__(self, config: SwiftFormerConfig): super().__init__(config) self.config = config self.patch_embed = SwiftFormerPatchEmbedding(config) self.encoder = SwiftFormerEncoder(config) # Initialize weights and apply fin...
class_definition
16,941
18,724
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,560
class SwiftFormerForImageClassification(SwiftFormerPreTrainedModel): def __init__(self, config: SwiftFormerConfig) -> None: super().__init__(config) embed_dims = config.embed_dims self.num_labels = config.num_labels self.swiftformer = SwiftFormerModel(config) # Classifier ...
class_definition
18,898
22,745
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swiftformer/modeling_swiftformer.py
null
8,561
class NougatTokenizerFast(PreTrainedTokenizerFast): """ Fast tokenizer for Nougat (backed by HuggingFace tokenizers library). This tokenizer inherits from [`PreTrainedTokenizerFast`] which contains most of the main methods. Users should refer to this superclass for more information regarding those meth...
class_definition
13,076
24,703
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/nougat/tokenization_nougat_fast.py
null
8,562
class NougatProcessor(ProcessorMixin): r""" Constructs a Nougat processor which wraps a Nougat image processor and a Nougat tokenizer into a single processor. [`NougatProcessor`] offers all the functionalities of [`NougatImageProcessor`] and [`NougatTokenizerFast`]. See the [`~NougatProcessor.__call__`...
class_definition
887
6,730
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/nougat/processing_nougat.py
null
8,563
class NougatImageProcessor(BaseImageProcessor): r""" Constructs a Nougat image processor. Args: do_crop_margin (`bool`, *optional*, defaults to `True`): Whether to crop the image margins. do_resize (`bool`, *optional*, defaults to `True`): Whether to resize the image...
class_definition
1,549
23,701
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/nougat/image_processing_nougat.py
null
8,564
class Swinv2Config(BackboneConfigMixin, PretrainedConfig): r""" This is the configuration class to store the configuration of a [`Swinv2Model`]. It is used to instantiate a Swin Transformer v2 model according to the specified arguments, defining the model architecture. Instantiating a configuration with...
class_definition
895
7,517
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/configuration_swinv2.py
null
8,565
class Swinv2EncoderOutput(ModelOutput): """ Swinv2 encoder's outputs, with potential hidden states and attentions. Args: last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): Sequence of hidden-states at the output of the last layer of the model....
class_definition
2,124
4,093
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,566
class Swinv2ModelOutput(ModelOutput): """ Swinv2 model's outputs that also contains a pooling of the last hidden states. Args: last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): Sequence of hidden-states at the output of the last layer of the ...
class_definition
4,194
6,427
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,567
class Swinv2MaskedImageModelingOutput(ModelOutput): """ Swinv2 masked image model outputs. Args: loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `bool_masked_pos` is provided): Masked image modeling (MLM) loss. reconstruction (`torch.FloatTensor` of shape `(...
class_definition
6,542
8,957
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,568
class Swinv2ImageClassifierOutput(ModelOutput): """ Swinv2 outputs for image classification. Args: loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Classification (or regression if config.num_labels==1) loss. logits (`torch.FloatTensor`...
class_definition
9,068
11,208
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,569
class Swinv2DropPath(nn.Module): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).""" def __init__(self, drop_prob: Optional[float] = None) -> None: super().__init__() self.drop_prob = drop_prob def forward(self, hidden_states: torch.Tensor) -> tor...
class_definition
13,456
13,936
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,570
class Swinv2Embeddings(nn.Module): """ Construct the patch and position embeddings. Optionally, also the mask token. """ def __init__(self, config, use_mask_token=False): super().__init__() self.patch_embeddings = Swinv2PatchEmbeddings(config) num_patches = self.patch_embedding...
class_definition
14,025
17,938
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,571
class Swinv2PatchEmbeddings(nn.Module): """ This class turns `pixel_values` of shape `(batch_size, num_channels, height, width)` into the initial `hidden_states` (patch embeddings) of shape `(batch_size, seq_length, hidden_size)` to be consumed by a Transformer. """ def __init__(self, config): ...
class_definition
18,032
20,214
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,572
class Swinv2PatchMerging(nn.Module): """ Patch Merging Layer. Args: input_resolution (`Tuple[int]`): Resolution of input feature. dim (`int`): Number of input channels. norm_layer (`nn.Module`, *optional*, defaults to `nn.LayerNorm`): Normalizatio...
class_definition
20,217
22,509
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,573
class Swinv2SelfAttention(nn.Module): def __init__(self, config, dim, num_heads, window_size, pretrained_window_size=[0, 0]): super().__init__() if dim % num_heads != 0: raise ValueError( f"The hidden size ({dim}) is not a multiple of the number of attention heads ({num_h...
class_definition
22,512
29,493
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,574
class Swinv2SelfOutput(nn.Module): def __init__(self, config, dim): super().__init__() self.dense = nn.Linear(dim, dim) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) def forward(self, hidden_states: torch.Tensor, input_tensor: torch.Tensor) -> torch.Tensor: hidd...
class_definition
29,582
30,021
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,575
class Swinv2Attention(nn.Module): def __init__(self, config, dim, num_heads, window_size, pretrained_window_size=0): super().__init__() self.self = Swinv2SelfAttention( config=config, dim=dim, num_heads=num_heads, window_size=window_size, p...
class_definition
30,024
32,027
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,576
class Swinv2Intermediate(nn.Module): def __init__(self, config, dim): super().__init__() self.dense = nn.Linear(dim, int(config.mlp_ratio * dim)) if isinstance(config.hidden_act, str): self.intermediate_act_fn = ACT2FN[config.hidden_act] else: self.intermediat...
class_definition
32,118
32,678
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,577
class Swinv2Output(nn.Module): def __init__(self, config, dim): super().__init__() self.dense = nn.Linear(int(config.mlp_ratio * dim), dim) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states: torch.Tensor) -> torch.Tensor: hidden_states = self....
class_definition
32,763
33,184
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,578
class Swinv2Layer(nn.Module): def __init__( self, config, dim, input_resolution, num_heads, drop_path_rate=0.0, shift_size=0, pretrained_window_size=0 ): super().__init__() self.input_resolution = input_resolution window_size, shift_size = self._compute_window_shift( ...
class_definition
33,187
39,128
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,579
class Swinv2Stage(nn.Module): def __init__( self, config, dim, input_resolution, depth, num_heads, drop_path, downsample, pretrained_window_size=0 ): super().__init__() self.config = config self.dim = dim blocks = [] for i in range(depth): block = Swin...
class_definition
39,131
41,424
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,580
class Swinv2Encoder(nn.Module): def __init__(self, config, grid_size, pretrained_window_sizes=(0, 0, 0, 0)): super().__init__() self.num_layers = len(config.depths) self.config = config if self.config.pretrained_window_sizes is not None: pretrained_window_sizes = config.p...
class_definition
41,427
46,347
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,581
class Swinv2PreTrainedModel(PreTrainedModel): """ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. """ config_class = Swinv2Config base_model_prefix = "swinv2" main_input_name = "pixel_values" supports_gradient_chec...
class_definition
46,454
47,413
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,582
class Swinv2Model(Swinv2PreTrainedModel): def __init__(self, config, add_pooling_layer=True, use_mask_token=False): super().__init__(config) self.config = config self.num_layers = len(config.depths) self.num_features = int(config.embed_dim * 2 ** (self.num_layers - 1)) self....
class_definition
49,563
53,744
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,583
class Swinv2ForMaskedImageModeling(Swinv2PreTrainedModel): def __init__(self, config): super().__init__(config) self.swinv2 = Swinv2Model(config, add_pooling_layer=False, use_mask_token=True) num_features = int(config.embed_dim * 2 ** (config.num_layers - 1)) self.decoder = nn.Sequ...
class_definition
54,340
59,064
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,584
class Swinv2ForImageClassification(Swinv2PreTrainedModel): def __init__(self, config): super().__init__(config) self.num_labels = config.num_labels self.swinv2 = Swinv2Model(config) # Classifier head self.classifier = ( nn.Linear(self.swinv2.num_features, config...
class_definition
59,742
63,385
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,585
class Swinv2Backbone(Swinv2PreTrainedModel, BackboneMixin): def __init__(self, config): super().__init__(config) super()._init_backbone(config) self.num_features = [config.embed_dim] + [int(config.embed_dim * 2**i) for i in range(len(config.depths))] self.embeddings = Swinv2Embeddin...
class_definition
63,532
66,847
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/swinv2/modeling_swinv2.py
null
8,586
class RegNetConvLayer(nn.Module): def __init__( self, in_channels: int, out_channels: int, kernel_size: int = 3, stride: int = 1, groups: int = 1, activation: Optional[str] = "relu", ): super().__init__() self.convolution = nn.Conv2d( ...
class_definition
1,625
2,530
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,587
class RegNetEmbeddings(nn.Module): """ RegNet Embedddings (stem) composed of a single aggressive convolution. """ def __init__(self, config: RegNetConfig): super().__init__() self.embedder = RegNetConvLayer( config.num_channels, config.embedding_size, kernel_size=3, stride=2...
class_definition
2,533
3,313
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,588
class RegNetShortCut(nn.Module): """ RegNet shortcut, used to project the residual features to the correct size. If needed, it is also used to downsample the input using `stride=2`. """ def __init__(self, in_channels: int, out_channels: int, stride: int = 2): super().__init__() self...
class_definition
3,408
4,059
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,589
class RegNetSELayer(nn.Module): """ Squeeze and Excitation layer (SE) proposed in [Squeeze-and-Excitation Networks](https://arxiv.org/abs/1709.01507). """ def __init__(self, in_channels: int, reduced_channels: int): super().__init__() self.pooler = nn.AdaptiveAvgPool2d((1, 1)) ...
class_definition
4,062
4,839
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,590
class RegNetXLayer(nn.Module): """ RegNet's layer composed by three `3x3` convolutions, same as a ResNet bottleneck layer with reduction = 1. """ def __init__(self, config: RegNetConfig, in_channels: int, out_channels: int, stride: int = 1): super().__init__() should_apply_shortcut = in...
class_definition
4,842
6,092
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,591
class RegNetYLayer(nn.Module): """ RegNet's Y layer: an X layer with Squeeze and Excitation. """ def __init__(self, config: RegNetConfig, in_channels: int, out_channels: int, stride: int = 1): super().__init__() should_apply_shortcut = in_channels != out_channels or stride != 1 ...
class_definition
6,095
7,383
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,592
class RegNetStage(nn.Module): """ A RegNet stage composed by stacked layers. """ def __init__( self, config: RegNetConfig, in_channels: int, out_channels: int, stride: int = 2, depth: int = 2, ): super().__init__() layer = RegNetXLaye...
class_definition
7,386
8,219
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,593
class RegNetEncoder(nn.Module): def __init__(self, config: RegNetConfig): super().__init__() self.stages = nn.ModuleList([]) # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input self.stages.append( RegNetStage( ...
class_definition
8,222
9,763
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,594
class RegNetPreTrainedModel(PreTrainedModel): """ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. """ config_class = RegNetConfig base_model_prefix = "regnet" main_input_name = "pixel_values" _no_split_modules = ["...
class_definition
9,766
10,975
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,595
class RegNetModel(RegNetPreTrainedModel): def __init__(self, config): super().__init__(config) self.config = config self.embedder = RegNetEmbeddings(config) self.encoder = RegNetEncoder(config) self.pooler = nn.AdaptiveAvgPool2d((1, 1)) # Initialize weights and apply ...
class_definition
12,464
14,204
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,596
class RegNetForImageClassification(RegNetPreTrainedModel): def __init__(self, config): super().__init__(config) self.num_labels = config.num_labels self.regnet = RegNetModel(config) # classification head self.classifier = nn.Sequential( nn.Flatten(), n...
class_definition
14,542
17,686
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/modeling_regnet.py
null
8,597
class RegNetConfig(PretrainedConfig): r""" This is the configuration class to store the configuration of a [`RegNetModel`]. It is used to instantiate a RegNet model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar...
class_definition
808
3,944
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/configuration_regnet.py
null
8,598
class Tracker: module: nn.Module traced: List[nn.Module] = field(default_factory=list) handles: list = field(default_factory=list) def _forward_hook(self, m, inputs: Tensor, outputs: Tensor): has_not_submodules = len(list(m.modules())) == 1 or isinstance(m, nn.Conv2d) or isinstance(m, nn.BatchN...
class_definition
1,329
2,173
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/regnet/convert_regnet_to_pytorch.py
null
8,599