Created
August 9, 2019 09:25
-
-
Save thomwolf/eabef5ee63eef190d0e47e05568ca71c to your computer and use it in GitHub Desktop.
Main forward pass for GPT-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def forward(self, input_ids): | |
position_ids = torch.arange(0, input_ids.size(-1), dtype=torch.long, device=input_ids.device) | |
position_ids = position_ids.unsqueeze(0).expand_as(input_ids) | |
hidden_states = self.wte(input_ids) + self.wpe(position_ids) | |
hidden_states = self.drop(hidden_states) | |
for block in self.h: | |
hidden_states = block(hidden_states) | |
hidden_states = self.ln_f(hidden_states) | |
return hidden_states |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment