When I run the script below I get the following error message: Traceback (most recent…
- User
When I run the script below I get the following error message:
Traceback (most recent call last): File "C:\Users\brook\PycharmProjects\PythonProject1\context_vectors.py", line 260, in class MultiHeadAttentionWrapper(nn.Module): ...<21 lines>... print("context_vecs.shape:", context_vecs.shape) File "C:\Users\brook\PycharmProjects\PythonProject1\context_vectors.py", line 277, in MultiHeadAttentionWrapper mha = MultiHeadAttentionWrapper( ^^^^^^^^^^^^^^^^^^^^^^^^^ NameError: name 'MultiHeadAttentionWrapper' is not defined
Process finished with exit code 1
class MultiHeadAttentionWrapper(nn.Module): def init(self, d_in, d_out, context_length, dropout, num_heads, qkv_bias=False): super().init() self.heads = nn.ModuleList( [CausalAttention( d_in, d_out, context_length, dropout, qkv_bias ) for _ in range(num_heads)] )
def forward(self, x): return torch.cat([head(x) for head in self.heads], dim=-1)
torch.manual_seed(123) context_length = batch.shape[1] # This is the number of tokens d_in, d_out = 3, 2 mha = MultiHeadAttentionWrapper( d_in, d_out, context_length, 0.0, num_heads=2 ) context_vecs = mha(batch) print(context_vecs) print("context_vecs.shape:", context_vecs.shape)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.