[GH-ISSUE #1692] [TinyTorch] GELU code solution issue in tinytorch/src/02_activations/02_activations.py #18065

Closed
opened 2026-05-28 21:49:31 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @bdub-1 on GitHub (May 6, 2026).
Original GitHub issue: https://github.com/harvard-edge/cs249r_book/issues/1692

Module

02 Activations

Type of Improvement

Code quality (refactor, style, consistency)

Description

Something to point out (relating to #1689). In this issue I referenced tinytorch/src/02_activations to populate the implementation for GELU. This fits in with how the other implementations are presented in the docs.

However, I noticed the current src code solution to be an issue. This line indicates we need to reuse the Sigmoid class we already built but then the current GELU solution uses a non-numerically stable GELU approximation approach.

Proposed Solution

Should the src code be updated in module 02 to reflect this? @profvjreddi

class GELU:
  """
  This implementation reuses our numerically stable Sigmoid implementation,
  as the instruction indicated we were supposed to.
  """
  def forward(self, x: Tensor) -> Tensor:
    result = Sigmoid()(x * 1.702) # returns newly allocated Tensor
    result *= x                   # in-place, element-wise multiplication
    return result
  • The pull request #1690 which addresses the issue #1689 would need to be updated prior to its merge or update the docs again with the source code change in a new PR
Originally created by @bdub-1 on GitHub (May 6, 2026). Original GitHub issue: https://github.com/harvard-edge/cs249r_book/issues/1692 ### Module 02 Activations ### Type of Improvement Code quality (refactor, style, consistency) ### Description Something to point out (relating to #1689). In this issue I referenced [tinytorch/src/02_activations](https://github.com/harvard-edge/cs249r_book/blob/ccf01ccd0808b302805bd610082910c966699b9c/tinytorch/src/02_activations/02_activations.py#L626-L633) to populate the implementation for GELU. This fits in with how the other implementations are presented in the docs. However, I noticed the current src code solution to be an issue. [This line](https://github.com/harvard-edge/cs249r_book/blob/ccf01ccd0808b302805bd610082910c966699b9c/tinytorch/src/02_activations/02_activations.py#L564) indicates we need to reuse the `Sigmoid` class we already built but then the current GELU solution uses a non-numerically stable GELU approximation approach. ### Proposed Solution Should the src code be updated in module 02 to reflect this? @profvjreddi ```py class GELU: """ This implementation reuses our numerically stable Sigmoid implementation, as the instruction indicated we were supposed to. """ def forward(self, x: Tensor) -> Tensor: result = Sigmoid()(x * 1.702) # returns newly allocated Tensor result *= x # in-place, element-wise multiplication return result ``` - The pull request #1690 which addresses the issue #1689 would need to be updated prior to its merge or update the docs again with the source code change in a new PR
GiteaMirror added the area: tinytorchtype: improvement labels 2026-05-28 21:49:31 -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#18065