Skip to content

Bugfix in tf32_hc_prenorm_gemm when SGLANG_ENABLE_JIT_DEEPGEMM=0 - #29740

Open
mattyding wants to merge 2 commits into
sgl-project:mainfrom
mattyding:fix/hc-prenorm-deep-gemm-import
Open

mattyding wants to merge 2 commits into
sgl-project:mainfrom
mattyding:fix/hc-prenorm-deep-gemm-import

Conversation

@mattyding

@mattyding mattyding commented Jun 30, 2026

Copy link
Copy Markdown

Motivation

Fixes #29738.

Modifications

tf32_hc_prenorm_gemm referenced the module-level deep_gemm, which is only imported under ENABLE_JIT_DEEPGEMM. The HC-prenorm path reaches it via the independent SGLANG_OPT_DEEPGEMM_HC_PRENORM gate, so SGLANG_ENABLE_JIT_DEEPGEMM=0 raised NameError. Added a local import deep_gemm, matching the existing pattern in mhc.py.


CI States

Latest PR Test (Base): ❌ Run #31571002834
Latest PR Test (Extra): ❌ Run #31571002654

…path works when SGLANG_ENABLE_JIT_DEEPGEMM=0.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a local import of deep_gemm inside the tf32_hc_prenorm_gemm function. The feedback notes that because this function is on the hot path, importing the module on every invocation adds unnecessary overhead. The reviewer suggests lazily importing and caching the module globally to optimize performance.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +197 to 199
import deep_gemm

deep_gemm.tf32_hc_prenorm_gemm(x, fn, out, sqrsum, num_splits=num_splits)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In high-performance LLM serving, tf32_hc_prenorm_gemm is executed on the hot path (potentially once per layer/step). Running import deep_gemm on every single invocation introduces unnecessary overhead from sys.modules lookups and import lock acquisition.

By declaring global deep_gemm and checking if it is already present in globals(), we can lazily import it on the first call and reuse the cached global reference on all subsequent calls. This reduces the overhead to a simple, extremely fast dictionary lookup.

Suggested change
import deep_gemm
deep_gemm.tf32_hc_prenorm_gemm(x, fn, out, sqrsum, num_splits=num_splits)
global deep_gemm
if "deep_gemm" not in globals():
import deep_gemm
deep_gemm.tf32_hc_prenorm_gemm(x, fn, out, sqrsum, num_splits=num_splits)

@mattyding mattyding Jun 30, 2026

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.

global cache call saves ~29ns, negligable (measured)

i follow the pre-exisitng example set by https://github.com/sgl-project/sglang/blob/v0.5.14/python/sglang/srt/layers/mhc.py#L1446-L1449

@mattyding

mattyding commented Jul 7, 2026

Copy link
Copy Markdown
Author

Hello @YAMY1234, I believe this bug was introduced in #26238 - can you help take a look / find a maintainer to review? Small change (missing import) that breaks dsv4 for certain configs.

This is my first contribution, so unclear to me how to get help here. Fixed in my downstream fork but would like to get fixed upstream so I don't have to keep re-patching it.

@YAMY1234

YAMY1234 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Let me take a look

@YAMY1234 YAMY1234 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@b8zhong b8zhong mentioned this pull request Aug 5, 2026
41 tasks
@mattyding

Copy link
Copy Markdown
Author

Hi @Fridge003, I see you approved the original PR - can I get a stamp here / help merging this change?

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.

[Bug] NameError: name 'deep_gemm' is not defined in tf32_hc_prenorm_gemm when SGLANG_ENABLE_JIT_DEEPGEMM=0

2 participants