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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def fused_silu_mul_bitexact(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
def fused_packed_silu_mul_bitexact(x: torch.Tensor) -> torch.Tensor:
"""Bit-exact SwiGLU over a contiguous packed ``[..., 2 * D]`` input."""
if not (
x.is_cuda
(x.is_cuda or x.is_xpu)
and x.dtype is torch.bfloat16
and x.dim() == 3
and x.stride(-1) == 1
Expand All @@ -113,7 +113,7 @@ def fused_packed_silu_mul_bitexact(x: torch.Tensor) -> torch.Tensor:
rows = x.numel() // x.shape[-1]
row_stride = x.stride(-2)
out = torch.empty((*x.shape[:-1], hidden), dtype=x.dtype, device=x.device)
with torch.cuda.device(x.device):
with torch.get_device_module(x.device).device(x.device):
_packed_silu_mul_kernel[(rows, triton.cdiv(hidden, 1024))](
out,
x,
Expand Down
8 changes: 6 additions & 2 deletions python/sglang/multimodal_gen/runtime/models/dits/flux_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def _flux2_swiglu(x: torch.Tensor) -> torch.Tensor:
verified = sig in _FLUX2_SWIGLU_SIGS
can_fuse = (
not _FLUX2_SWIGLU.disabled
and x.is_cuda
and (x.is_cuda or x.is_xpu)
and x.dtype is torch.bfloat16
and x.dim() == 3
and x.stride(-1) == 1
Expand All @@ -441,7 +441,11 @@ def _flux2_swiglu(x: torch.Tensor) -> torch.Tensor:
)
# Per-signature verification may compare tensors and synchronize. Never
# verify a new layout while a CUDA graph is being captured.
if can_fuse and not verified and torch.cuda.is_current_stream_capturing():
if (
can_fuse
and not verified
and torch.get_device_module(x.device).is_current_stream_capturing()
):
return F.silu(x[..., :half]) * x[..., half:]
if can_fuse:
try:
Expand Down
Loading