-
Notifications
You must be signed in to change notification settings - Fork 5k
[Refactor] Add -fp4-gemm-backend to replace SGLANG_FLASHINFER_FP4_GEMM_BACKEND
#16534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Fridge003
merged 3 commits into
sgl-project:main
from
bzhng-development:brayden/refactor-fp4-backend
Jan 18, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from enum import Enum | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from sglang.srt.environ import envs | ||
|
|
||
| if TYPE_CHECKING: | ||
| from sglang.srt.server_args import ServerArgs | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Fp4GemmRunnerBackend(Enum): | ||
| """Enum for FP4 GEMM runner backend selection.""" | ||
|
|
||
| AUTO = "auto" | ||
| CUDNN = "cudnn" | ||
| CUTLASS = "cutlass" | ||
| TRTLLM = "trtllm" | ||
|
|
||
| def is_auto(self) -> bool: | ||
| return self == Fp4GemmRunnerBackend.AUTO | ||
|
|
||
| def is_cudnn(self) -> bool: | ||
| return self == Fp4GemmRunnerBackend.CUDNN | ||
|
|
||
| def is_cutlass(self) -> bool: | ||
| return self == Fp4GemmRunnerBackend.CUTLASS | ||
|
|
||
| def is_trtllm(self) -> bool: | ||
| return self == Fp4GemmRunnerBackend.TRTLLM | ||
|
|
||
|
|
||
| FP4_GEMM_RUNNER_BACKEND: Fp4GemmRunnerBackend | None = None | ||
|
|
||
|
|
||
| def initialize_fp4_gemm_config(server_args: ServerArgs) -> None: | ||
| """Initialize FP4 GEMM configuration from server args.""" | ||
| global FP4_GEMM_RUNNER_BACKEND | ||
|
|
||
| backend = server_args.fp4_gemm_runner_backend | ||
|
|
||
| # Handle deprecated env var for backward compatibility | ||
| # TODO: Remove this in a future version | ||
| if envs.SGLANG_FLASHINFER_FP4_GEMM_BACKEND.is_set(): | ||
| env_backend = envs.SGLANG_FLASHINFER_FP4_GEMM_BACKEND.get() | ||
| if backend == "auto": | ||
| logger.warning( | ||
| "SGLANG_FLASHINFER_FP4_GEMM_BACKEND is deprecated. " | ||
| f"Please use '--fp4-gemm-backend={env_backend}' instead." | ||
| ) | ||
| backend = env_backend | ||
| else: | ||
| logger.warning( | ||
| f"FP4 GEMM backend set to '{backend}' via --fp4-gemm-backend overrides " | ||
| "environment variable SGLANG_FLASHINFER_FP4_GEMM_BACKEND. " | ||
| "Using server argument value." | ||
| ) | ||
|
|
||
| FP4_GEMM_RUNNER_BACKEND = Fp4GemmRunnerBackend(backend) | ||
|
|
||
|
|
||
| def get_fp4_gemm_runner_backend() -> Fp4GemmRunnerBackend: | ||
| """Get the current FP4 GEMM runner backend.""" | ||
| global FP4_GEMM_RUNNER_BACKEND | ||
| if FP4_GEMM_RUNNER_BACKEND is None: | ||
| FP4_GEMM_RUNNER_BACKEND = Fp4GemmRunnerBackend.AUTO | ||
| return FP4_GEMM_RUNNER_BACKEND | ||
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deduplicate line48-line53 here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consolidated 👍