Skip to content

Add optional TE-native SwiGLU kernel dispatch (USE_TE_SWIGLU)#122

Open
sarthak-amd wants to merge 2 commits intorocm_devfrom
te-native-swiglu-dispatch
Open

Add optional TE-native SwiGLU kernel dispatch (USE_TE_SWIGLU)#122
sarthak-amd wants to merge 2 commits intorocm_devfrom
te-native-swiglu-dispatch

Conversation

@sarthak-amd
Copy link
Copy Markdown

@sarthak-amd sarthak-amd commented Apr 8, 2026

Summary

  • Adds opt-in dispatch to Transformer Engine's native SwiGLU kernel in SwiGLUFunction (forward: te.ops.SwiGLU(), backward: tex.dswiglu())
  • Enabled via USE_TE_SWIGLU=1 env var; disabled by default

Made with Cursor

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
Copy link
Copy Markdown

@Micky774 Micky774 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit

except ImportError:
_te_swiglu_available = False

_use_te_swiglu = os.getenv("USE_TE_SWIGLU", "0") == "1"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sarthak-amd sarthak-amd requested a review from Micky774 April 9, 2026 23:28
@sudhu2k sudhu2k self-requested a review April 13, 2026 20:38
ctx.fp8_input_store = fp8_input_store

if _use_te_swiglu:
return te.ops.SwiGLU()(input)
Copy link
Copy Markdown
Collaborator

@sudhu2k sudhu2k Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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.

3 participants