Fix activation docstring math in log_softmax and gelu_approx#3590
Open
adityasingh2400 wants to merge 1 commit into
Open
Fix activation docstring math in log_softmax and gelu_approx#3590adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
The log_softmax docstring rendered the formula as x + log sum exp(x_i), but the function subtracts the log-sum-exp, so the sign was wrong. Correct it to x - log sum exp(x_i), which matches both the implementation and the definition of log(softmax(x)). The gelu_approx math block (and the duplicate in the GELU class docstring) had an extra opening parenthesis right after Tanh, leaving the LaTeX delimiters unbalanced so the expression rendered incorrectly. Remove the stray parenthesis so the grouping matches the implementation. These are documentation-only changes with no effect on runtime behavior. Signed-off-by: Aditya Singh <adisin650@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A couple of the activation docstrings in
mlx.nnhave incorrect math.log_softmaxdocuments the formula asx - mx.logsumexp(...)). The documented sign is wrong. This corrects it togelu_approxhas an extra opening parenthesis immediately after\text{Tanh}in its math block, so the LaTeX delimiters do not balance (three\left(against three\right)plus one stray bare() and the expression renders incorrectly. The same block is duplicated in theGELUclass docstring. Removing the stray parenthesis makes the grouping match the implementation0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x**3))).These are documentation-only changes, so there is no effect on runtime behavior. I verified the corrected
log_softmaxformula againstlog(softmax(x))numerically, confirmed the GELU LaTeX now balances and matches the code, and ranblack/isortplus the activation tests inpython/tests/test_nn.py.