mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-05-29 17:47:14 -05:00
Enable cleaner API usage by adding __call__ methods to all activation, layer, and loss classes. This allows students to write: - relu(x) instead of relu.forward(x) - layer(x) instead of layer.forward(x) - loss_fn(pred, target) instead of loss_fn.forward(pred, target) Changes: - Module 02 (Activations): Add __call__ to ReLU, Tanh, GELU, Softmax * Sigmoid already had __call__ - Module 03 (Layers): Add __call__ to Dropout * Linear already had __call__ - Module 04 (Losses): Add __call__ to MSELoss, CrossEntropyLoss, BinaryCrossEntropyLoss This matches PyTorch's API convention where model(x) calls model.__call__(x) which internally calls model.forward(x). Makes code more Pythonic and intuitive for students familiar with PyTorch. Expected impact: Test pass rates should improve significantly as tests expect PyTorch-style callable API.