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 TFLEDModel(TFLEDPreTrainedModel):
def __init__(self, config, *inputs, **kwargs):
super().__init__(config, *inputs, **kwargs)
self.led = TFLEDMainLayer(config, name="led")
def get_encoder(self):
return self.led.encoder
def get_decoder(self):
return self.led.decoder
... | class_definition | 108,760 | 112,548 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py | null | 4,300 |
class BiasLayer(keras.layers.Layer):
"""
Bias as a layer. It is used for serialization purposes: `keras.Model.save_weights` stores on a per-layer basis,
so all weights have to be registered in a layer.
"""
def __init__(self, shape, initializer, trainable, name, **kwargs):
super().__init__(n... | class_definition | 112,617 | 113,423 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py | null | 4,301 |
class TFLEDForConditionalGeneration(TFLEDPreTrainedModel):
_keys_to_ignore_on_load_unexpected = [
r"led.encoder.embed_tokens.weight",
r"led.decoder.embed_tokens.weight",
]
def __init__(self, config, *inputs, **kwargs):
super().__init__(config, *inputs, **kwargs)
self.led = T... | class_definition | 113,559 | 123,069 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py | null | 4,302 |
class LEDConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`LEDModel`]. It is used to instantiate an LED
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configu... | class_definition | 859 | 7,418 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/configuration_led.py | null | 4,303 |
class LEDTokenizerFast(PreTrainedTokenizerFast):
r"""
Construct a "fast" LED tokenizer (backed by HuggingFace's *tokenizers* library), derived from the GPT-2 tokenizer,
using byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiec... | class_definition | 1,201 | 14,156 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/tokenization_led_fast.py | null | 4,304 |
class LEDTokenizer(PreTrainedTokenizer):
"""
Constructs a LED tokenizer, which is smilar to the ROBERTa tokenizer, using byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will
be encoded differently whether it is... | class_definition | 2,630 | 19,835 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/tokenization_led.py | null | 4,305 |
class LEDLearnedPositionalEmbedding(nn.Embedding):
"""
This module learns positional embeddings up to a fixed maximum size.
"""
def __init__(self, num_embeddings: int, embedding_dim: int):
super().__init__(num_embeddings, embedding_dim)
def forward(self, input_ids_shape: torch.Size, past_k... | class_definition | 3,006 | 3,662 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,306 |
class LEDEncoderSelfAttention(nn.Module):
def __init__(self, config, layer_id):
super().__init__()
if config.hidden_size % config.num_attention_heads != 0:
raise ValueError(
f"The hidden size ({config.hidden_size}) is not a multiple of the number of attention "
... | class_definition | 3,782 | 33,455 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,307 |
class LEDEncoderAttention(nn.Module):
def __init__(self, config, layer_id):
super().__init__()
self.longformer_self_attn = LEDEncoderSelfAttention(config, layer_id=layer_id)
self.output = nn.Linear(config.d_model, config.d_model)
def forward(
self,
hidden_states: torch.T... | class_definition | 33,458 | 34,745 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,308 |
class LEDDecoderAttention(nn.Module):
"""Multi-headed attention from 'Attention Is All You Need' paper"""
def __init__(
self,
embed_dim: int,
num_heads: int,
dropout: float = 0.0,
is_decoder: bool = False,
bias: bool = True,
):
super().__init__()
... | class_definition | 34,748 | 41,454 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,309 |
class LEDEncoderLayer(nn.Module):
def __init__(self, config: LEDConfig, layer_id: int):
super().__init__()
self.embed_dim = config.d_model
self.self_attn = LEDEncoderAttention(config, layer_id)
self.self_attn_layer_norm = nn.LayerNorm(self.embed_dim)
self.dropout = config.dro... | class_definition | 41,457 | 44,353 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,310 |
class LEDDecoderLayer(nn.Module):
def __init__(self, config: LEDConfig):
super().__init__()
self.embed_dim = config.d_model
self.self_attn = LEDDecoderAttention(
embed_dim=self.embed_dim,
num_heads=config.decoder_attention_heads,
dropout=config.attention_... | class_definition | 44,356 | 50,020 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,311 |
class LEDClassificationHead(nn.Module):
"""Head for sentence-level classification tasks."""
def __init__(
self,
input_dim: int,
inner_dim: int,
num_classes: int,
pooler_dropout: float,
):
super().__init__()
self.dense = nn.Linear(input_dim, inner_dim)... | class_definition | 50,023 | 50,792 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,312 |
class LEDPreTrainedModel(PreTrainedModel):
config_class = LEDConfig
base_model_prefix = "led"
supports_gradient_checkpointing = True
def _init_weights(self, module):
std = self.config.init_std
if isinstance(module, nn.Linear):
module.weight.data.normal_(mean=0.0, std=std)
... | class_definition | 50,795 | 51,749 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,313 |
class LEDEncoderBaseModelOutput(ModelOutput):
"""
Base class for LEDEncoder's outputs, with potential hidden states, local and global attentions.
Args:
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
Sequence of hidden-states at the output ... | class_definition | 51,882 | 55,124 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,314 |
class LEDSeq2SeqModelOutput(ModelOutput):
"""
Base class for model encoder's outputs that also contains : pre-computed hidden states that can speed up sequential
decoding.
Args:
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
Sequence o... | class_definition | 55,138 | 59,967 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,315 |
class LEDSeq2SeqLMOutput(ModelOutput):
"""
Base class for sequence-to-sequence language models outputs.
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
Language modeling loss.
logits (`torch.FloatTensor` of shape `(batch_size, se... | class_definition | 59,981 | 64,766 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,316 |
class LEDSeq2SeqSequenceClassifierOutput(ModelOutput):
"""
Base class for outputs of sequence-to-sequence sentence classification models.
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `label` is provided):
Classification (or regression if config.num_labels==... | class_definition | 64,780 | 69,599 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,317 |
class LEDSeq2SeqQuestionAnsweringModelOutput(ModelOutput):
"""
Base class for outputs of sequence-to-sequence question answering models.
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
Total span extraction loss is the sum of a Cross-Ent... | class_definition | 69,613 | 74,597 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,318 |
class LEDEncoder(LEDPreTrainedModel):
"""
Transformer encoder consisting of *config.encoder_layers* self-attention layers. Each layer is a
[`LEDEncoderLayer`].
Args:
config: LEDConfig
embed_tokens (nn.Embedding): output embedding
"""
def __init__(self, config: LEDConfig, embed_... | class_definition | 85,249 | 99,546 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,319 |
class LEDDecoder(LEDPreTrainedModel):
"""
Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`LEDDecoderLayer`]
Args:
config: LEDConfig
embed_tokens (nn.Embedding): output embedding
"""
def __init__(self, config: LEDConfig, embed_tokens: Optional[nn.... | class_definition | 99,549 | 113,040 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,320 |
class LEDModel(LEDPreTrainedModel):
_tied_weights_keys = ["decoder.embed_tokens.weight", "encoder.embed_tokens.weight"]
def __init__(self, config: LEDConfig):
super().__init__(config)
padding_idx, vocab_size = config.pad_token_id, config.vocab_size
self.shared = nn.Embedding(vocab_size... | class_definition | 113,182 | 118,771 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,321 |
class LEDForConditionalGeneration(LEDPreTrainedModel, GenerationMixin):
base_model_prefix = "led"
_keys_to_ignore_on_load_missing = ["final_logits_bias"]
_tied_weights_keys = ["decoder.embed_tokens.weight", "encoder.embed_tokens.weight", "lm_head.weight"]
def __init__(self, config: LEDConfig):
... | class_definition | 118,902 | 125,995 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,322 |
class LEDForSequenceClassification(LEDPreTrainedModel):
_tied_weights_keys = ["decoder.embed_tokens.weight", "encoder.embed_tokens.weight"]
def __init__(self, config: LEDConfig, **kwargs):
warnings.warn(
"The `transformers.LEDForSequenceClassification` class is deprecated and will be remove... | class_definition | 126,192 | 132,165 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,323 |
class LEDForQuestionAnswering(LEDPreTrainedModel):
_tied_weights_keys = ["decoder.embed_tokens.weight", "encoder.embed_tokens.weight"]
def __init__(self, config):
super().__init__(config)
config.num_labels = 2
self.num_labels = config.num_labels
self.led = LEDModel(config)
... | class_definition | 132,449 | 138,016 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_led.py | null | 4,324 |
class OlmoConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`OlmoModel`]. It is used to instantiate an OLMo
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar conf... | class_definition | 1,086 | 8,809 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/configuration_olmo.py | null | 4,325 |
class OlmoLayerNorm(nn.Module):
"""LayerNorm but with no learnable weight or bias."""
def __init__(self, hidden_size: int) -> None:
super().__init__()
self.normalized_shape = (hidden_size,)
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
orig_dtype = hidden_states.d... | class_definition | 1,719 | 2,192 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,326 |
class OlmoMLP(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 | 2,195 | 2,862 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,327 |
class OlmoAttention(nn.Module):
"""Multi-headed attention from 'Attention Is All You Need' paper"""
def __init__(self, config: OlmoConfig, layer_idx: int):
super().__init__()
self.config = config
self.layer_idx = layer_idx
self.head_dim = getattr(config, "head_dim", config.hidde... | class_definition | 6,141 | 10,080 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,328 |
class OlmoDecoderLayer(nn.Module):
def __init__(self, config: OlmoConfig, layer_idx: int):
super().__init__()
self.hidden_size = config.hidden_size
self.self_attn = OlmoAttention(config=config, layer_idx=layer_idx)
self.mlp = OlmoMLP(config)
self.input_layernorm = OlmoLayerN... | class_definition | 10,083 | 12,100 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,329 |
class OlmoRotaryEmbedding(nn.Module):
def __init__(self, config: OlmoConfig, 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", conf... | class_definition | 12,103 | 15,296 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,330 |
class OlmoPreTrainedModel(PreTrainedModel):
config_class = OlmoConfig
base_model_prefix = "model"
supports_gradient_checkpointing = True
_no_split_modules = ["OlmoDecoderLayer"]
_skip_keys_device_placement = ["past_key_values"]
_supports_flash_attn_2 = True
_supports_sdpa = True
_support... | class_definition | 16,314 | 17,234 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,331 |
class OlmoModel(OlmoPreTrainedModel):
"""
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`OlmoDecoderLayer`]
Args:
config: OlmoConfig
"""
def __init__(self, config: OlmoConfig):
super().__init__(config)
self.padding_idx = config.pad_to... | class_definition | 22,035 | 33,228 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,332 |
class KwargsForCausalLM(FlashAttentionKwargs, LossKwargs): ... | class_definition | 33,231 | 33,293 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,333 |
class OlmoForCausalLM(OlmoPreTrainedModel, GenerationMixin):
_tied_weights_keys = ["lm_head.weight"]
_tp_plan = {"lm_head": "colwise_rep"}
def __init__(self, config):
super().__init__(config)
self.model = OlmoModel(config)
self.vocab_size = config.vocab_size
self.lm_head = n... | class_definition | 33,296 | 38,413 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modeling_olmo.py | null | 4,334 |
class OlmoLayerNorm(nn.Module):
"""LayerNorm but with no learnable weight or bias."""
def __init__(self, hidden_size: int) -> None:
super().__init__()
self.normalized_shape = (hidden_size,)
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
orig_dtype = hidden_states.d... | class_definition | 534 | 1,007 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modular_olmo.py | null | 4,335 |
class OlmoMLP(LlamaMLP):
def __init__(self, config):
super().__init__(config)
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
self.down_proj = nn.Linear(self.intermediate_s... | class_definition | 1,010 | 1,364 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modular_olmo.py | null | 4,336 |
class OlmoAttention(LlamaAttention):
def forward(
self,
hidden_states: torch.Tensor,
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
attention_mask: Optional[torch.Tensor],
past_key_value: Optional[Cache] = None,
cache_position: Optional[torch.LongTensor] = No... | class_definition | 1,367 | 4,175 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modular_olmo.py | null | 4,337 |
class OlmoDecoderLayer(LlamaDecoderLayer):
def __init__(self, config: OlmoConfig, layer_idx: int):
super().__init__(config, layer_idx)
self.input_layernorm = OlmoLayerNorm(config.hidden_size)
self.post_attention_layernorm = OlmoLayerNorm(config.hidden_size)
self.self_attn = OlmoAtten... | class_definition | 4,178 | 4,538 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modular_olmo.py | null | 4,338 |
class OlmoModel(LlamaModel):
def __init__(self, config: OlmoConfig):
super().__init__(config)
self.layers = nn.ModuleList(
[OlmoDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
)
self.norm = OlmoLayerNorm(config.hidden_size) | class_definition | 4,541 | 4,846 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modular_olmo.py | null | 4,339 |
class OlmoForCausalLM(LlamaForCausalLM):
pass | class_definition | 4,849 | 4,898 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/olmo/modular_olmo.py | null | 4,340 |
class ChameleonRMSNorm(nn.Module):
def __init__(self, hidden_size, eps=1e-6):
"""
ChameleonRMSNorm 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 | 2,121 | 2,849 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,341 |
class ChameleonRotaryEmbedding(nn.Module):
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
super().__init__()
self.scaling_factor = scaling_factor
self.dim = dim
self.max_position_embeddings = max_position_embeddings
self.ba... | class_definition | 3,032 | 4,556 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,342 |
class ChameleonLinearScalingRotaryEmbedding(ChameleonRotaryEmbedding):
"""ChameleonRotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
def forward(self, x, position_ids):
# difference to the original RoPE: a scaling factor is aplied to the position ids
posi... | class_definition | 4,559 | 5,008 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,343 |
class ChameleonDynamicNTKScalingRotaryEmbedding(ChameleonRotaryEmbedding):
"""ChameleonRotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
def forward(self, x, position_ids):
# difference to the original RoPE: inv_freq is recomputed when the seque... | class_definition | 5,011 | 5,988 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,344 |
class ChameleonMLP(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 | 7,945 | 8,665 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,345 |
class ChameleonLayerNorm(nn.LayerNorm):
"""
LayerNorm but computes stats only over the last dim because Chameleon applies gamma and beta
from each shard separately to each head, instead of reducing. We can apply each head's own
gamma/beta by repeat-interleaving weights from each shard, but the stats hav... | class_definition | 8,668 | 9,498 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,346 |
class ChameleonAttention(nn.Module):
"""Multi-headed attention from 'Attention Is All You Need' paper"""
def __init__(self, config: ChameleonConfig, layer_idx: Optional[int] = None):
super().__init__()
self.config = config
self.layer_idx = layer_idx
if layer_idx is None:
... | class_definition | 10,175 | 16,706 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,347 |
class ChameleonFlashAttention2(ChameleonAttention):
"""
Chameleon flash attention module. This module inherits from `ChameleonAttention` 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 public API of
flash attention ... | class_definition | 16,857 | 22,723 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,348 |
class ChameleonSdpaAttention(ChameleonAttention):
"""
Chameleon attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
`ChameleonAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
SDPA API.
"""
... | class_definition | 22,726 | 27,478 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,349 |
class ChameleonDecoderLayer(nn.Module):
def __init__(self, config: ChameleonConfig, layer_idx: int):
super().__init__()
self.hidden_size = config.hidden_size
self.self_attn = CHAMELEON_ATTENTION_CLASSES[config._attn_implementation](config=config, layer_idx=layer_idx)
self.mlp = Cha... | class_definition | 27,784 | 31,103 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,350 |
class ChameleonSwinDecoderLayer(nn.Module):
def __init__(self, config: ChameleonConfig, layer_idx: int):
super().__init__()
self.hidden_size = config.hidden_size
self.self_attn = CHAMELEON_ATTENTION_CLASSES[config._attn_implementation](config=config, layer_idx=layer_idx)
self.mlp =... | class_definition | 31,106 | 34,468 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,351 |
class ChameleonVQVAEVectorQuantizer(nn.Module):
"""
A module for vector quantization using learned embedding vectors.
This module implements the quantization process similar to te one described in
the VQ-VAE (Vector Quantized Variational AutoEncoder) paper. It quantizes continuous
input vectors int... | class_definition | 34,471 | 36,567 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,352 |
class ChameleonVQVAEEncoderConvDownsample(nn.Module):
def __init__(self, in_channels):
super().__init__()
self.conv = nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=2, padding=0)
def forward(self, hidden_states):
# no asymmetric padding in torch conv, must do it ourselves
... | class_definition | 36,570 | 37,053 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,353 |
class ChameleonVQVAEEncoderResnetBlock(nn.Module):
def __init__(
self,
config,
in_channels,
out_channels=None,
conv_shortcut=False,
):
super().__init__()
self.in_channels = in_channels
self.out_channels = in_channels if out_channels is None else ou... | class_definition | 37,056 | 38,931 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,354 |
class ChameleonVQVAEEncoderAttnBlock(nn.Module):
def __init__(self, in_channels):
super().__init__()
self.in_channels = in_channels
self.norm = torch.nn.GroupNorm(num_groups=32, num_channels=in_channels, eps=1e-6, affine=True)
self.q = torch.nn.Conv2d(in_channels, in_channels, kerne... | class_definition | 38,934 | 40,634 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,355 |
class ChameleonVQVAEEncoder(nn.Module):
def __init__(self, config):
super().__init__()
self.num_resolutions = len(config.channel_multiplier)
self.num_res_blocks = config.num_res_blocks
base_channels = config.base_channels
resolution = config.resolution
in_channels = ... | class_definition | 40,637 | 44,593 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,356 |
class ChameleonImageVocabularyMapping:
"""
A class for mapping discrete image tokens from VQGAN to BPE tokens.
"""
def __init__(self, vocab_map):
self.vocab_map = vocab_map
self.image_token_id = vocab_map.get("<image>")
@cached_property
def val2name(self):
return {v: k ... | class_definition | 44,596 | 46,147 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,357 |
class ChameleonPreTrainedModel(PreTrainedModel):
config_class = ChameleonConfig
base_model_prefix = "model"
supports_gradient_checkpointing = True
_no_split_modules = ["ChameleonDecoderLayer", "ChameleonSwinDecoderLayer"]
_skip_keys_device_placement = ["past_key_values", "causal_mask"]
_supports... | class_definition | 47,185 | 48,288 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,358 |
class ChameleonVQVAE(ChameleonPreTrainedModel):
config_class = ChameleonVQVAEConfig
_no_split_modules = ["ChameleonVQVAEVectorQuantizer"]
def _init_weights(self, module):
std = self.config.initializer_range
if isinstance(module, nn.Embedding):
module.weight.data.normal_(mean=0.0... | class_definition | 49,580 | 50,934 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,359 |
class ChameleonModel(ChameleonPreTrainedModel):
"""
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`ChameleonDecoderLayer`]
Args:
config: ChameleonConfig
"""
def __init__(self, config: ChameleonConfig):
super().__init__(config)
self.pa... | class_definition | 55,510 | 69,178 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,360 |
class ChameleonForConditionalGeneration(ChameleonPreTrainedModel, GenerationMixin):
_tied_weights_keys = ["lm_head.weight"]
def __init__(self, config):
super().__init__(config)
self.model = ChameleonModel(config)
self.vocab_size = config.vocab_size
self.lm_head = nn.Linear(confi... | class_definition | 69,333 | 77,630 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/modeling_chameleon.py | null | 4,361 |
class ChameleonImageProcessor(BaseImageProcessor):
r"""
Constructs a Chameleon image processor.
Args:
do_resize (`bool`, *optional*, defaults to `True`):
Whether to resize the image's (height, width) dimensions to the specified `size`. Can be overridden by
`do_resize` in the... | class_definition | 2,118 | 17,500 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/image_processing_chameleon.py | null | 4,362 |
class ChameleonVQVAEConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`ChameleonVQModel`]. It is used to instantiate a
`ChameleonVQModel` according to the specified arguments, defining the model architecture.
Configuration objects inherit from [`PretrainedCo... | class_definition | 825 | 4,107 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/configuration_chameleon.py | null | 4,363 |
class ChameleonConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`ChameleonModel`]. It is used to instantiate a
chameleon model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield ... | class_definition | 4,110 | 13,236 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/configuration_chameleon.py | null | 4,364 |
class ChameleonTextKwargs(TextKwargs, total=False):
return_for_text_completion: bool | class_definition | 1,003 | 1,091 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/processing_chameleon.py | null | 4,365 |
class ChameleonProcessorKwargs(ProcessingKwargs, total=False):
text_kwargs: ChameleonTextKwargs
_defaults = {
"text_kwargs": {
"padding": False,
"return_for_text_completion": False,
},
"common_kwargs": {
"return_tensors": "pt",
},
} | class_definition | 1,094 | 1,406 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/processing_chameleon.py | null | 4,366 |
class ChameleonProcessor(ProcessorMixin):
r"""
Constructs a Chameleon processor which wraps a Chameleon image processor and a Chameleon tokenizer into a single
processor.
[`ChameleonProcessor`] offers all the functionalities of [`ChameleonImageProcessor`] and [`LlamaTokenizerFast`].
See the [`~Cham... | class_definition | 1,409 | 8,461 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/chameleon/processing_chameleon.py | null | 4,367 |
class LongT5Config(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`LongT5Model`] or a [`FlaxLongT5Model`]. It is
used to instantiate a LongT5 model according to the specified arguments, defining the model architecture.
Instantiating a configuration with the defa... | class_definition | 850 | 7,091 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/configuration_longt5.py | null | 4,368 |
class LongT5OnnxConfig(OnnxSeq2SeqConfigWithPast):
@property
def inputs(self) -> Mapping[str, Mapping[int, str]]:
common_inputs = {
"input_ids": {0: "batch", 1: "encoder_sequence"},
"attention_mask": {0: "batch", 1: "encoder_sequence"},
}
if self.use_past:
... | class_definition | 7,094 | 8,057 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/configuration_longt5.py | null | 4,369 |
class LongT5LayerNorm(nn.Module):
def __init__(self, hidden_size, eps=1e-6):
"""
Construct a layernorm module in the LongT5 style. No bias and no subtraction of mean.
"""
super().__init__()
self.weight = nn.Parameter(torch.ones(hidden_size))
self.variance_epsilon = ep... | class_definition | 10,142 | 11,247 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,370 |
class LongT5DenseActDense(nn.Module):
def __init__(self, config: LongT5Config):
super().__init__()
self.wi = nn.Linear(config.d_model, config.d_ff, bias=False)
self.wo = nn.Linear(config.d_ff, config.d_model, bias=False)
self.dropout = nn.Dropout(config.dropout_rate)
self.act... | class_definition | 11,768 | 12,635 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,371 |
class LongT5DenseGatedActDense(nn.Module):
def __init__(self, config: LongT5Config):
super().__init__()
self.wi_0 = nn.Linear(config.d_model, config.d_ff, bias=False)
self.wi_1 = nn.Linear(config.d_model, config.d_ff, bias=False)
self.wo = nn.Linear(config.d_ff, config.d_model, bias=... | class_definition | 12,638 | 13,391 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,372 |
class LongT5LayerFF(nn.Module):
def __init__(self, config: LongT5Config):
super().__init__()
if config.is_gated_act:
self.DenseReluDense = LongT5DenseGatedActDense(config)
else:
self.DenseReluDense = LongT5DenseActDense(config)
self.layer_norm = LongT5LayerNo... | class_definition | 13,469 | 14,155 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,373 |
class LongT5Attention(nn.Module):
def __init__(
self,
config: LongT5Config,
has_relative_attention_bias=False,
layer_idx: Optional[int] = None,
):
super().__init__()
self.is_decoder = config.is_decoder
self.has_relative_attention_bias = has_relative_attent... | class_definition | 14,235 | 25,475 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,374 |
class LongT5LocalAttention(nn.Module):
def __init__(self, config: LongT5Config, has_relative_attention_bias: bool = False) -> None:
super().__init__()
self.is_decoder = config.is_decoder
self.has_relative_attention_bias = has_relative_attention_bias
self.relative_attention_num_bucket... | class_definition | 25,478 | 34,803 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,375 |
class LongT5TransientGlobalAttention(nn.Module):
def __init__(self, config: LongT5Config, has_relative_attention_bias: bool = False) -> None:
super().__init__()
self.is_decoder = config.is_decoder
self.has_relative_attention_bias = has_relative_attention_bias
self.relative_attention_... | class_definition | 34,806 | 48,442 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,376 |
class LongT5LayerSelfAttention(nn.Module):
def __init__(self, config, has_relative_attention_bias=False, layer_idx: Optional[int] = None):
super().__init__()
self.SelfAttention = LongT5Attention(
config, has_relative_attention_bias=has_relative_attention_bias, layer_idx=layer_idx
... | class_definition | 48,531 | 49,893 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,377 |
class LongT5LayerLocalSelfAttention(nn.Module):
"""Local self attention used in encoder"""
def __init__(self, config, has_relative_attention_bias=False, layer_idx: Optional[int] = None):
super().__init__()
self.LocalSelfAttention = LongT5LocalAttention(config, has_relative_attention_bias=has_re... | class_definition | 49,896 | 51,153 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,378 |
class LongT5LayerTransientGlobalSelfAttention(nn.Module):
"""Transient-Global self attention used in encoder"""
def __init__(self, config, has_relative_attention_bias=False, layer_idx: Optional[int] = None):
super().__init__()
self.TransientGlobalSelfAttention = LongT5TransientGlobalAttention(
... | class_definition | 51,156 | 52,486 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,379 |
class LongT5LayerCrossAttention(nn.Module):
def __init__(self, config, layer_idx: Optional[int] = None):
super().__init__()
self.EncDecAttention = LongT5Attention(config, has_relative_attention_bias=False, layer_idx=layer_idx)
self.layer_norm = LongT5LayerNorm(config.d_model, eps=config.laye... | class_definition | 52,576 | 54,001 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,380 |
class LongT5Block(nn.Module):
def __init__(self, config, has_relative_attention_bias=False, layer_idx: Optional[int] = None):
super().__init__()
self.is_decoder = config.is_decoder
if config.is_decoder:
attention_layer = LongT5LayerSelfAttention
elif config.encoder_attent... | class_definition | 54,004 | 58,622 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,381 |
class LongT5PreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = LongT5Config
base_model_prefix = "transformer"
supports_gradient_checkpointing = True
_no_split_m... | class_definition | 58,625 | 64,418 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,382 |
class LongT5Stack(LongT5PreTrainedModel):
def __init__(self, config, embed_tokens=None):
super().__init__(config)
self.embed_tokens = nn.Embedding(config.vocab_size, config.d_model)
if embed_tokens is not None:
self.embed_tokens.weight = embed_tokens.weight
self.is_decod... | class_definition | 64,421 | 81,875 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,383 |
class LongT5Model(LongT5PreTrainedModel):
_keys_to_ignore_on_load_unexpected = [
r"decoder.block.0.layer.1.EncDecAttention.relative_attention_bias.weight",
]
_tied_weights_keys = ["encoder.embed_tokens.weight", "decoder.embed_tokens.weight"]
def __init__(self, config: LongT5Config):
sup... | class_definition | 92,531 | 99,216 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,384 |
class LongT5ForConditionalGeneration(LongT5PreTrainedModel, GenerationMixin):
_keys_to_ignore_on_load_unexpected = [
r"decoder.block.0.layer.1.EncDecAttention.relative_attention_bias.weight",
]
_tied_weights_keys = ["encoder.embed_tokens.weight", "decoder.embed_tokens.weight", "lm_head.weight"]
... | class_definition | 99,325 | 108,950 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,385 |
class LongT5EncoderModel(LongT5PreTrainedModel):
_tied_weights_keys = ["encoder.embed_tokens.weight"]
_keys_to_ignore_on_load_unexpected = [r"decoder"]
def __init__(self, config: LongT5Config):
super().__init__(config)
self.shared = nn.Embedding(config.vocab_size, config.d_model)
e... | class_definition | 109,120 | 112,190 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_longt5.py | null | 4,386 |
class FlaxLongT5LayerNorm(nn.Module):
hidden_size: int
dtype: jnp.dtype = jnp.float32
eps: float = 1e-6
weight_init: Callable[..., np.ndarray] = jax.nn.initializers.ones
def setup(self):
self.weight = self.param("weight", self.weight_init, (self.hidden_size,))
def __call__(self, hidden... | class_definition | 9,380 | 10,090 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,387 |
class FlaxLongT5DenseActDense(nn.Module):
config: LongT5Config
dtype: jnp.dtype = jnp.float32
def setup(self):
wi_init_std = self.config.initializer_factor * (self.config.d_model**-0.5)
wo_init_std = self.config.initializer_factor * (self.config.d_ff**-0.5)
self.wi = nn.Dense(
... | class_definition | 10,183 | 11,279 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,388 |
class FlaxLongT5DenseGatedActDense(nn.Module):
config: LongT5Config
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
wi_init_std = self.config.initializer_factor * (self.config.d_model**-0.5)
wo_init_std = self.config.initializer_factor * (self.config.d_ff**-0... | class_definition | 11,377 | 12,763 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,389 |
class FlaxLongT5LayerFF(nn.Module):
config: LongT5Config
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
if self.config.is_gated_act:
self.DenseReluDense = FlaxLongT5DenseGatedActDense(self.config, dtype=self.dtype)
else:
self.DenseRel... | class_definition | 12,850 | 13,778 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,390 |
class FlaxLongT5Attention(nn.Module):
config: LongT5Config
has_relative_attention_bias: bool = False
causal: bool = False
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.relative_attention_num_buckets = self.config.relative_attention_num_buckets
... | class_definition | 13,867 | 26,937 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,391 |
class FlaxLongT5LocalAttention(nn.Module):
config: LongT5Config
has_relative_attention_bias: bool = False
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.relative_attention_num_buckets = self.config.relative_attention_num_buckets
self.relative_attent... | class_definition | 26,940 | 36,133 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,392 |
class FlaxLongT5TransientGlobalAttention(nn.Module):
config: LongT5Config
has_relative_attention_bias: bool = False
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.relative_attention_num_buckets = self.config.relative_attention_num_buckets
self.relat... | class_definition | 36,136 | 49,672 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,393 |
class FlaxLongT5LayerLocalSelfAttention(nn.Module):
"""Local self attention used in encoder"""
config: LongT5Config
has_relative_attention_bias: bool = False
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.LocalSelfAttention = FlaxLongT5LocalAttention(
... | class_definition | 49,675 | 51,098 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,394 |
class FlaxLongT5LayerTransientGlobalSelfAttention(nn.Module):
"""Transient-Global self attention used in encoder"""
config: LongT5Config
has_relative_attention_bias: bool = False
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.TransientGlobalSelfAttenti... | class_definition | 51,101 | 52,575 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,395 |
class FlaxLongT5LayerSelfAttention(nn.Module):
config: LongT5Config
has_relative_attention_bias: bool = False
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.SelfAttention = FlaxLongT5Attention(
self.config,
has_relative_attention_bia... | class_definition | 52,673 | 54,099 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,396 |
class FlaxLongT5LayerCrossAttention(nn.Module):
config: LongT5Config
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.EncDecAttention = FlaxLongT5Attention(
self.config, has_relative_attention_bias=False, causal=False, dtype=self.dtype
)
... | class_definition | 54,198 | 55,477 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,397 |
class FlaxLongT5Block(nn.Module):
config: LongT5Config
has_relative_attention_bias: bool = False
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.causal = self.config.causal
if self.causal:
attention_layer = FlaxLongT5LayerSelfAttention
... | class_definition | 55,480 | 58,857 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,398 |
class FlaxLongT5LayerCollection(nn.Module):
config: LongT5Config
has_relative_attention_bias: bool
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.layer = FlaxLongT5Block(
self.config, has_relative_attention_bias=self.has_relative_attention_bias,... | class_definition | 58,952 | 60,085 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/longt5/modeling_flax_longt5.py | null | 4,399 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.