Skip to content
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

feat: use sgl-kernel by default #3088

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
if: github.repository == 'sgl-project/sglang' || github.event_name == 'pull_request'
runs-on: 1-gpu-runner
strategy:
fail-fast: false
matrix:
range: [0-6, 6-15, 15-22, 22-32, 32-40, 40-100]
steps:
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ runtime_common = [
]
srt = [
"sglang[runtime_common]", "cuda-python",
"sgl-kernel>=0.0.2.post14", "torch", "vllm==0.6.4.post1",
"sgl-kernel>=0.0.2.post16", "torch", "vllm==0.6.4.post1",
"flashinfer==0.1.6"
]

Expand Down
14 changes: 11 additions & 3 deletions python/sglang/srt/layers/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
import torch.nn as nn
import torch.nn.functional as F

from sglang.srt.utils import is_flashinfer_available
from sglang.srt.utils import (
enable_use_sgl_kernel_first,
is_cuda_available,
is_flashinfer_available,
)

if is_flashinfer_available():
from flashinfer.activation import gelu_and_mul, gelu_tanh_and_mul, silu_and_mul
if enable_use_sgl_kernel_first:
if is_cuda_available():
from sgl_kernel import gelu_and_mul, gelu_tanh_and_mul, silu_and_mul
else:
if is_flashinfer_available():
from flashinfer.activation import gelu_and_mul, gelu_tanh_and_mul, silu_and_mul

from vllm.model_executor.custom_op import CustomOp

Expand Down
31 changes: 22 additions & 9 deletions python/sglang/srt/layers/layernorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,28 @@
import torch
import torch.nn as nn

from sglang.srt.utils import is_flashinfer_available

if is_flashinfer_available():
from flashinfer.norm import (
fused_add_rmsnorm,
gemma_fused_add_rmsnorm,
gemma_rmsnorm,
rmsnorm,
)
from sglang.srt.utils import (
enable_use_sgl_kernel_first,
is_cuda_available,
is_flashinfer_available,
)

if enable_use_sgl_kernel_first:
if is_cuda_available():
from sgl_kernel import (
fused_add_rmsnorm,
gemma_fused_add_rmsnorm,
gemma_rmsnorm,
rmsnorm,
)
else:
if is_flashinfer_available():
from flashinfer.norm import (
fused_add_rmsnorm,
gemma_fused_add_rmsnorm,
gemma_rmsnorm,
rmsnorm,
)

from vllm.model_executor.custom_op import CustomOp

Expand Down
25 changes: 18 additions & 7 deletions python/sglang/srt/layers/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,28 @@
from sglang.srt.sampling.sampling_batch_info import SamplingBatchInfo
from sglang.srt.utils import (
crash_on_warnings,
enable_use_sgl_kernel_first,
get_bool_env_var,
is_cuda_available,
is_flashinfer_available,
)

if is_flashinfer_available():
from flashinfer.sampling import (
min_p_sampling_from_probs,
top_k_renorm_prob,
top_k_top_p_sampling_from_probs,
top_p_renorm_prob,
)
if enable_use_sgl_kernel_first:
if is_cuda_available():
from sgl_kernel import (
min_p_sampling_from_probs,
top_k_renorm_prob,
top_k_top_p_sampling_from_probs,
top_p_renorm_prob,
)
else:
if is_flashinfer_available():
from flashinfer.sampling import (
min_p_sampling_from_probs,
top_k_renorm_prob,
top_k_top_p_sampling_from_probs,
top_p_renorm_prob,
)


logger = logging.getLogger(__name__)
Expand Down
14 changes: 12 additions & 2 deletions python/sglang/srt/models/deepseek_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,18 @@

is_hip_ = is_hip()

if is_flashinfer_available():
from flashinfer import bmm_fp8
from sglang.srt.utils import (
enable_use_sgl_kernel_first,
is_cuda_available,
is_flashinfer_available,
)

if enable_use_sgl_kernel_first:
if is_cuda_available():
from sgl_kernel import bmm_fp8
else:
if is_flashinfer_available():
from flashinfer import bmm_fp8


class DeepseekV2MLP(nn.Module):
Expand Down
14 changes: 11 additions & 3 deletions python/sglang/srt/models/minicpm3.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@
from sglang.srt.managers.schedule_batch import global_server_args_dict
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import is_flashinfer_available
from sglang.srt.utils import (
enable_use_sgl_kernel_first,
is_cuda_available,
is_flashinfer_available,
)

if is_flashinfer_available():
from flashinfer import bmm_fp8
if enable_use_sgl_kernel_first:
if is_cuda_available():
from sgl_kernel import bmm_fp8
else:
if is_flashinfer_available():
from flashinfer import bmm_fp8


class MiniCPM3MLP(nn.Module):
Expand Down
2 changes: 2 additions & 0 deletions python/sglang/srt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
show_time_cost = False
time_infos = {}

enable_use_sgl_kernel_first = bool(int(os.getenv("ENABLE_USE_SGL_KERNEL_FIRST", "1")))


def is_hip() -> bool:
"""Return whether it is HIP on the AMD ROCm platform."""
Expand Down
Loading