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 partsigmoid_part=1.0/(1.0+np.exp(-1.702*x.data))# Then multiply by xresult=x.data*sigmoid_partreturnTensor(result)### END SOLUTION
After:
### BEGIN SOLUTIONreturnSigmoid()(x*1.702)*x### END SOLUTION
Verified numerically: both produce identical outputs across positive and negative inputs.
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:** ✅ Merged
**Merged:** 5/10/2026
**Merged by:** [@profvjreddi](https://github.com/profvjreddi)
**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>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/harvard-edge/cs249r_book/pull/1695
Author: @Shashank-Tripathi-07
Created: 5/7/2026
Status: ✅ Merged
Merged: 5/10/2026
Merged by: @profvjreddi
Base:
dev← Head:fix/tinytorch-gelu-reuse-sigmoid📝 Commits (1)
4257203fix(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
forward()solution used rawnp.expto compute the sigmoid, bypassing theSigmoidclass students built earlier in the same module.return Sigmoid()(x * 1.702) * x, which is numerically identical and demonstrates class composition.Fix
Before:
After:
Verified numerically: both produce identical outputs across positive and negative inputs.
Fixes #1692
Test plan
np.allclose(Sigmoid()(x * 1.702) * x, old_impl(x))passes for representative inputspytest tests/tito src export 02_activationsand 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.