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 MvpForCausalLM(MvpPreTrainedModel, GenerationMixin):
_tied_weights_keys = ["lm_head.weight"]
def __init__(self, config):
config = copy.deepcopy(config)
config.is_decoder = True
config.is_encoder_decoder = False
super().__init__(config)
self.model = MvpDecoderWrappe... | class_definition | 81,057 | 90,257 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mvp/modeling_mvp.py | null | 4,100 |
class MvpTokenizerFast(PreTrainedTokenizerFast):
r"""
Construct a "fast" MVP 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,161 | 11,798 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mvp/tokenization_mvp_fast.py | null | 4,101 |
class MvpConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`MvpModel`]. It is used to instantiate a MVP model
according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configur... | class_definition | 821 | 8,408 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mvp/configuration_mvp.py | null | 4,102 |
class MvpTokenizer(PreTrainedTokenizer):
"""
Constructs a MVP 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,330 | 16,191 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mvp/tokenization_mvp.py | null | 4,103 |
class PvtV2Config(BackboneConfigMixin, PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`PvtV2Model`]. It is used to instantiate a Pvt V2
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults w... | class_definition | 1,051 | 7,962 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/configuration_pvt_v2.py | null | 4,104 |
class PvtV2DropPath(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 | 3,016 | 3,495 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,105 |
class PvtV2OverlapPatchEmbeddings(nn.Module):
"""Image to Patch Embedding"""
def __init__(self, config: PvtV2Config, layer_idx: int):
super().__init__()
patch_size = config.patch_sizes[layer_idx]
patch_size = (patch_size, patch_size) if isinstance(patch_size, int) else patch_size
... | class_definition | 3,498 | 4,620 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,106 |
class PvtV2DepthWiseConv(nn.Module):
"""
Depth-wise (DW) convolution to infuse positional information using zero-padding. Depth-wise convolutions
have an equal number of groups to the number of input channels, meaning one filter per input channel. This
reduces the overall parameters and compute costs si... | class_definition | 4,623 | 5,533 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,107 |
class PvtV2SelfAttention(nn.Module):
"""Efficient self-attention mechanism."""
def __init__(self, config: PvtV2Config, hidden_size: int, num_attention_heads: int, spatial_reduction_ratio: int):
super().__init__()
self.linear_attention = config.linear_attention
self.pruned_heads = set()
... | class_definition | 5,536 | 10,740 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,108 |
class PvtV2ConvFeedForwardNetwork(nn.Module):
def __init__(
self,
config: PvtV2Config,
in_features: int,
hidden_features: Optional[int] = None,
out_features: Optional[int] = None,
):
super().__init__()
out_features = out_features if out_features is not Non... | class_definition | 10,743 | 12,091 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,109 |
class PvtV2BlockLayer(nn.Module):
def __init__(self, config: PvtV2Config, layer_idx: int, drop_path: float = 0.0):
super().__init__()
hidden_size: int = config.hidden_sizes[layer_idx]
num_attention_heads: int = config.num_attention_heads[layer_idx]
spatial_reduction_ratio: int = conf... | class_definition | 12,094 | 13,946 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,110 |
class PvtV2EncoderLayer(nn.Module):
def __init__(self, config: PvtV2Config, layer_idx: int):
super().__init__()
self.patch_embedding = PvtV2OverlapPatchEmbeddings(
config=config,
layer_idx=layer_idx,
)
# Transformer block
# stochastic depth decay rule
... | class_definition | 13,949 | 15,668 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,111 |
class PvtV2Encoder(nn.Module):
def __init__(self, config: PvtV2Config):
super().__init__()
self.config = config
self.gradient_checkpointing = False
# encoder layers
self.layers = nn.ModuleList([PvtV2EncoderLayer(config, i) for i in range(config.num_encoder_blocks)])
def... | class_definition | 15,671 | 17,577 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,112 |
class PvtV2PreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = PvtV2Config
base_model_prefix = "pvt_v2"
main_input_name = "pixel_values"
supports_gradient_checkp... | class_definition | 17,580 | 18,882 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,113 |
class PvtV2Model(PvtV2PreTrainedModel):
def __init__(self, config: PvtV2Config):
super().__init__(config)
self.config = config
# hierarchical Transformer encoder
self.encoder = PvtV2Encoder(config)
# Initialize weights and apply final processing
self.post_init()
... | class_definition | 20,465 | 22,643 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,114 |
class PvtV2ForImageClassification(PvtV2PreTrainedModel):
def __init__(self, config: PvtV2Config) -> None:
super().__init__(config)
self.num_labels = config.num_labels
self.pvt_v2 = PvtV2Model(config)
# Classifier head
self.classifier = (
nn.Linear(config.hidden_... | class_definition | 22,878 | 26,773 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,115 |
class PvtV2Backbone(PvtV2Model, BackboneMixin):
def __init__(self, config: PvtV2Config):
super().__init__(config)
super()._init_backbone(config)
self.num_features = config.hidden_sizes
@add_start_docstrings_to_model_forward(PVT_V2_INPUTS_DOCSTRING)
@replace_return_docstrings(output_... | class_definition | 26,919 | 29,416 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/pvt_v2/modeling_pvt_v2.py | null | 4,116 |
class DonutSwinConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`DonutSwinModel`]. It is used to instantiate a
Donut model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a si... | class_definition | 799 | 5,752 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/configuration_donut_swin.py | null | 4,117 |
class DonutSwinEncoderOutput(ModelOutput):
"""
DonutSwin 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 ... | class_definition | 1,701 | 3,676 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,118 |
class DonutSwinModelOutput(ModelOutput):
"""
DonutSwin 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 o... | class_definition | 3,780 | 6,019 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,119 |
class DonutSwinEmbeddings(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 = DonutSwinPatchEmbeddings(config)
num_patches = self.patch_emb... | class_definition | 7,117 | 11,036 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,120 |
class DonutSwinPatchEmbeddings(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 | 11,133 | 13,318 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,121 |
class DonutSwinPatchMerging(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`):
Normaliza... | class_definition | 13,391 | 15,674 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,122 |
class DonutSwinDropPath(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) -> ... | class_definition | 16,898 | 17,381 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,123 |
class DonutSwinSelfAttention(nn.Module):
def __init__(self, config, dim, num_heads, window_size):
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_heads})"
)
... | class_definition | 17,476 | 22,353 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,124 |
class DonutSwinSelfOutput(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:
h... | class_definition | 22,424 | 22,866 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,125 |
class DonutSwinAttention(nn.Module):
def __init__(self, config, dim, num_heads, window_size):
super().__init__()
self.self = DonutSwinSelfAttention(config, dim, num_heads, window_size)
self.output = DonutSwinSelfOutput(config, dim)
self.pruned_heads = set()
def prune_heads(self,... | class_definition | 22,957 | 24,650 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,126 |
class DonutSwinIntermediate(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.intermed... | class_definition | 24,723 | 25,286 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,127 |
class DonutSwinOutput(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 = se... | class_definition | 25,353 | 25,777 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,128 |
class DonutSwinLayer(nn.Module):
def __init__(self, config, dim, input_resolution, num_heads, drop_path_rate=0.0, shift_size=0):
super().__init__()
self.chunk_size_feed_forward = config.chunk_size_feed_forward
self.shift_size = shift_size
self.window_size = config.window_size
... | class_definition | 25,864 | 31,557 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,129 |
class DonutSwinStage(nn.Module):
def __init__(self, config, dim, input_resolution, depth, num_heads, drop_path, downsample):
super().__init__()
self.config = config
self.dim = dim
self.blocks = nn.ModuleList(
[
DonutSwinLayer(
config=co... | class_definition | 31,644 | 33,868 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,130 |
class DonutSwinEncoder(nn.Module):
def __init__(self, config, grid_size):
super().__init__()
self.num_layers = len(config.depths)
self.config = config
dpr = [x.item() for x in torch.linspace(0, config.drop_path_rate, sum(config.depths))]
self.layers = nn.ModuleList(
... | class_definition | 33,957 | 38,719 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,131 |
class DonutSwinPreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = DonutSwinConfig
base_model_prefix = "swin"
main_input_name = "pixel_values"
supports_gradient_... | class_definition | 38,816 | 39,782 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,132 |
class DonutSwinModel(DonutSwinPreTrainedModel):
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))
... | class_definition | 41,845 | 45,891 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/modeling_donut_swin.py | null | 4,133 |
class DonutFeatureExtractor(DonutImageProcessor):
def __init__(self, *args, **kwargs) -> None:
warnings.warn(
"The class DonutFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"
" use DonutImageProcessor instead.",
FutureWarning,
... | class_definition | 812 | 1,178 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/feature_extraction_donut.py | null | 4,134 |
class DonutProcessorKwargs(ProcessingKwargs, total=False):
_defaults = {} | class_definition | 957 | 1,034 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/processing_donut.py | null | 4,135 |
class DonutProcessor(ProcessorMixin):
r"""
Constructs a Donut processor which wraps a Donut image processor and an XLMRoBERTa tokenizer into a single
processor.
[`DonutProcessor`] offers all the functionalities of [`DonutImageProcessor`] and
[`XLMRobertaTokenizer`/`XLMRobertaTokenizerFast`]. See th... | class_definition | 1,077 | 9,663 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/processing_donut.py | null | 4,136 |
class DonutImageProcessor(BaseImageProcessor):
r"""
Constructs a Donut 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 `prepro... | class_definition | 1,480 | 21,758 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/donut/image_processing_donut.py | null | 4,137 |
class SamVisionEncoderOutput(ModelOutput):
"""
Base class for sam vision model's outputs that also contains image embeddings obtained by applying the projection
layer to the pooler_output.
Args:
image_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)` *optional* returned when model... | class_definition | 1,368 | 3,183 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,138 |
class SamImageSegmentationOutput(ModelOutput):
"""
Base class for Segment-Anything model's output
Args:
iou_scores (`torch.FloatTensor` of shape `(batch_size, num_masks)`):
The iou scores of the predicted masks.
pred_masks (`torch.FloatTensor` of shape `(batch_size, num_masks, h... | class_definition | 3,197 | 5,333 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,139 |
class SamPatchEmbeddings(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 | 5,336 | 7,054 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,140 |
class SamMLPBlock(nn.Module):
def __init__(self, config):
super().__init__()
self.lin1 = nn.Linear(config.hidden_size, config.mlp_dim)
self.lin2 = nn.Linear(config.mlp_dim, config.hidden_size)
self.act = ACT2FN[config.hidden_act]
def forward(self, hidden_states: torch.Tensor) ->... | class_definition | 7,057 | 7,566 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,141 |
class SamLayerNorm(nn.Module):
r"""LayerNorm that supports two data formats: channels_last (default) or channels_first.
The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height,
width, channels) while channels_first corresponds to inputs with shape (ba... | class_definition | 7,667 | 9,138 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,142 |
class SamAttention(nn.Module):
"""
SAM's attention layer that allows for downscaling the size of the embedding after projection to queries, keys, and
values.
"""
def __init__(self, config, downsample_rate=None):
super().__init__()
self.hidden_size = config.hidden_size
downs... | class_definition | 9,141 | 11,888 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,143 |
class SamSdpaAttention(SamAttention):
"""
SAM's attention layer that allows for downscaling the size of the embedding after projection to queries, keys, and
values. Using SDPA instead of the default attention.
"""
def __init__(self, config, downsample_rate=None):
super().__init__(config, do... | class_definition | 11,891 | 13,180 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,144 |
class SamTwoWayAttentionBlock(nn.Module):
def __init__(self, config, attention_downsample_rate: int = 2, skip_first_layer_pe: bool = False):
"""
A transformer block with four layers:
(1) self-attention of sparse inputs (2) cross attention of sparse inputs -> dense inputs (3) mlp block on... | class_definition | 13,270 | 16,798 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,145 |
class SamTwoWayTransformer(nn.Module):
def __init__(self, config: SamMaskDecoderConfig):
super().__init__()
self.config = config
self.num_hidden_layers = config.num_hidden_layers
self.layers = nn.ModuleList()
for i in range(self.num_hidden_layers):
self.layers.a... | class_definition | 16,801 | 19,576 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,146 |
class SamFeedForward(nn.Module):
def __init__(
self, input_dim: int, hidden_dim: int, output_dim: int, num_layers: int, sigmoid_output: bool = False
):
super().__init__()
self.num_layers = num_layers
self.activation = nn.ReLU()
self.proj_in = nn.Linear(input_dim, hidden_d... | class_definition | 19,579 | 20,523 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,147 |
class SamMaskDecoder(nn.Module):
def __init__(self, config: SamMaskDecoderConfig):
super().__init__()
self.config = config
self.hidden_size = config.hidden_size
self.num_multimask_outputs = config.num_multimask_outputs
self.num_mask_tokens = config.num_multimask_outputs + 1
... | class_definition | 20,526 | 26,191 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,148 |
class SamPositionalEmbedding(nn.Module):
def __init__(self, config):
super().__init__()
self.scale = config.hidden_size // 2
self.register_buffer("positional_embedding", self.scale * torch.randn((2, config.num_pos_feats)))
def forward(self, input_coords, input_shape=None):
"""Po... | class_definition | 26,194 | 27,247 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,149 |
class SamMaskEmbedding(nn.Module):
def __init__(self, config: SamPromptEncoderConfig):
super().__init__()
self.mask_input_channels = config.mask_input_channels // 4
self.activation = ACT2FN[config.hidden_act]
self.conv1 = nn.Conv2d(1, self.mask_input_channels, kernel_size=2, stride=2... | class_definition | 27,250 | 28,500 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,150 |
class SamPromptEncoder(nn.Module):
def __init__(self, config: SamPromptEncoderConfig, shared_patch_embedding):
super().__init__()
self.shared_embedding = shared_patch_embedding
self.mask_embed = SamMaskEmbedding(config)
self.no_mask_embed = nn.Embedding(1, config.hidden_size)
... | class_definition | 28,503 | 33,604 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,151 |
class SamVisionAttention(nn.Module):
"""Multi-head Attention block with relative position embeddings."""
def __init__(self, config, window_size):
super().__init__()
input_size = (
(config.image_size // config.patch_size, config.image_size // config.patch_size)
if window_... | class_definition | 33,607 | 39,710 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,152 |
class SamVisionSdpaAttention(SamVisionAttention):
"""
Multi-head Attention block with relative position embeddings.
Using SDPA instead of the default attention.
"""
def __init__(self, config, window_size):
super().__init__(config, window_size)
def add_decomposed_rel_pos(
self,
... | class_definition | 39,713 | 44,476 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,153 |
class SamVisionLayer(nn.Module):
def __init__(self, config, window_size):
super().__init__()
self.layer_norm1 = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
self.attn = SAM_VISION_ATTENTION_CLASSES[config._attn_implementation](config, window_size)
self.layer_norm2 = nn... | class_definition | 44,585 | 48,772 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,154 |
class SamVisionNeck(nn.Module):
def __init__(self, config: SamVisionConfig):
super().__init__()
self.config = config
self.conv1 = nn.Conv2d(config.hidden_size, config.output_channels, kernel_size=1, bias=False)
self.layer_norm1 = SamLayerNorm(config.output_channels, data_format="cha... | class_definition | 48,775 | 49,658 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,155 |
class SamVisionEncoder(nn.Module):
def __init__(self, config: SamVisionConfig):
super().__init__()
self.config = config
self.image_size = config.image_size
self.patch_embed = SamPatchEmbeddings(config)
self.pos_embed = None
if config.use_abs_pos:
# Initi... | class_definition | 49,661 | 53,093 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,156 |
class SamPreTrainedModel(PreTrainedModel):
config_class = SamConfig
base_model_prefix = "sam"
main_input_name = "pixel_values"
_no_split_modules = ["SamVisionAttention"]
supports_gradient_checkpointing = True
_supports_sdpa = True
def _init_weights(self, module):
std = self.config.i... | class_definition | 53,096 | 53,861 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,157 |
class SamModel(SamPreTrainedModel):
_tied_weights_keys = ["prompt_encoder.shared_embedding.positional_embedding"]
def __init__(self, config):
super().__init__(config)
self.shared_image_embedding = SamPositionalEmbedding(config.vision_config)
self.vision_encoder = SamVisionEncoder(confi... | class_definition | 60,247 | 71,276 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_sam.py | null | 4,158 |
class SamImagesKwargs(ImagesKwargs):
segmentation_maps: Optional[ImageInput]
input_points: Optional[List[List[float]]]
input_labels: Optional[List[List[int]]]
input_boxes: Optional[List[List[List[float]]]]
point_pad_value: Optional[int] | class_definition | 1,105 | 1,361 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/processing_sam.py | null | 4,159 |
class SamProcessorKwargs(ProcessingKwargs, total=False):
images_kwargs: SamImagesKwargs
_defaults = {
"images_kwargs": {
"point_pad_value": -10,
}
} | class_definition | 1,364 | 1,552 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/processing_sam.py | null | 4,160 |
class SamProcessor(ProcessorMixin):
r"""
Constructs a SAM processor which wraps a SAM image processor and an 2D points & Bounding boxes processor into a
single processor.
[`SamProcessor`] offers all the functionalities of [`SamImageProcessor`]. See the docstring of
[`~SamImageProcessor.__call__`] f... | class_definition | 1,555 | 12,900 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/processing_sam.py | null | 4,161 |
class SamImageProcessor(BaseImageProcessor):
r"""
Constructs a SAM 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 the
`do_resize` parameter in t... | class_definition | 1,853 | 48,363 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/image_processing_sam.py | null | 4,162 |
class TFSamVisionEncoderOutput(ModelOutput):
"""
Base class for sam vision model's outputs that also contains image embeddings obtained by applying the projection
layer to the pooler_output.
Args:
image_embeds (`tf.Tensor` of shape `(batch_size, output_dim)` *optional* returned when model is in... | class_definition | 1,610 | 3,338 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,163 |
class TFSamImageSegmentationOutput(ModelOutput):
"""
Base class for Segment-Anything model's output
Args:
iou_scores (`tf.Tensor` of shape `(batch_size, num_masks)`):
The iou scores of the predicted masks.
pred_masks (`tf.Tensor` of shape `(batch_size, num_masks, height, width)`... | class_definition | 3,352 | 5,377 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,164 |
class TFSamPatchEmbeddings(keras.layers.Layer):
"""
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, c... | class_definition | 5,380 | 7,478 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,165 |
class TFSamMLPBlock(keras.layers.Layer):
def __init__(self, config, **kwargs):
super().__init__(**kwargs)
self.lin1 = keras.layers.Dense(config.mlp_dim, name="lin1")
self.lin2 = keras.layers.Dense(config.hidden_size, name="lin2")
self.act = ACT2FN[config.hidden_act]
self.conf... | class_definition | 7,481 | 8,493 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,166 |
class TFSamLayerNorm(keras.layers.Layer):
r"""LayerNorm that supports two data formats: channels_last (default) or channels_first.
The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height,
width, channels) while channels_first corresponds to inputs wit... | class_definition | 8,496 | 9,906 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,167 |
class TFSamAttention(keras.layers.Layer):
"""
SAM's attention layer that allows for downscaling the size of the embedding after projection to queries, keys, and
values.
"""
def __init__(self, config, downsample_rate=None, **kwargs):
super().__init__(**kwargs)
self.hidden_size = conf... | class_definition | 9,909 | 13,566 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,168 |
class TFSamTwoWayAttentionBlock(keras.layers.Layer):
def __init__(self, config, attention_downsample_rate: int = 2, skip_first_layer_pe: bool = False, **kwargs):
"""
A transformer block with four layers:
(1) self-attention of sparse inputs (2) cross attention of sparse inputs -> dense in... | class_definition | 13,569 | 18,687 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,169 |
class TFSamTwoWayTransformer(keras.layers.Layer):
def __init__(self, config: SamMaskDecoderConfig, **kwargs):
super().__init__(**kwargs)
self.config = config
self.num_hidden_layers = config.num_hidden_layers
self.layers = []
for i in range(self.num_hidden_layers):
... | class_definition | 18,690 | 22,039 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,170 |
class TFSamFeedForward(keras.layers.Layer):
def __init__(
self, input_dim: int, hidden_dim: int, output_dim: int, num_layers: int, sigmoid_output: bool = False, **kwargs
):
super().__init__(**kwargs)
self.num_layers = num_layers
self.activation = keras.layers.ReLU()
self.... | class_definition | 22,042 | 23,898 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,171 |
class TFSamMaskDecoder(keras.layers.Layer):
def __init__(self, config: SamMaskDecoderConfig, **kwargs):
super().__init__(**kwargs)
self.hidden_size = config.hidden_size
self.num_multimask_outputs = config.num_multimask_outputs
self.num_mask_tokens = config.num_multimask_outputs + 1... | class_definition | 23,901 | 30,466 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,172 |
class TFSamPositionalEmbedding(keras.layers.Layer):
def __init__(self, config, **kwargs):
super().__init__(**kwargs)
self.scale = config.hidden_size // 2
self.config = config
def build(self, input_shape):
# TODO Matt: What is going on here? Why is a non-trainable weight randomly... | class_definition | 30,469 | 32,042 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,173 |
class TFSamMaskEmbedding(keras.layers.Layer):
def __init__(self, config: SamPromptEncoderConfig, **kwargs):
super().__init__(**kwargs)
self.mask_input_channels = config.mask_input_channels // 4
self.activation = ACT2FN[config.hidden_act]
self.conv1 = keras.layers.Conv2D(self.mask_inp... | class_definition | 32,045 | 34,277 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,174 |
class TFSamPromptEncoder(keras.layers.Layer):
def __init__(self, config: SamPromptEncoderConfig, shared_patch_embedding, **kwargs):
super().__init__(**kwargs)
self.shared_embedding = shared_patch_embedding
self.mask_embed = TFSamMaskEmbedding(config, name="mask_embed")
self.no_mask_e... | class_definition | 34,280 | 40,585 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,175 |
class TFSamVisionAttention(keras.layers.Layer):
"""Multi-head Attention block with relative position embeddings."""
def __init__(self, config, window_size, **kwargs):
super().__init__(**kwargs)
input_size = (
(config.image_size // config.patch_size, config.image_size // config.patch... | class_definition | 40,588 | 47,825 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,176 |
class TFSamVisionLayer(keras.layers.Layer):
def __init__(self, config, window_size, **kwargs):
super().__init__(**kwargs)
self.layer_norm1 = keras.layers.LayerNormalization(epsilon=config.layer_norm_eps, name="layer_norm1")
self.attn = TFSamVisionAttention(config, window_size, name="attn")
... | class_definition | 47,828 | 51,974 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,177 |
class TFSamVisionNeck(keras.layers.Layer):
def __init__(self, config: SamVisionConfig, **kwargs):
super().__init__(**kwargs)
self.config = config
self.conv1 = keras.layers.Conv2D(
config.output_channels,
kernel_size=1,
use_bias=False,
name="co... | class_definition | 51,977 | 53,820 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,178 |
class TFSamVisionEncoder(keras.layers.Layer):
def __init__(self, config: SamVisionConfig, **kwargs):
super().__init__(**kwargs)
self.config = config
self.image_size = config.image_size
self.patch_embed = TFSamPatchEmbeddings(config, name="patch_embed")
self.pos_embed = None... | class_definition | 53,823 | 57,757 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,179 |
class TFSamPreTrainedModel(TFPreTrainedModel):
config_class = SamConfig
base_model_prefix = "sam"
main_input_name = "pixel_values" | class_definition | 57,760 | 57,902 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,180 |
class TFSamModel(TFSamPreTrainedModel):
_keys_to_ignore_on_load_missing = [r"prompt_encoder.shared_embedding.positional_embedding"]
def __init__(self, config, **kwargs):
super().__init__(config, **kwargs)
self.shared_image_embedding = TFSamPositionalEmbedding(config.vision_config, name="shared_... | class_definition | 63,666 | 75,449 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/modeling_tf_sam.py | null | 4,181 |
class SamPromptEncoderConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`SamPromptEncoder`]. The [`SamPromptEncoder`]
module is used to encode the input 2D points and bounding boxes. Instantiating a configuration defaults will yield
a similar configuration t... | class_definition | 780 | 2,835 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/configuration_sam.py | null | 4,182 |
class SamMaskDecoderConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`SamMaskDecoder`]. It is used to instantiate a SAM
mask decoder to the specified arguments, defining the model architecture. Instantiating a configuration defaults
will yield a similar con... | class_definition | 2,838 | 5,792 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/configuration_sam.py | null | 4,183 |
class SamVisionConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`SamVisionModel`]. It is used to instantiate a SAM
vision encoder according to the specified arguments, defining the model architecture. Instantiating a configuration
defaults will yield a simi... | class_definition | 5,795 | 10,448 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/configuration_sam.py | null | 4,184 |
class SamConfig(PretrainedConfig):
r"""
[`SamConfig`] is the configuration class to store the configuration of a [`SamModel`]. It is used to instantiate a
SAM model according to the specified arguments, defining the vision model, prompt-encoder model and mask decoder
configs. Instantiating a configurati... | class_definition | 10,451 | 14,069 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/sam/configuration_sam.py | null | 4,185 |
class MptAttention(nn.Module):
"""Multi-head self attention.
Using torch or triton attention implemetation enables user to also use additive bias.
"""
def __init__(self, config: MptConfig):
super().__init__()
self.hidden_size = config.hidden_size
self.n_heads = config.n_heads
... | class_definition | 2,710 | 6,303 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,186 |
class MptMLP(nn.Module):
def __init__(self, config: MptConfig):
super().__init__()
hidden_size = config.hidden_size
self.up_proj = nn.Linear(hidden_size, 4 * hidden_size, bias=False)
self.act = nn.GELU(approximate="none")
self.down_proj = nn.Linear(4 * hidden_size, hidden_si... | class_definition | 6,306 | 7,071 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,187 |
class MptBlock(nn.Module):
def __init__(self, config: MptConfig):
super().__init__()
hidden_size = config.hidden_size
self.norm_1 = LayerNorm(hidden_size, eps=config.layer_norm_epsilon)
# backward compatibility with weights on the Hub
self.norm_1.bias = None
self.nu... | class_definition | 7,074 | 9,029 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,188 |
class MptPreTrainedModel(PreTrainedModel):
config_class = MptConfig
base_model_prefix = "transformer"
supports_gradient_checkpointing = True
_no_split_modules = ["MptBlock"]
_keys_to_ignore_on_load_missing = [r"lm_head.*."]
def __init__(self, *inputs, **kwargs):
super().__init__(*inputs... | class_definition | 9,032 | 11,177 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,189 |
class MptModel(MptPreTrainedModel):
def __init__(self, config: MptConfig):
super().__init__(config)
self.hidden_size = config.hidden_size
self.num_heads = config.n_heads
# Embedding + LN Embedding
self.wte = nn.Embedding(config.vocab_size, self.hidden_size)
# Trans... | class_definition | 15,195 | 21,277 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,190 |
class MptForCausalLM(MptPreTrainedModel, GenerationMixin):
_tied_weights_keys = ["lm_head.weight"]
def __init__(self, config: MptConfig):
super().__init__(config)
self.transformer = MptModel(config)
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
# I... | class_definition | 21,476 | 26,061 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,191 |
class MptForSequenceClassification(MptPreTrainedModel):
def __init__(self, config: MptConfig):
super().__init__(config)
self.num_labels = config.num_labels
self.transformer = MptModel(config)
self.score = nn.Linear(config.hidden_size, config.num_labels, bias=False)
# Initial... | class_definition | 26,848 | 31,832 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,192 |
class MptForTokenClassification(MptPreTrainedModel):
def __init__(self, config: MptConfig):
super().__init__(config)
self.num_labels = config.num_labels
self.transformer = MptModel(config)
if hasattr(config, "classifier_dropout") and config.classifier_dropout is not None:
... | class_definition | 32,059 | 35,491 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,193 |
class MptForQuestionAnswering(MptPreTrainedModel):
def __init__(self, config):
super().__init__(config)
self.transformer = MptModel(config)
self.qa_outputs = nn.Linear(config.hidden_size, 2)
# Initialize weights and apply final processing
self.post_init()
@add_start_doc... | class_definition | 35,792 | 39,486 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/modeling_mpt.py | null | 4,194 |
class MptAttentionConfig(PretrainedConfig):
"""
This is the configuration class to store the configuration of a [`MptAttention`] class. It is used to instantiate
attention layers according to the specified arguments, defining the layers architecture. Instantiating a
configuration with the defaults will ... | class_definition | 851 | 4,618 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/configuration_mpt.py | null | 4,195 |
class MptConfig(PretrainedConfig):
"""
This is the configuration class to store the configuration of a [`MptModel`]. It is used to instantiate a Mpt model
according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configura... | class_definition | 4,621 | 10,516 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mpt/configuration_mpt.py | null | 4,196 |
class Wav2Vec2PhonemeCTCTokenizerOutput(ModelOutput):
"""
Output type of [` Wav2Vec2PhonemeCTCTokenizer`], with transcription.
Args:
text (list of `str` or `str`):
Decoded logits in text from. Usually the speech transcription.
char_offsets (list of `List[Dict[str, Union[int, str... | class_definition | 1,600 | 2,327 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/wav2vec2_phoneme/tokenization_wav2vec2_phoneme.py | null | 4,197 |
class Wav2Vec2PhonemeCTCTokenizer(PreTrainedTokenizer):
"""
Constructs a Wav2Vec2PhonemeCTC tokenizer.
This tokenizer inherits from [`PreTrainedTokenizer`] which contains some of the main methods. Users should refer to
the superclass for more information regarding such methods.
Args:
vocab... | class_definition | 2,330 | 23,160 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/wav2vec2_phoneme/tokenization_wav2vec2_phoneme.py | null | 4,198 |
class MaskFormerFeatureExtractor(MaskFormerImageProcessor):
def __init__(self, *args, **kwargs) -> None:
warnings.warn(
"The class MaskFormerFeatureExtractor is deprecated and will be removed in version 5 of Transformers."
" Please use MaskFormerImageProcessor instead.",
... | class_definition | 827 | 1,213 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/feature_extraction_maskformer.py | null | 4,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.