Skip to content
Merged
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
12 changes: 9 additions & 3 deletions python/sglang/srt/layers/attention/flashinfer_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def __init__(
init_new_workspace: bool = False,
):
super().__init__()
self.prefill_backend = "fa2"
self.decode_backend = "fa2"
Comment on lines +124 to +125
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While hardcoding the backends to "fa2" fixes the immediate performance regression, it might be beneficial for future flexibility to make these configurable. This would allow easier tuning or adaptation to new hardware or flashinfer versions without code changes.

Consider using environment variables to control the backend selection, with "fa2" as the default. This can be managed through the envs module. You would need to add SGLANG_FLASHINFER_PREFILL_BACKEND and SGLANG_FLASHINFER_DECODE_BACKEND to sglang/srt/environ.py with a default value of "fa2".

Suggested change
self.prefill_backend = "fa2"
self.decode_backend = "fa2"
self.prefill_backend = envs.SGLANG_FLASHINFER_PREFILL_BACKEND.get()
self.decode_backend = envs.SGLANG_FLASHINFER_DECODE_BACKEND.get()


# Store multi-item scoring delimiter for efficient access
self.multi_item_scoring_delimiter = (
Expand Down Expand Up @@ -264,19 +266,21 @@ def __init__(
BatchPrefillWithPagedKVCacheWrapper(
self.workspace_buffer,
"NHD",
backend="fa2",
backend=self.prefill_backend,
)
)
self.prefill_wrappers_verify.append(
BatchPrefillWithPagedKVCacheWrapper(
self.workspace_buffer,
"NHD",
backend=self.prefill_backend,
)
)
self.decode_wrappers.append(
BatchDecodeWithPagedKVCacheWrapper(
self.workspace_buffer,
"NHD",
backend=self.decode_backend,
use_tensor_cores=self.decode_use_tensor_cores,
)
)
Expand Down Expand Up @@ -555,6 +559,7 @@ def init_forward_metadata_capture_cuda_graph(
BatchDecodeWithPagedKVCacheWrapper(
self.workspace_buffer,
"NHD",
backend=self.decode_backend,
use_cuda_graph=True,
use_tensor_cores=self.decode_use_tensor_cores,
paged_kv_indptr_buffer=self.kv_indptr[i][: num_tokens + 1],
Expand Down Expand Up @@ -590,6 +595,7 @@ def init_forward_metadata_capture_cuda_graph(
self.workspace_buffer,
"NHD",
use_cuda_graph=True,
backend=self.prefill_backend,
qo_indptr_buf=self.cuda_graph_qo_indptr[i][: bs + 1],
paged_kv_indptr_buf=self.kv_indptr[i][: bs + 1],
paged_kv_indices_buf=self.cuda_graph_kv_indices[i],
Expand Down Expand Up @@ -619,7 +625,7 @@ def init_forward_metadata_capture_cuda_graph(
BatchPrefillWithPagedKVCacheWrapper(
self.workspace_buffer,
"NHD",
backend="fa2",
backend=self.prefill_backend,
use_cuda_graph=True,
qo_indptr_buf=self.cuda_graph_qo_indptr[i][: bs + 1],
paged_kv_indptr_buf=self.kv_indptr[i][: bs + 1],
Expand Down Expand Up @@ -649,7 +655,7 @@ def init_forward_metadata_capture_cuda_graph(
BatchPrefillWithPagedKVCacheWrapper(
self.workspace_buffer,
"NHD",
backend="fa2",
backend=self.prefill_backend,
use_cuda_graph=True,
qo_indptr_buf=self.cuda_graph_qo_indptr[i][: bs + 1],
paged_kv_indptr_buf=self.kv_indptr[i][: bs + 1],
Expand Down
Loading