Skip to content

Fix geglu - #986

Merged
lancerts merged 2 commits into
linkedin:mainfrom
konstantinos-p:fix_geglu_v2
Dec 23, 2025
Merged

Fix geglu#986
lancerts merged 2 commits into
linkedin:mainfrom
konstantinos-p:fix_geglu_v2

Conversation

@konstantinos-p

@konstantinos-p konstantinos-p commented Dec 23, 2025

Copy link
Copy Markdown
Contributor

Fixes #959 for fp16

geglu comparison tests with the original torch implementation, were passing with very loose tolerance. This PR fixes the issue for fp16.

geglu tests had loose tolerance both for fp32 and fp16. These seem to be different bugs. Here I fix the bug affecting fp16, which affected only the gradients for the up_proj matrix. Specifically the issue was the recomputation of the forward inside the backward. In the original torch implementaiton, and for fp16, the forward values are implicitly cast to fp16 then stored and reused. The implicit casting step was missing from the current implementation. Note that following downcasting to fp16 I reupcast to fp32 for computations inside the backward.

The FP16 tests now pass with a tolerance of 1e-2, which is a commonly accepted standard. I did not benchmark performance after the bug fix, but I expect any impact to be minimal.

Testing Done

test_geglu.py tests are passing with the tighter tolerance for fp16 on a 1x RTX 5070

@Tcc0403

@lancerts
lancerts merged commit 57848d5 into linkedin:main Dec 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeGLU kernel numerical issue

2 participants