Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/sglang/srt/layers/deep_gemm_wrapper/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ def tf32_hc_prenorm_gemm(
):
if x.shape[0] == 0:
return
import deep_gemm

deep_gemm.tf32_hc_prenorm_gemm(x, fn, out, sqrsum, num_splits=num_splits)
Comment on lines +245 to 247

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



Expand Down
Loading