Skip to content
Merged
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
9 changes: 6 additions & 3 deletions python/sglang/multimodal_gen/runtime/layers/layernorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from sglang.multimodal_gen.runtime.utils.common import get_bool_env_var

_is_cuda = current_platform.is_cuda()
_is_rocm = current_platform.is_rocm()
_is_npu = current_platform.is_npu()
_is_musa = current_platform.is_musa()
_is_cpu = current_platform.is_cpu()
Expand Down Expand Up @@ -984,10 +985,10 @@ def apply_qk_norm(
batch_size = q.size(0)
q_eps = q_norm.variance_epsilon
k_eps = k_norm.variance_epsilon
# Only try fused path on CUDA and when it won't introduce implicit copies.
# Only try fused path on CUDA/ROCm and when it won't introduce implicit copies.
# The in-place kernel needs a real view (no copy), so it also requires contiguity.
if (
_is_cuda
(_is_cuda or _is_rocm)
and allow_inplace
and (q_eps == k_eps)
and q.dtype in (torch.float16, torch.bfloat16)
Expand Down Expand Up @@ -1028,6 +1029,7 @@ def apply_qk_norm_with_optional_rope(
positions: Optional[torch.Tensor] = None,
position_offset: int = 0,
allow_inplace: bool = True,
allow_strided_qk: bool = False,
) -> Tuple[torch.Tensor, torch.Tensor]:
"""Apply QK RMSNorm and optionally RoPE when a cos/sin cache is provided."""

Expand All @@ -1053,6 +1055,7 @@ def apply_qk_norm_with_optional_rope(
positions=positions,
position_offset=position_offset,
allow_inplace=allow_inplace,
allow_strided_qk=allow_strided_qk,
)


Expand Down Expand Up @@ -1146,7 +1149,7 @@ def apply_qk_norm_rope(

if (
fused_enabled
and _is_cuda
and (_is_cuda or _is_rocm)
and not torch.compiler.is_compiling()
and allow_inplace
and (q_eps == k_eps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ def forward(
freqs_complex=complex_freqs,
is_neox=False,
allow_inplace=True,
allow_strided_qk=True if current_platform.is_rocm() else False,
)
hidden_states = self.attn(
query,
Expand Down
Loading