Add optional TE-native SwiGLU kernel dispatch (USE_TE_SWIGLU)#122
Open
sarthak-amd wants to merge 2 commits intorocm_devfrom
Open
Add optional TE-native SwiGLU kernel dispatch (USE_TE_SWIGLU)#122sarthak-amd wants to merge 2 commits intorocm_devfrom
sarthak-amd wants to merge 2 commits intorocm_devfrom
Conversation
When USE_TE_SWIGLU=1 and Transformer Engine is installed, SwiGLUFunction dispatches to te.ops.SwiGLU() (forward) and tex.dswiglu() (backward) instead of the default Triton-fused pointwise fallback. Opt-in, disabled by default. Guarded by try/except so environments without Transformer Engine are unaffected. Made-with: Cursor
Micky774
reviewed
Apr 9, 2026
| except ImportError: | ||
| _te_swiglu_available = False | ||
|
|
||
| _use_te_swiglu = os.getenv("USE_TE_SWIGLU", "0") == "1" |
There was a problem hiding this comment.
Suggested change
| _use_te_swiglu = os.getenv("USE_TE_SWIGLU", "0") == "1" | |
| _use_te_swiglu = _te_swiglu_available and int(os.getenv("USE_TE_SWIGLU", "0")) |
You can then remove _te_swiglu_available from the conditionals below
sudhu2k
requested changes
Apr 13, 2026
| ctx.fp8_input_store = fp8_input_store | ||
|
|
||
| if _use_te_swiglu: | ||
| return te.ops.SwiGLU()(input) |
Collaborator
There was a problem hiding this comment.
Can we use tex.swiglu instead? This will also remove the need to import both
import transformer_engine.pytorch as te
import transformer_engine_torch as tex
Instead, we can just import
import transformer_engine_torch as tex
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.
Summary
SwiGLUFunction(forward:te.ops.SwiGLU(), backward:tex.dswiglu())USE_TE_SWIGLU=1env var; disabled by defaultMade with Cursor