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 FlaxBeitEncoder(nn.Module):
config: BeitConfig
window_size: Tuple[int, int]
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
if self.config.use_shared_relative_position_bias:
self.relative_position_bias = FlaxBeitRelativePositionBias(
... | class_definition | 22,888 | 24,247 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,000 |
class FlaxBeitPreTrainedModel(FlaxPreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = BeitConfig
base_model_prefix = "beit"
main_input_name = "pixel_values"
module_class: nn.Mod... | class_definition | 24,250 | 27,429 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,001 |
class FlaxBeitPooler(nn.Module):
config: BeitConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
if self.config.use_mean_pooling:
self.layernorm = nn.LayerNorm(epsilon=self.config.layer_norm_eps, dtype=self.dtype)
def __call__(self, hidden_states)... | class_definition | 27,432 | 28,158 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,002 |
class FlaxBeitModule(nn.Module):
config: BeitConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
add_pooling_layer: bool = True
def setup(self):
self.embeddings = FlaxBeitEmbeddings(self.config, dtype=self.dtype)
self.encoder = FlaxBeitEncoder(
self.config,... | class_definition | 28,161 | 30,077 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,003 |
class FlaxBeitModel(FlaxBeitPreTrainedModel):
module_class = FlaxBeitModule | class_definition | 30,233 | 30,312 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,004 |
class FlaxBeitForMaskedImageModelingModule(nn.Module):
config: BeitConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.beit = FlaxBeitModule(self.config, add_pooling_layer=False, dtype=self.dtype)
# Classifier head
self.layernorm = nn.LayerNo... | class_definition | 31,205 | 32,818 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,005 |
class FlaxBeitForMaskedImageModeling(FlaxBeitPreTrainedModel):
module_class = FlaxBeitForMaskedImageModelingModule | class_definition | 32,969 | 33,087 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,006 |
class FlaxBeitForImageClassificationModule(nn.Module):
config: BeitConfig
dtype: jnp.dtype = jnp.float32
def setup(self):
self.beit = FlaxBeitModule(config=self.config, dtype=self.dtype, add_pooling_layer=True)
self.classifier = nn.Dense(
self.config.num_labels,
kern... | class_definition | 34,167 | 35,520 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,007 |
class FlaxBeitForImageClassification(FlaxBeitPreTrainedModel):
module_class = FlaxBeitForImageClassificationModule | class_definition | 35,768 | 35,886 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/modeling_flax_beit.py | null | 8,008 |
class BeitConfig(BackboneConfigMixin, PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`BeitModel`]. It is used to instantiate an BEiT
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will... | class_definition | 972 | 11,077 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/configuration_beit.py | null | 8,009 |
class BeitOnnxConfig(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 | 11,150 | 11,547 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/beit/configuration_beit.py | null | 8,010 |
class HybridMambaAttentionDynamicCache(modeling_jamba.HybridMambaAttentionDynamicCache):
"""
A dynamic cache that can handle both the attention cache (which has a seq_len dimension) and the mamba cache
(which has a constant shape regardless of seq_len).
This cache has two sets of lists of tensors: `key... | class_definition | 2,835 | 5,632 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,011 |
class BambaRotaryEmbedding(LlamaRotaryEmbedding):
pass | class_definition | 5,635 | 5,693 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,012 |
class BambaAttention(LlamaAttention):
pass | class_definition | 7,789 | 7,835 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,013 |
class BambaRMSNormGated(MambaRMSNormGated):
pass | class_definition | 7,838 | 7,890 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,014 |
class BambaMixer(nn.Module):
"""
Compute ∆, A, B, C, and D the state space parameters and compute the `contextualized_states`.
A, D are input independent (see Mamba paper [1] Section 3.5.2 "Interpretation of A" for why A isn't selective)
∆, B, C are input-dependent (this is a key difference between Mamb... | class_definition | 8,390 | 31,281 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,015 |
class BambaMLP(LlamaMLP):
pass | class_definition | 31,284 | 31,318 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,016 |
class BambaRMSNorm(LlamaRMSNorm):
pass | class_definition | 31,321 | 31,363 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,017 |
class BambaDecoderLayer(JambaAttentionDecoderLayer):
def __init__(self, config: BambaConfig, layer_idx: int, layer_type: str = "mamba"):
super().__init__()
del self.self_attn
num_experts = 1
ffn_layer_class = BambaMLP if num_experts == 1 else None
self.feed_forward = ffn_la... | class_definition | 31,366 | 35,584 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,018 |
class BambaPreTrainedModel(PreTrainedModel):
config_class = BambaConfig
base_model_prefix = "model"
supports_gradient_checkpointing = True
_no_split_modules = ["BambaDecoderLayer"]
_skip_keys_device_placement = "past_key_values"
_supports_flash_attn_2 = True
_supports_sdpa = True
_suppor... | class_definition | 36,605 | 37,517 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,019 |
class BambaModel(BambaPreTrainedModel):
"""
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`BambaDecoderLayer`]
Args:
config: BambaConfig
"""
def __init__(self, config: BambaConfig):
super().__init__(config)
self.padding_idx = config.p... | class_definition | 42,345 | 54,686 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,020 |
class BambaForCausalLM(LlamaForCausalLM):
@add_start_docstrings_to_model_forward(BAMBA_INPUTS_DOCSTRING)
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
def forward(
self,
input_ids: torch.LongTensor = None,
attention_mask: Optional[torch.... | class_definition | 54,689 | 59,864 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modular_bamba.py | null | 8,021 |
class BambaConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`BambaModel`]. It is used to instantiate a
BambaModel model according to the specified arguments, defining the model architecture. Instantiating a configuration
with defaults taken from [ibm-fms/Ba... | class_definition | 790 | 9,857 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/configuration_bamba.py | null | 8,022 |
class HybridMambaAttentionDynamicCache(modeling_jamba.HybridMambaAttentionDynamicCache):
"""
A dynamic cache that can handle both the attention cache (which has a seq_len dimension) and the mamba cache
(which has a constant shape regardless of seq_len).
This cache has two sets of lists of tensors: `key... | class_definition | 3,300 | 6,097 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,023 |
class BambaRotaryEmbedding(nn.Module):
def __init__(self, config: BambaConfig, device=None):
super().__init__()
# BC: "rope_type" was originally "type"
if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
self.rope_type = config.rope_scaling.get("rope_type", co... | class_definition | 6,100 | 9,295 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,024 |
class BambaAttention(nn.Module):
"""Multi-headed attention from 'Attention Is All You Need' paper"""
def __init__(self, config: BambaConfig, layer_idx: int):
super().__init__()
self.config = config
self.layer_idx = layer_idx
self.head_dim = getattr(config, "head_dim", config.hid... | class_definition | 13,129 | 16,696 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,025 |
class BambaRMSNormGated(torch.nn.Module):
def __init__(self, hidden_size, eps=1e-6):
super().__init__()
self.weight = nn.Parameter(torch.ones(hidden_size))
self.variance_epsilon = eps
def forward(self, hidden_states, gate=None):
input_dtype = hidden_states.dtype
hidden_s... | class_definition | 16,699 | 17,384 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,026 |
class BambaMixer(nn.Module):
"""
Compute ∆, A, B, C, and D the state space parameters and compute the `contextualized_states`.
A, D are input independent (see Mamba paper [1] Section 3.5.2 "Interpretation of A" for why A isn't selective)
∆, B, C are input-dependent (this is a key difference between Mamb... | class_definition | 20,465 | 43,356 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,027 |
class BambaMLP(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=config.mlp_bias)
... | class_definition | 43,359 | 44,057 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,028 |
class BambaRMSNorm(nn.Module):
def __init__(self, hidden_size, eps=1e-6):
"""
BambaRMSNorm 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 | 44,060 | 44,780 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,029 |
class BambaDecoderLayer(nn.Module):
def __init__(self, config: BambaConfig, layer_idx: int, layer_type: str = "mamba"):
super().__init__()
num_experts = 1
ffn_layer_class = BambaMLP if num_experts == 1 else None
self.feed_forward = ffn_layer_class(config)
self.input_layernor... | class_definition | 44,783 | 49,135 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,030 |
class BambaPreTrainedModel(PreTrainedModel):
config_class = BambaConfig
base_model_prefix = "model"
supports_gradient_checkpointing = True
_no_split_modules = ["BambaDecoderLayer"]
_skip_keys_device_placement = "past_key_values"
_supports_flash_attn_2 = True
_supports_sdpa = True
_suppor... | class_definition | 50,156 | 51,068 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,031 |
class BambaModel(BambaPreTrainedModel):
"""
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`BambaDecoderLayer`]
Args:
config: BambaConfig
"""
def __init__(self, config: BambaConfig):
super().__init__(config)
self.padding_idx = config.p... | class_definition | 55,896 | 68,237 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,032 |
class BambaForCausalLM(BambaPreTrainedModel, GenerationMixin):
_tied_weights_keys = ["lm_head.weight"]
_tp_plan = {"lm_head": "colwise_rep"}
def __init__(self, config):
super().__init__(config)
self.model = BambaModel(config)
self.vocab_size = config.vocab_size
self.lm_head ... | class_definition | 68,240 | 75,581 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/bamba/modeling_bamba.py | null | 8,033 |
class TimmBackbone(PreTrainedModel, BackboneMixin):
"""
Wrapper class for timm models to be used as backbones. This enables using the timm models interchangeably with the
other models in the library keeping the same API.
"""
main_input_name = "pixel_values"
supports_gradient_checkpointing = Fal... | class_definition | 1,065 | 6,619 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/timm_backbone/modeling_timm_backbone.py | null | 8,034 |
class TimmBackboneConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration for a timm backbone [`TimmBackbone`].
It is used to instantiate a timm backbone model according to the specified arguments, defining the model.
Configuration objects inherit from [`PretrainedCon... | class_definition | 791 | 3,150 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/timm_backbone/configuration_timm_backbone.py | null | 8,035 |
class XCLIPOutput(ModelOutput):
"""
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `return_loss` is `True`):
Contrastive loss for video-text similarity.
logits_per_video (`torch.FloatTensor` of shape `(video_batch_size, text_batch_size)`):
The ... | class_definition | 2,047 | 4,146 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,036 |
class XCLIPVisionEmbeddings(nn.Module):
def __init__(self, config: XCLIPVisionConfig):
super().__init__()
self.config = config
self.embed_dim = config.hidden_size
self.image_size = config.image_size
self.patch_size = config.patch_size
self.class_embedding = nn.Parame... | class_definition | 4,240 | 8,068 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,037 |
class XCLIPTextEmbeddings(nn.Module):
def __init__(self, config: XCLIPTextConfig):
super().__init__()
embed_dim = config.hidden_size
self.token_embedding = nn.Embedding(config.vocab_size, embed_dim)
self.position_embedding = nn.Embedding(config.max_position_embeddings, embed_dim)
... | class_definition | 8,160 | 9,740 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,038 |
class XCLIPAttention(nn.Module):
"""Multi-headed attention from 'Attention Is All You Need' paper"""
def __init__(self, config):
super().__init__()
self.config = config
self.embed_dim = config.hidden_size
self.num_heads = config.num_attention_heads
self.head_dim = self.e... | class_definition | 9,827 | 14,558 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,039 |
class XCLIPMLP(nn.Module):
def __init__(self, config):
super().__init__()
self.config = config
self.activation_fn = ACT2FN[config.hidden_act]
self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
... | class_definition | 14,639 | 15,210 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,040 |
class XCLIPEncoderLayer(nn.Module):
def __init__(self, config: XCLIPConfig):
super().__init__()
self.embed_dim = config.hidden_size
self.self_attn = XCLIPAttention(config)
self.layer_norm1 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
self.mlp = XCLIPMLP(config)
... | class_definition | 15,312 | 17,261 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,041 |
class XCLIPDropPath(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) -> torc... | class_definition | 18,502 | 18,981 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,042 |
class XCLIPVisionEncoderLayer(nn.Module):
"""
This corresponds to the `CrossFramelAttentionBlock` class in the original implementation.
"""
def __init__(self, config: XCLIPConfig):
super().__init__()
self.num_frames = config.num_frames
self.embed_dim = config.hidden_size
... | class_definition | 18,984 | 22,353 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,043 |
class XCLIPPreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = XCLIPConfig
base_model_prefix = "x_clip"
supports_gradient_checkpointing = True
def _init_weights... | class_definition | 22,356 | 25,378 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,044 |
class XCLIPEncoder(nn.Module):
"""
Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`XCLIPEncoderLayer`].
Args:
config: XCLIPConfig
"""
def __init__(self, config: XCLIPConfig):
super().__init__()
self.config = config
... | class_definition | 31,071 | 35,464 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,045 |
class XCLIPTextTransformer(nn.Module):
def __init__(self, config: XCLIPTextConfig):
super().__init__()
self.config = config
embed_dim = config.hidden_size
self.embeddings = XCLIPTextEmbeddings(config)
self.encoder = XCLIPEncoder(config)
self.final_layer_norm = nn.Laye... | class_definition | 35,467 | 38,740 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,046 |
class XCLIPTextModel(XCLIPPreTrainedModel):
config_class = XCLIPTextConfig
def __init__(self, config: XCLIPTextConfig):
super().__init__(config)
self.text_model = XCLIPTextTransformer(config)
# Initialize weights and apply final processing
self.post_init()
def get_input_emb... | class_definition | 38,743 | 40,716 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,047 |
class XCLIPVisionEncoder(nn.Module):
"""
Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`XCLIPVisionEncoderLayer`].
Args:
config: XCLIPConfig
"""
def __init__(self, config: XCLIPConfig):
super().__init__()
self.confi... | class_definition | 40,719 | 45,130 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,048 |
class XCLIPVisionTransformer(nn.Module):
"""
This corresponds to the `CrossFrameCommunicationTransformer` class in the original implementation.
"""
def __init__(self, config: XCLIPVisionConfig):
super().__init__()
self.config = config
embed_dim = config.hidden_size
self... | class_definition | 45,133 | 47,517 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,049 |
class XCLIPVisionModel(XCLIPPreTrainedModel):
config_class = XCLIPVisionConfig
main_input_name = "pixel_values"
def __init__(self, config: XCLIPVisionConfig):
super().__init__(config)
self.vision_model = XCLIPVisionTransformer(config)
# Initialize weights and apply final processing
... | class_definition | 47,520 | 51,827 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,050 |
class XCLIPMultiframeIntegrationTransformer(nn.Module):
"""
This corresponds to the `MultiframeIntegrationTransformer` class in the original implementation.
"""
def __init__(self, config: XCLIPVisionConfig):
super().__init__()
self.position_embedding = nn.Parameter(torch.empty(1, confi... | class_definition | 51,830 | 53,393 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,051 |
class XCLIPCrossAttention(nn.Module):
"""Multi-headed attention from 'Attention Is All You Need' paper"""
def __init__(self, config):
super().__init__()
self.num_heads = config.prompt_num_attention_heads
dim = config.projection_dim
head_dim = dim // self.num_heads
self.... | class_definition | 53,396 | 55,345 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,052 |
class PromptGeneratorLayer(nn.Module):
def __init__(self, config):
super().__init__()
embed_dim = config.projection_dim
self.cross_attn = XCLIPCrossAttention(config)
self.norm1 = nn.LayerNorm(embed_dim, eps=config.text_config.layer_norm_eps)
self.norm3 = nn.LayerNorm(embed_d... | class_definition | 55,348 | 56,110 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,053 |
class XCLIPPromptGenerator(nn.Module):
"""This corresponds to the `VideoSpecificPrompt` class in the original implementation."""
def __init__(self, config):
super().__init__()
embed_dim = config.projection_dim
self.layernorm = nn.LayerNorm(embed_dim, eps=config.vision_config.layer_norm_... | class_definition | 56,113 | 56,808 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,054 |
class XCLIPModel(XCLIPPreTrainedModel):
config_class = XCLIPConfig
def __init__(self, config: XCLIPConfig):
super().__init__(config)
if not isinstance(config.text_config, XCLIPTextConfig):
raise TypeError(
"config.text_config is expected to be of type XCLIPTextConfi... | class_definition | 56,857 | 73,270 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/modeling_x_clip.py | null | 8,055 |
class XCLIPTextConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`XCLIPModel`]. It is used to instantiate an X-CLIP
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a simi... | class_definition | 783 | 5,075 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/configuration_x_clip.py | null | 8,056 |
class XCLIPVisionConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`XCLIPModel`]. It is used to instantiate an X-CLIP
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a si... | class_definition | 5,078 | 10,280 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/configuration_x_clip.py | null | 8,057 |
class XCLIPConfig(PretrainedConfig):
r"""
[`XCLIPConfig`] is the configuration class to store the configuration of a [`XCLIPModel`]. It is used to
instantiate X-CLIP model according to the specified arguments, defining the text model and vision model configs.
Instantiating a configuration with the defau... | class_definition | 10,283 | 18,660 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/configuration_x_clip.py | null | 8,058 |
class XCLIPProcessor(ProcessorMixin):
r"""
Constructs an X-CLIP processor which wraps a VideoMAE image processor and a CLIP tokenizer into a single processor.
[`XCLIPProcessor`] offers all the functionalities of [`VideoMAEImageProcessor`] and [`CLIPTokenizerFast`]. See the
[`~XCLIPProcessor.__call__`] ... | class_definition | 770 | 6,896 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/x_clip/processing_x_clip.py | null | 8,059 |
class TFBaseModelOutputWithCLSToken(ModelOutput):
"""
Base class for model's outputs.
Args:
last_hidden_state (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`):
Sequence of hidden-states at the output of the last layer of the model.
cls_token_value (`tf.Tensor`... | class_definition | 1,451 | 2,463 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,060 |
class TFCvtDropPath(keras.layers.Layer):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
References:
(1) github.com:rwightman/pytorch-image-models
"""
def __init__(self, drop_prob: float, **kwargs):
super().__init__(**kwargs)
self.drop... | class_definition | 2,466 | 3,217 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,061 |
class TFCvtEmbeddings(keras.layers.Layer):
"""Construct the Convolutional Token Embeddings."""
def __init__(
self,
config: CvtConfig,
patch_size: int,
num_channels: int,
embed_dim: int,
stride: int,
padding: int,
dropout_rate: float,
**kwa... | class_definition | 3,220 | 4,484 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,062 |
class TFCvtConvEmbeddings(keras.layers.Layer):
"""Image to Convolution Embeddings. This convolutional operation aims to model local spatial contexts."""
def __init__(
self,
config: CvtConfig,
patch_size: int,
num_channels: int,
embed_dim: int,
stride: int,
... | class_definition | 4,487 | 6,914 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,063 |
class TFCvtSelfAttentionConvProjection(keras.layers.Layer):
"""Convolutional projection layer."""
def __init__(self, config: CvtConfig, embed_dim: int, kernel_size: int, stride: int, padding: int, **kwargs):
super().__init__(**kwargs)
self.padding = keras.layers.ZeroPadding2D(padding=padding)
... | class_definition | 6,917 | 8,558 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,064 |
class TFCvtSelfAttentionLinearProjection(keras.layers.Layer):
"""Linear projection layer used to flatten tokens into 1D."""
def call(self, hidden_state: tf.Tensor) -> tf.Tensor:
# "batch_size, height, width, num_channels -> batch_size, (height*width), num_channels"
batch_size, height, width, nu... | class_definition | 8,561 | 9,078 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,065 |
class TFCvtSelfAttentionProjection(keras.layers.Layer):
"""Convolutional Projection for Attention."""
def __init__(
self,
config: CvtConfig,
embed_dim: int,
kernel_size: int,
stride: int,
padding: int,
projection_method: str = "dw_bn",
**kwargs,
... | class_definition | 9,081 | 10,292 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,066 |
class TFCvtSelfAttention(keras.layers.Layer):
"""
Self-attention layer. A depth-wise separable convolution operation (Convolutional Projection), is applied for
query, key, and value embeddings.
"""
def __init__(
self,
config: CvtConfig,
num_heads: int,
embed_dim: int... | class_definition | 10,295 | 16,491 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,067 |
class TFCvtSelfOutput(keras.layers.Layer):
"""Output of the Attention layer ."""
def __init__(self, config: CvtConfig, embed_dim: int, drop_rate: float, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=embed_dim, kernel_initializer=get_initializer(config.... | class_definition | 16,494 | 17,461 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,068 |
class TFCvtAttention(keras.layers.Layer):
"""Attention layer. First chunk of the convolutional transformer block."""
def __init__(
self,
config: CvtConfig,
num_heads: int,
embed_dim: int,
kernel_size: int,
stride_q: int,
stride_kv: int,
padding_q:... | class_definition | 17,464 | 19,289 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,069 |
class TFCvtIntermediate(keras.layers.Layer):
"""Intermediate dense layer. Second chunk of the convolutional transformer block."""
def __init__(self, config: CvtConfig, embed_dim: int, mlp_ratio: int, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=int(em... | class_definition | 19,292 | 20,217 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,070 |
class TFCvtOutput(keras.layers.Layer):
"""
Output of the Convolutional Transformer Block (last chunk). It consists of a MLP and a residual connection.
"""
def __init__(self, config: CvtConfig, embed_dim: int, mlp_ratio: int, drop_rate: int, **kwargs):
super().__init__(**kwargs)
self.den... | class_definition | 20,220 | 21,416 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,071 |
class TFCvtLayer(keras.layers.Layer):
"""
Convolutional Transformer Block composed by attention layers, normalization and multi-layer perceptrons (mlps). It
consists of 3 chunks : an attention layer, an intermediate dense layer and an output layer. This corresponds to the
`Block` class in the original i... | class_definition | 21,419 | 25,441 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,072 |
class TFCvtStage(keras.layers.Layer):
"""
Cvt stage (encoder block). Each stage has 2 parts :
- (1) A Convolutional Token Embedding layer
- (2) A Convolutional Transformer Block (layer).
The classification token is added only in the last stage.
Args:
config ([`CvtConfig`]): Model config... | class_definition | 25,444 | 29,598 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,073 |
class TFCvtEncoder(keras.layers.Layer):
"""
Convolutional Vision Transformer encoder. CVT has 3 stages of encoder blocks with their respective number of layers
(depth) being 1, 2 and 10.
Args:
config ([`CvtConfig`]): Model configuration class.
"""
config_class = CvtConfig
def __in... | class_definition | 29,601 | 32,017 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,074 |
class TFCvtMainLayer(keras.layers.Layer):
"""Construct the Cvt model."""
config_class = CvtConfig
def __init__(self, config: CvtConfig, **kwargs):
super().__init__(**kwargs)
self.config = config
self.encoder = TFCvtEncoder(config, name="encoder")
@unpack_inputs
def call(
... | class_definition | 32,040 | 33,540 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,075 |
class TFCvtPreTrainedModel(TFPreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = CvtConfig
base_model_prefix = "cvt"
main_input_name = "pixel_values" | class_definition | 33,543 | 33,831 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,076 |
class TFCvtModel(TFCvtPreTrainedModel):
def __init__(self, config: CvtConfig, *inputs, **kwargs):
super().__init__(config, *inputs, **kwargs)
self.cvt = TFCvtMainLayer(config, name="cvt")
@unpack_inputs
@add_start_docstrings_to_model_forward(TFCVT_INPUTS_DOCSTRING)
@replace_return_docs... | class_definition | 36,427 | 38,619 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,077 |
class TFCvtForImageClassification(TFCvtPreTrainedModel, TFSequenceClassificationLoss):
def __init__(self, config: CvtConfig, *inputs, **kwargs):
super().__init__(config, *inputs, **kwargs)
self.num_labels = config.num_labels
self.cvt = TFCvtMainLayer(config, name="cvt")
# Using same... | class_definition | 38,850 | 43,462 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_tf_cvt.py | null | 8,078 |
class CvtConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`CvtModel`]. It is used to instantiate a CvT model
according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configur... | class_definition | 780 | 6,657 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/configuration_cvt.py | null | 8,079 |
class BaseModelOutputWithCLSToken(ModelOutput):
"""
Base class for model'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... | class_definition | 1,606 | 2,720 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,080 |
class CvtDropPath(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) -> torch.... | class_definition | 3,944 | 4,421 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,081 |
class CvtEmbeddings(nn.Module):
"""
Construct the CvT embeddings.
"""
def __init__(self, patch_size, num_channels, embed_dim, stride, padding, dropout_rate):
super().__init__()
self.convolution_embeddings = CvtConvEmbeddings(
patch_size=patch_size, num_channels=num_channels,... | class_definition | 4,424 | 5,035 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,082 |
class CvtConvEmbeddings(nn.Module):
"""
Image to Conv Embedding.
"""
def __init__(self, patch_size, num_channels, embed_dim, stride, padding):
super().__init__()
patch_size = patch_size if isinstance(patch_size, collections.abc.Iterable) else (patch_size, patch_size)
self.patch_... | class_definition | 5,038 | 6,144 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,083 |
class CvtSelfAttentionConvProjection(nn.Module):
def __init__(self, embed_dim, kernel_size, padding, stride):
super().__init__()
self.convolution = nn.Conv2d(
embed_dim,
embed_dim,
kernel_size=kernel_size,
padding=padding,
stride=stride,
... | class_definition | 6,147 | 6,759 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,084 |
class CvtSelfAttentionLinearProjection(nn.Module):
def forward(self, hidden_state):
batch_size, num_channels, height, width = hidden_state.shape
hidden_size = height * width
# rearrange " b c h w -> b (h w) c"
hidden_state = hidden_state.view(batch_size, num_channels, hidden_size).pe... | class_definition | 6,762 | 7,124 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,085 |
class CvtSelfAttentionProjection(nn.Module):
def __init__(self, embed_dim, kernel_size, padding, stride, projection_method="dw_bn"):
super().__init__()
if projection_method == "dw_bn":
self.convolution_projection = CvtSelfAttentionConvProjection(embed_dim, kernel_size, padding, stride)
... | class_definition | 7,127 | 7,704 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,086 |
class CvtSelfAttention(nn.Module):
def __init__(
self,
num_heads,
embed_dim,
kernel_size,
padding_q,
padding_kv,
stride_q,
stride_kv,
qkv_projection_method,
qkv_bias,
attention_drop_rate,
with_cls_token=True,
**k... | class_definition | 7,707 | 11,069 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,087 |
class CvtSelfOutput(nn.Module):
"""
The residual connection is defined in CvtLayer instead of here (as is the case with other models), due to the
layernorm applied before each block.
"""
def __init__(self, embed_dim, drop_rate):
super().__init__()
self.dense = nn.Linear(embed_dim, e... | class_definition | 11,072 | 11,624 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,088 |
class CvtAttention(nn.Module):
def __init__(
self,
num_heads,
embed_dim,
kernel_size,
padding_q,
padding_kv,
stride_q,
stride_kv,
qkv_projection_method,
qkv_bias,
attention_drop_rate,
drop_rate,
with_cls_token=Tr... | class_definition | 11,627 | 13,546 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,089 |
class CvtIntermediate(nn.Module):
def __init__(self, embed_dim, mlp_ratio):
super().__init__()
self.dense = nn.Linear(embed_dim, int(embed_dim * mlp_ratio))
self.activation = nn.GELU()
def forward(self, hidden_state):
hidden_state = self.dense(hidden_state)
hidden_state ... | class_definition | 13,549 | 13,928 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,090 |
class CvtOutput(nn.Module):
def __init__(self, embed_dim, mlp_ratio, drop_rate):
super().__init__()
self.dense = nn.Linear(int(embed_dim * mlp_ratio), embed_dim)
self.dropout = nn.Dropout(drop_rate)
def forward(self, hidden_state, input_tensor):
hidden_state = self.dense(hidden_... | class_definition | 13,931 | 14,386 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,091 |
class CvtLayer(nn.Module):
"""
CvtLayer composed by attention layers, normalization and multi-layer perceptrons (mlps).
"""
def __init__(
self,
num_heads,
embed_dim,
kernel_size,
padding_q,
padding_kv,
stride_q,
stride_kv,
qkv_proj... | class_definition | 14,389 | 16,424 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,092 |
class CvtStage(nn.Module):
def __init__(self, config, stage):
super().__init__()
self.config = config
self.stage = stage
if self.config.cls_token[self.stage]:
self.cls_token = nn.Parameter(torch.randn(1, 1, self.config.embed_dim[-1]))
self.embedding = CvtEmbeddin... | class_definition | 16,427 | 19,245 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,093 |
class CvtEncoder(nn.Module):
def __init__(self, config):
super().__init__()
self.config = config
self.stages = nn.ModuleList([])
for stage_idx in range(len(config.depth)):
self.stages.append(CvtStage(config, stage_idx))
def forward(self, pixel_values, output_hidden_s... | class_definition | 19,248 | 20,268 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,094 |
class CvtPreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = CvtConfig
base_model_prefix = "cvt"
main_input_name = "pixel_values"
_no_split_modules = ["CvtLayer"... | class_definition | 20,271 | 21,335 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,095 |
class CvtModel(CvtPreTrainedModel):
def __init__(self, config, add_pooling_layer=True):
super().__init__(config)
self.config = config
self.encoder = CvtEncoder(config)
self.post_init()
def _prune_heads(self, heads_to_prune):
"""
Prunes heads of the model. heads_t... | class_definition | 22,715 | 24,677 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,096 |
class CvtForImageClassification(CvtPreTrainedModel):
def __init__(self, config):
super().__init__(config)
self.num_labels = config.num_labels
self.cvt = CvtModel(config, add_pooling_layer=False)
self.layernorm = nn.LayerNorm(config.embed_dim[-1])
# Classifier head
se... | class_definition | 24,906 | 28,703 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cvt/modeling_cvt.py | null | 8,097 |
class CpmTokenizer(PreTrainedTokenizer):
"""Runs pre-tokenization with Jieba segmentation tool. It is used in CPM models."""
vocab_files_names = VOCAB_FILES_NAMES
def __init__(
self,
vocab_file,
do_lower_case=False,
remove_space=True,
keep_accents=False,
bos... | class_definition | 1,020 | 15,026 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpm/tokenization_cpm.py | null | 8,098 |
class CpmTokenizerFast(PreTrainedTokenizerFast):
"""Runs pre-tokenization with Jieba segmentation tool. It is used in CPM models."""
def __init__(
self,
vocab_file=None,
tokenizer_file=None,
do_lower_case=False,
remove_space=True,
keep_accents=False,
bos_... | class_definition | 988 | 10,425 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpm/tokenization_cpm_fast.py | null | 8,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.