[diffusion] attention: Allow disabling sequence masking in SP (#33855)
Co-authored-by: jacky.cheng <yichiche@amd.com>
This commit is contained in:
co-authored by
jacky.cheng
parent
c41b2d26e5
commit
9f7d38ffd3
@@ -35,6 +35,7 @@ if TYPE_CHECKING:
|
||||
NVCC_THREADS: str | None = None
|
||||
CMAKE_BUILD_TYPE: str | None = None
|
||||
VERBOSE: bool = False
|
||||
SGLANG_DIFFUSION_DISABLE_SP_PAD_MASK: bool = False
|
||||
SGLANG_DIFFUSION_SERVER_DEV_MODE: bool = False
|
||||
SGLANG_DIFFUSION_DISABLE_MAPPED_COURIER: bool = False
|
||||
SGLANG_DIFFUSION_HOST_SPILL_DIR: str = os.path.expanduser(
|
||||
@@ -255,6 +256,13 @@ environment_variables: dict[str, Callable[[], Any]] = {
|
||||
"SGLANG_DIFFUSION_MXFP8_FA_HEAD_CHUNK_SIZE": _lazy_int(
|
||||
"SGLANG_DIFFUSION_MXFP8_FA_HEAD_CHUNK_SIZE", 4
|
||||
),
|
||||
# Drop the SP tail-pad attention mask and run dense (unmasked) attention on
|
||||
# the padded layout, instead of the packed-varlen path. Applies only when
|
||||
# sequence parallelism is active and the mask is derived purely from the
|
||||
# shard pad span.
|
||||
"SGLANG_DIFFUSION_DISABLE_SP_PAD_MASK": _lazy_bool(
|
||||
"SGLANG_DIFFUSION_DISABLE_SP_PAD_MASK"
|
||||
),
|
||||
# Select a built-in platform or an installed platform entry point.
|
||||
# Empty means automatic plugin activation followed by built-in detection.
|
||||
"SGLANG_DIFFUSION_PLATFORM_OVERRIDE": _lazy_str(
|
||||
|
||||
@@ -18,6 +18,7 @@ from sglang.kernels.ops.diffusion import (
|
||||
fused_pack_segmented_qkv,
|
||||
fused_scatter_to_padded,
|
||||
)
|
||||
from sglang.multimodal_gen import envs
|
||||
from sglang.multimodal_gen.runtime import server_args as server_args_module
|
||||
from sglang.multimodal_gen.runtime.breakable_cuda_graph.replay_token import (
|
||||
get_current_replay_token,
|
||||
@@ -90,6 +91,10 @@ _PYTORCH_DEFAULT_CUDA_SDP_BACKENDS = [
|
||||
# USPAttention masked branch and fall back to SDPA.
|
||||
_VARLEN_FA_ENABLED = os.environ.get("SGLANG_VARLEN_FA", "1") != "0"
|
||||
|
||||
# Set ``SGLANG_DIFFUSION_DISABLE_SP_PAD_MASK=1`` to drop the SP tail-pad mask
|
||||
# and run dense attention on the padded layout.
|
||||
_SP_PAD_MASK_DISABLED = envs.SGLANG_DIFFUSION_DISABLE_SP_PAD_MASK
|
||||
|
||||
|
||||
def _resolve_sp_attention_mode(
|
||||
*, causal: bool, sparse_backend: bool
|
||||
@@ -988,6 +993,15 @@ class USPAttention(nn.Module):
|
||||
if isinstance(attn_mask_meta, DynamicVarlenMaskMeta)
|
||||
else attn_mask
|
||||
)
|
||||
|
||||
if (
|
||||
_SP_PAD_MASK_DISABLED
|
||||
and attn_mask is None
|
||||
and not effective_skip_sp
|
||||
and get_sequence_parallel_world_size() > 1
|
||||
):
|
||||
attn_mask_meta = None
|
||||
|
||||
if isinstance(attn_mask_meta, DynamicVarlenMaskMeta):
|
||||
attn_mask_meta = attn_mask_meta.resolve(attn_mask)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user