mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-03 21:00:08 +06:00
Fix unnecessary super calls (#38897)
Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
parent
b949747b54
commit
0a53df1a77
@ -135,7 +135,7 @@ class BitGroupNormActivation(nn.GroupNorm):
|
||||
"""
|
||||
|
||||
def __init__(self, config, num_channels, eps=1e-5, affine=True, apply_activation=True):
|
||||
super(BitGroupNormActivation, self).__init__(config.num_groups, num_channels, eps=eps, affine=affine)
|
||||
super().__init__(config.num_groups, num_channels, eps=eps, affine=affine)
|
||||
if apply_activation:
|
||||
self.activation = ACT2FN[config.hidden_act]
|
||||
else:
|
||||
|
@ -1183,7 +1183,7 @@ class BlenderbotModel(BlenderbotPreTrainedModel):
|
||||
)
|
||||
return BlenderbotSmallModel.from_pretrained(pretrained_model_name_or_path)
|
||||
|
||||
return super(BlenderbotModel, cls).from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
|
||||
return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
|
||||
|
||||
def get_input_embeddings(self):
|
||||
return self.shared
|
||||
@ -1344,9 +1344,7 @@ class BlenderbotForConditionalGeneration(BlenderbotPreTrainedModel, GenerationMi
|
||||
)
|
||||
return BlenderbotSmallForConditionalGeneration.from_pretrained(pretrained_model_name_or_path)
|
||||
|
||||
return super(BlenderbotForConditionalGeneration, cls).from_pretrained(
|
||||
pretrained_model_name_or_path, *model_args, **kwargs
|
||||
)
|
||||
return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
|
||||
|
||||
def get_encoder(self):
|
||||
return self.model.get_encoder()
|
||||
|
@ -74,7 +74,7 @@ class BrosPositionalEmbedding1D(nn.Module):
|
||||
# Reference: https://github.com/kimiyoung/transformer-xl/blob/master/pytorch/mem_transformer.py#L15
|
||||
|
||||
def __init__(self, config):
|
||||
super(BrosPositionalEmbedding1D, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.dim_bbox_sinusoid_emb_1d = config.dim_bbox_sinusoid_emb_1d
|
||||
|
||||
@ -93,7 +93,7 @@ class BrosPositionalEmbedding1D(nn.Module):
|
||||
|
||||
class BrosPositionalEmbedding2D(nn.Module):
|
||||
def __init__(self, config):
|
||||
super(BrosPositionalEmbedding2D, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.dim_bbox = config.dim_bbox
|
||||
self.x_pos_emb = BrosPositionalEmbedding1D(config)
|
||||
@ -112,7 +112,7 @@ class BrosPositionalEmbedding2D(nn.Module):
|
||||
|
||||
class BrosBboxEmbeddings(nn.Module):
|
||||
def __init__(self, config):
|
||||
super(BrosBboxEmbeddings, self).__init__()
|
||||
super().__init__()
|
||||
self.bbox_sinusoid_emb = BrosPositionalEmbedding2D(config)
|
||||
self.bbox_projection = nn.Linear(config.dim_bbox_sinusoid_emb_2d, config.dim_bbox_projection, bias=False)
|
||||
|
||||
|
@ -1229,7 +1229,7 @@ class Data2VecAudioForAudioFrameClassification(Data2VecAudioPreTrainedModel):
|
||||
|
||||
class AMSoftmaxLoss(nn.Module):
|
||||
def __init__(self, input_dim, num_labels, scale=30.0, margin=0.4):
|
||||
super(AMSoftmaxLoss, self).__init__()
|
||||
super().__init__()
|
||||
self.scale = scale
|
||||
self.margin = margin
|
||||
self.num_labels = num_labels
|
||||
|
@ -484,7 +484,7 @@ ERNIE_M_INPUTS_DOCSTRING = r"""
|
||||
)
|
||||
class ErnieMModel(ErnieMPreTrainedModel):
|
||||
def __init__(self, config, add_pooling_layer=True):
|
||||
super(ErnieMModel, self).__init__(config)
|
||||
super().__init__(config)
|
||||
self.initializer_range = config.initializer_range
|
||||
self.embeddings = ErnieMEmbeddings(config)
|
||||
self.encoder = ErnieMEncoder(config)
|
||||
@ -964,7 +964,7 @@ class ErnieMForQuestionAnswering(ErnieMPreTrainedModel):
|
||||
)
|
||||
class ErnieMForInformationExtraction(ErnieMPreTrainedModel):
|
||||
def __init__(self, config):
|
||||
super(ErnieMForInformationExtraction, self).__init__(config)
|
||||
super().__init__(config)
|
||||
self.ernie_m = ErnieMModel(config)
|
||||
self.linear_start = nn.Linear(config.hidden_size, 1)
|
||||
self.linear_end = nn.Linear(config.hidden_size, 1)
|
||||
|
@ -324,7 +324,7 @@ class GraniteMoeMoE(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config: GraniteMoeConfig):
|
||||
super(GraniteMoeMoE, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.input_size = config.hidden_size
|
||||
self.hidden_size = config.intermediate_size
|
||||
|
@ -856,7 +856,7 @@ class GraniteMoeHybridMLP(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config: GraniteMoeHybridConfig):
|
||||
super(GraniteMoeHybridMLP, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.input_size = config.hidden_size
|
||||
self.hidden_size = config.shared_intermediate_size
|
||||
@ -995,7 +995,7 @@ class GraniteMoeHybridMoE(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config: GraniteMoeHybridConfig):
|
||||
super(GraniteMoeHybridMoE, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.input_size = config.hidden_size
|
||||
self.hidden_size = config.intermediate_size
|
||||
|
@ -56,7 +56,7 @@ class GraniteMoeSharedMLP(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config: GraniteMoeSharedConfig):
|
||||
super(GraniteMoeSharedMLP, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.input_size = config.hidden_size
|
||||
self.hidden_size = config.shared_intermediate_size
|
||||
@ -195,7 +195,7 @@ class GraniteMoeSharedMoE(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config: GraniteMoeSharedConfig):
|
||||
super(GraniteMoeSharedMoE, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.input_size = config.hidden_size
|
||||
self.hidden_size = config.intermediate_size
|
||||
|
@ -43,7 +43,7 @@ class GraniteMoeSharedMLP(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config: GraniteMoeSharedConfig):
|
||||
super(GraniteMoeSharedMLP, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.input_size = config.hidden_size
|
||||
self.hidden_size = config.shared_intermediate_size
|
||||
|
@ -233,7 +233,7 @@ class JetMoeMoE(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config: JetMoeConfig):
|
||||
super(JetMoeMoE, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.input_size = config.hidden_size
|
||||
self.hidden_size = config.intermediate_size
|
||||
@ -291,7 +291,7 @@ class JetMoeMoA(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config: JetMoeConfig):
|
||||
super(JetMoeMoA, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
self.num_experts = config.num_local_experts
|
||||
self.input_size = config.hidden_size
|
||||
|
@ -47,7 +47,7 @@ class LayoutLMEmbeddings(nn.Module):
|
||||
"""Construct the embeddings from word, position and token_type embeddings."""
|
||||
|
||||
def __init__(self, config):
|
||||
super(LayoutLMEmbeddings, self).__init__()
|
||||
super().__init__()
|
||||
self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id)
|
||||
self.position_embeddings = nn.Embedding(config.max_position_embeddings, config.hidden_size)
|
||||
self.x_position_embeddings = nn.Embedding(config.max_2d_position_embeddings, config.hidden_size)
|
||||
@ -635,7 +635,7 @@ class LayoutLMPreTrainedModel(PreTrainedModel):
|
||||
@auto_docstring
|
||||
class LayoutLMModel(LayoutLMPreTrainedModel):
|
||||
def __init__(self, config):
|
||||
super(LayoutLMModel, self).__init__(config)
|
||||
super().__init__(config)
|
||||
self.config = config
|
||||
|
||||
self.embeddings = LayoutLMEmbeddings(config)
|
||||
|
@ -52,7 +52,7 @@ class LayoutLMv2Embeddings(nn.Module):
|
||||
"""Construct the embeddings from word, position and token_type embeddings."""
|
||||
|
||||
def __init__(self, config):
|
||||
super(LayoutLMv2Embeddings, self).__init__()
|
||||
super().__init__()
|
||||
self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id)
|
||||
self.position_embeddings = nn.Embedding(config.max_position_embeddings, config.hidden_size)
|
||||
|
||||
|
@ -648,7 +648,7 @@ class LxmertEncoder(nn.Module):
|
||||
|
||||
class LxmertPooler(nn.Module):
|
||||
def __init__(self, config):
|
||||
super(LxmertPooler, self).__init__()
|
||||
super().__init__()
|
||||
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
||||
self.activation = nn.Tanh()
|
||||
|
||||
@ -663,7 +663,7 @@ class LxmertPooler(nn.Module):
|
||||
|
||||
class LxmertPredictionHeadTransform(nn.Module):
|
||||
def __init__(self, config):
|
||||
super(LxmertPredictionHeadTransform, self).__init__()
|
||||
super().__init__()
|
||||
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
||||
self.transform_act_fn = ACT2FN[config.hidden_act]
|
||||
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=1e-12)
|
||||
@ -677,7 +677,7 @@ class LxmertPredictionHeadTransform(nn.Module):
|
||||
|
||||
class LxmertLMPredictionHead(nn.Module):
|
||||
def __init__(self, config, lxmert_model_embedding_weights):
|
||||
super(LxmertLMPredictionHead, self).__init__()
|
||||
super().__init__()
|
||||
self.transform = LxmertPredictionHeadTransform(config)
|
||||
|
||||
# The output weights are the same as the input embeddings, but there is
|
||||
@ -744,7 +744,7 @@ class LxmertVisualObjHead(nn.Module):
|
||||
|
||||
class LxmertPreTrainingHeads(nn.Module):
|
||||
def __init__(self, config, lxmert_model_embedding_weights):
|
||||
super(LxmertPreTrainingHeads, self).__init__()
|
||||
super().__init__()
|
||||
self.predictions = LxmertLMPredictionHead(config, lxmert_model_embedding_weights)
|
||||
self.seq_relationship = nn.Linear(config.hidden_size, 2)
|
||||
|
||||
|
@ -52,7 +52,7 @@ class XPathEmbeddings(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
super(XPathEmbeddings, self).__init__()
|
||||
super().__init__()
|
||||
self.max_depth = config.max_depth
|
||||
|
||||
self.xpath_unitseq2_embeddings = nn.Linear(config.xpath_unit_hidden_size * self.max_depth, config.hidden_size)
|
||||
@ -116,7 +116,7 @@ class MarkupLMEmbeddings(nn.Module):
|
||||
"""Construct the embeddings from word, position and token_type embeddings."""
|
||||
|
||||
def __init__(self, config):
|
||||
super(MarkupLMEmbeddings, self).__init__()
|
||||
super().__init__()
|
||||
self.config = config
|
||||
self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id)
|
||||
self.position_embeddings = nn.Embedding(config.max_position_embeddings, config.hidden_size)
|
||||
@ -724,9 +724,7 @@ class MarkupLMPreTrainedModel(PreTrainedModel):
|
||||
|
||||
@classmethod
|
||||
def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.PathLike]], *model_args, **kwargs):
|
||||
return super(MarkupLMPreTrainedModel, cls).from_pretrained(
|
||||
pretrained_model_name_or_path, *model_args, **kwargs
|
||||
)
|
||||
return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
|
||||
|
||||
|
||||
@auto_docstring
|
||||
|
@ -2533,7 +2533,7 @@ class Conv2dSamePadding(nn.Conv2d):
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Conv2dSamePadding, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.zero_pad_2d = nn.ZeroPad2d(
|
||||
reduce(__add__, [(k // 2 + (k - 2 * (k // 2)) - 1, k // 2) for k in self.kernel_size[::-1]])
|
||||
)
|
||||
|
@ -77,7 +77,7 @@ class Conv1dSubsampler(nn.Module):
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
super(Conv1dSubsampler, self).__init__()
|
||||
super().__init__()
|
||||
self.config = config
|
||||
self.num_layers = config.num_conv_layers
|
||||
self.in_channels = config.input_feat_per_channel * config.input_channels
|
||||
|
@ -476,7 +476,7 @@ class TFSwinDropPath(keras.layers.Layer):
|
||||
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks)."""
|
||||
|
||||
def __init__(self, drop_prob: Optional[float] = None, scale_by_keep: bool = True, **kwargs) -> None:
|
||||
super(TFSwinDropPath, self).__init__(**kwargs)
|
||||
super().__init__(**kwargs)
|
||||
self.drop_prob = drop_prob
|
||||
self.scale_by_keep = scale_by_keep
|
||||
|
||||
|
@ -1871,7 +1871,7 @@ class ProductIndexMap(IndexMap):
|
||||
if outer_index.batch_dims != inner_index.batch_dims:
|
||||
raise ValueError("outer_index.batch_dims and inner_index.batch_dims must be the same.")
|
||||
|
||||
super(ProductIndexMap, self).__init__(
|
||||
super().__init__(
|
||||
indices=(
|
||||
inner_index.indices
|
||||
+ outer_index.indices * tf.cast(inner_index.num_segments, inner_index.indices.dtype)
|
||||
|
@ -847,7 +847,7 @@ class UdopBlock(nn.Module):
|
||||
|
||||
class UdopCellEmbeddings(nn.Module):
|
||||
def __init__(self, max_2d_position_embeddings=501, hidden_size=1024):
|
||||
super(UdopCellEmbeddings, self).__init__()
|
||||
super().__init__()
|
||||
self.max_2d_position_embeddings = max_2d_position_embeddings
|
||||
|
||||
self.x_position_embeddings = nn.Embedding(max_2d_position_embeddings, hidden_size)
|
||||
@ -911,7 +911,7 @@ class RelativePositionBiasBase(nn.Module, ABC):
|
||||
prefix_bucket=False,
|
||||
expand=False,
|
||||
):
|
||||
super(RelativePositionBiasBase, self).__init__()
|
||||
super().__init__()
|
||||
self.prefix_bucket = prefix_bucket
|
||||
self.augmentation = augmentation
|
||||
self.level = level
|
||||
@ -1499,7 +1499,7 @@ class UdopModel(UdopPreTrainedModel):
|
||||
]
|
||||
|
||||
def __init__(self, config):
|
||||
super(UdopModel, self).__init__(config)
|
||||
super().__init__(config)
|
||||
|
||||
# text and image embeddings
|
||||
self.shared = nn.Embedding(config.vocab_size, config.d_model)
|
||||
@ -1695,7 +1695,7 @@ class UdopForConditionalGeneration(UdopPreTrainedModel, GenerationMixin):
|
||||
]
|
||||
|
||||
def __init__(self, config):
|
||||
super(UdopForConditionalGeneration, self).__init__(config)
|
||||
super().__init__(config)
|
||||
|
||||
# text and image embeddings
|
||||
self.shared = nn.Embedding(config.vocab_size, config.d_model)
|
||||
|
@ -1670,7 +1670,7 @@ class UniSpeechSatForAudioFrameClassification(UniSpeechSatPreTrainedModel):
|
||||
|
||||
class AMSoftmaxLoss(nn.Module):
|
||||
def __init__(self, input_dim, num_labels, scale=30.0, margin=0.4):
|
||||
super(AMSoftmaxLoss, self).__init__()
|
||||
super().__init__()
|
||||
self.scale = scale
|
||||
self.margin = margin
|
||||
self.num_labels = num_labels
|
||||
|
@ -2203,7 +2203,7 @@ class Wav2Vec2ForAudioFrameClassification(Wav2Vec2PreTrainedModel):
|
||||
|
||||
class AMSoftmaxLoss(nn.Module):
|
||||
def __init__(self, input_dim, num_labels, scale=30.0, margin=0.4):
|
||||
super(AMSoftmaxLoss, self).__init__()
|
||||
super().__init__()
|
||||
self.scale = scale
|
||||
self.margin = margin
|
||||
self.num_labels = num_labels
|
||||
|
@ -1358,7 +1358,7 @@ class Wav2Vec2BertForAudioFrameClassification(Wav2Vec2BertPreTrainedModel):
|
||||
|
||||
class AMSoftmaxLoss(nn.Module):
|
||||
def __init__(self, input_dim, num_labels, scale=30.0, margin=0.4):
|
||||
super(AMSoftmaxLoss, self).__init__()
|
||||
super().__init__()
|
||||
self.scale = scale
|
||||
self.margin = margin
|
||||
self.num_labels = num_labels
|
||||
|
@ -1751,7 +1751,7 @@ class Wav2Vec2ConformerForAudioFrameClassification(Wav2Vec2ConformerPreTrainedMo
|
||||
|
||||
class AMSoftmaxLoss(nn.Module):
|
||||
def __init__(self, input_dim, num_labels, scale=30.0, margin=0.4):
|
||||
super(AMSoftmaxLoss, self).__init__()
|
||||
super().__init__()
|
||||
self.scale = scale
|
||||
self.margin = margin
|
||||
self.num_labels = num_labels
|
||||
|
@ -1514,7 +1514,7 @@ class WavLMForAudioFrameClassification(WavLMPreTrainedModel):
|
||||
|
||||
class AMSoftmaxLoss(nn.Module):
|
||||
def __init__(self, input_dim, num_labels, scale=30.0, margin=0.4):
|
||||
super(AMSoftmaxLoss, self).__init__()
|
||||
super().__init__()
|
||||
self.scale = scale
|
||||
self.margin = margin
|
||||
self.num_labels = num_labels
|
||||
|
Loading…
Reference in New Issue
Block a user