Unverified Commit 9c5ae87f authored by karthikrangasai's avatar karthikrangasai Committed by GitHub
Browse files

Type hint complete Albert model file. (#16682)



* Type hint complete Albert model file.

* Update typing.

* Update src/transformers/models/albert/modeling_albert.py
Co-authored-by: default avatarMatt <Rocketknight1@users.noreply.github.com>
parent 2bf95e2b
......@@ -203,8 +203,13 @@ class BertEmbeddings(nn.Module):
)
def forward(
self, input_ids=None, token_type_ids=None, position_ids=None, inputs_embeds=None, past_key_values_length=0
):
self,
input_ids: Optional[torch.LongTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
past_key_values_length: int = 0,
) -> torch.Tensor:
if input_ids is not None:
input_shape = input_ids.size()
else:
......@@ -266,7 +271,7 @@ class BertSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
......@@ -182,7 +182,7 @@ class Data2VecTextSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
......@@ -174,8 +174,13 @@ class ElectraEmbeddings(nn.Module):
# Copied from transformers.models.bert.modeling_bert.BertEmbeddings.forward
def forward(
self, input_ids=None, token_type_ids=None, position_ids=None, inputs_embeds=None, past_key_values_length=0
):
self,
input_ids: Optional[torch.LongTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
past_key_values_length: int = 0,
) -> torch.Tensor:
if input_ids is not None:
input_shape = input_ids.size()
else:
......@@ -238,7 +243,7 @@ class ElectraSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
......@@ -154,7 +154,7 @@ class LayoutLMSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
......@@ -212,7 +212,7 @@ class MegatronBertSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
......@@ -19,6 +19,7 @@
import math
import os
import warnings
from typing import Optional
import torch
import torch.utils.checkpoint
......@@ -173,8 +174,13 @@ class QDQBertEmbeddings(nn.Module):
)
def forward(
self, input_ids=None, token_type_ids=None, position_ids=None, inputs_embeds=None, past_key_values_length=0
):
self,
input_ids: Optional[torch.LongTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
past_key_values_length: int = 0,
) -> torch.Tensor:
if input_ids is not None:
input_shape = input_ids.size()
else:
......
......@@ -189,8 +189,13 @@ class RealmEmbeddings(nn.Module):
)
def forward(
self, input_ids=None, token_type_ids=None, position_ids=None, inputs_embeds=None, past_key_values_length=0
):
self,
input_ids: Optional[torch.LongTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
past_key_values_length: int = 0,
) -> torch.Tensor:
if input_ids is not None:
input_shape = input_ids.size()
else:
......@@ -253,7 +258,7 @@ class RealmSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
......@@ -182,7 +182,7 @@ class RobertaSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
......@@ -126,7 +126,7 @@ class SplinterSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
......@@ -176,7 +176,7 @@ class XLMRobertaXLSelfAttention(nn.Module):
self.is_decoder = config.is_decoder
def transpose_for_scores(self, x):
def transpose_for_scores(self, x: torch.Tensor) -> torch.Tensor:
new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
x = x.view(new_x_shape)
return x.permute(0, 2, 1, 3)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment