MCPcopy Create free account
hub / github.com/AtlasAnalyticsLab/AdaFisher / __init__

Method __init__

Language_Model/GPT1.py:239–260  ·  view source on GitHub ↗

A decoder layer. This module combines a Multi-headed Attention module and an MLP to create a layer of the transformer, with normalization and skip-connections. See Lecture 06, slide 33.

(self, head_size, mlp_hidden_size, num_heads, sequence_length)

Source from the content-addressed store, hash-verified

237
238class Block(nn.Module):
239 def __init__(self, head_size, mlp_hidden_size, num_heads, sequence_length):
240 """A decoder layer.
241
242 This module combines a Multi-headed Attention module and an MLP to
243 create a layer of the transformer, with normalization and skip-connections.
244 See Lecture 06, slide 33.
245 """
246 super(Block, self).__init__()
247 self.head_size = head_size
248 self.mlp_hidden_size = mlp_hidden_size
249 self.num_heads = num_heads
250 self.sequence_length = sequence_length
251 self.hidden_size = num_heads * head_size
252
253 self.attention = MultiHeadedAttention(head_size, num_heads, sequence_length)
254 self.norm1 = nn.LayerNorm(self.hidden_size)
255 self.mlp = nn.Sequential(
256 nn.Linear(self.hidden_size, mlp_hidden_size),
257 nn.GELU(),
258 nn.Linear(mlp_hidden_size, self.hidden_size),
259 )
260 self.norm2 = nn.LayerNorm(self.hidden_size)
261
262 def forward(self, hidden_states):
263 attention_outputs = self.attention(hidden_states)

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 1

Tested by

no test coverage detected