fix(package): Add PyTorch-style __call__ methods to exported modules

Resolved transformer training issues by adding __call__ methods to:
- Embedding, PositionalEncoding, EmbeddingLayer (text.embeddings)
- LayerNorm, MLP, TransformerBlock, GPT (models.transformer)
- MultiHeadAttention (core.attention)

This enables PyTorch-style syntax: model(x) instead of model.forward(x)
All transformer diagnostic tests now pass (5/5 ✓)(https://claude.ai/code)
This commit is contained in:
Vijay Janapa Reddi
2025-10-28 13:53:43 -04:00
parent dfc8577cad
commit 8ccb0ab4d9
3 changed files with 33 additions and 1 deletions

View File

@@ -280,6 +280,10 @@ class MultiHeadAttention:
return output
### END SOLUTION
def __call__(self, x: Tensor, mask: Optional[Tensor] = None) -> Tensor:
"""Allows the attention layer to be called like a function."""
return self.forward(x, mask)
def parameters(self) -> List[Tensor]:
"""
Return all trainable parameters.