Files
TinyTorch/modules/source/18_compression
Vijay Janapa Reddi dfc8577cad feat: Add PyTorch-style __call__ methods and update milestone syntax
This commit implements comprehensive PyTorch compatibility improvements:

**Core Changes:**
- Add __call__ methods to all neural network components in modules 11-18
- Enable PyTorch-standard calling syntax: model(input) vs model.forward(input)
- Maintain backward compatibility - forward() methods still work

**Modules Updated:**
- Module 11 (Embeddings): Embedding, PositionalEncoding, EmbeddingLayer
- Module 12 (Attention): MultiHeadAttention
- Module 13 (Transformers): LayerNorm, MLP, TransformerBlock, GPT
- Module 17 (Quantization): QuantizedLinear
- Module 18 (Compression): Linear, Sequential classes

**Milestone Updates:**
- Replace all .forward() calls with direct () calls in milestone examples
- Update transformer milestones (vaswani_shakespeare, tinystories_gpt, tinytalks_gpt)
- Update CNN and MLP milestone examples
- Update MILESTONE_TEMPLATE.py for consistency

**Educational Benefits:**
- Students now write identical syntax to production PyTorch code
- Seamless transition from TinyTorch to PyTorch development
- Industry-standard calling conventions from day one

**Implementation Pattern:**
```python
def __call__(self, *args, **kwargs):
    """Allows the component to be called like a function."""
    return self.forward(*args, **kwargs)
```

All changes maintain full backward compatibility while enabling PyTorch-style usage.(https://claude.ai/code)
2025-10-28 13:46:05 -04:00
..