[PR #1695] fix(tinytorch): reuse Sigmoid class in GELU solution #10237

Open
opened 2026-05-08 11:21:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/harvard-edge/cs249r_book/pull/1695
Author: @Shashank-Tripathi-07
Created: 5/7/2026
Status: 🔄 Open

Base: devHead: fix/tinytorch-gelu-reuse-sigmoid


📝 Commits (1)

  • 4257203 fix(tinytorch): reuse Sigmoid class in GELU solution

📊 Changes

1 file changed (+1 additions, -6 deletions)

View changed files

📝 tinytorch/src/02_activations/02_activations.py (+1 -6)

📄 Description

Summary

  • GELU's forward() solution used raw np.exp to compute the sigmoid, bypassing the Sigmoid class students built earlier in the same module.
  • The docstring explicitly says "reuse sigmoid (which you just built!)" -- the old solution contradicted this hint.
  • Replaced the 6-line implementation with return Sigmoid()(x * 1.702) * x, which is numerically identical and demonstrates class composition.

Fix

Before:

### BEGIN SOLUTION
# GELU approximation: x * sigmoid(1.702 * x)
# First compute sigmoid part
sigmoid_part = 1.0 / (1.0 + np.exp(-1.702 * x.data))
# Then multiply by x
result = x.data * sigmoid_part
return Tensor(result)
### END SOLUTION

After:

### BEGIN SOLUTION
return Sigmoid()(x * 1.702) * x
### END SOLUTION

Verified numerically: both produce identical outputs across positive and negative inputs.

Fixes #1692

Test plan

  • Confirm np.allclose(Sigmoid()(x * 1.702) * x, old_impl(x)) passes for representative inputs
  • Run TinyTorch test suite: pytest tests/
  • Regenerate notebook via tito src export 02_activations and confirm the student-facing cell is still a blank stub

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1695 **Author:** [@Shashank-Tripathi-07](https://github.com/Shashank-Tripathi-07) **Created:** 5/7/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix/tinytorch-gelu-reuse-sigmoid` --- ### 📝 Commits (1) - [`4257203`](https://github.com/harvard-edge/cs249r_book/commit/42572031c71d04af54ef90570e742180db416801) fix(tinytorch): reuse Sigmoid class in GELU solution ### 📊 Changes **1 file changed** (+1 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `tinytorch/src/02_activations/02_activations.py` (+1 -6) </details> ### 📄 Description ## Summary - GELU's `forward()` solution used raw `np.exp` to compute the sigmoid, bypassing the `Sigmoid` class students built earlier in the same module. - The docstring explicitly says "reuse sigmoid (which you just built!)" -- the old solution contradicted this hint. - Replaced the 6-line implementation with `return Sigmoid()(x * 1.702) * x`, which is numerically identical and demonstrates class composition. ## Fix **Before:** ```python ### BEGIN SOLUTION # GELU approximation: x * sigmoid(1.702 * x) # First compute sigmoid part sigmoid_part = 1.0 / (1.0 + np.exp(-1.702 * x.data)) # Then multiply by x result = x.data * sigmoid_part return Tensor(result) ### END SOLUTION ``` **After:** ```python ### BEGIN SOLUTION return Sigmoid()(x * 1.702) * x ### END SOLUTION ``` Verified numerically: both produce identical outputs across positive and negative inputs. Fixes #1692 ## Test plan - [ ] Confirm `np.allclose(Sigmoid()(x * 1.702) * x, old_impl(x))` passes for representative inputs - [ ] Run TinyTorch test suite: `pytest tests/` - [ ] Regenerate notebook via `tito src export 02_activations` and confirm the student-facing cell is still a blank stub --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-08 11:21:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#10237