[NPU][diffusion] npu support enable_torch_compile for torchair backend on diffusion models (#20687)
This commit is contained in:
@@ -79,6 +79,7 @@ from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
|
|||||||
from sglang.multimodal_gen.runtime.utils.perf_logger import StageProfiler
|
from sglang.multimodal_gen.runtime.utils.perf_logger import StageProfiler
|
||||||
from sglang.multimodal_gen.runtime.utils.profiler import SGLDiffusionProfiler
|
from sglang.multimodal_gen.runtime.utils.profiler import SGLDiffusionProfiler
|
||||||
from sglang.multimodal_gen.utils import dict_to_3d_list, masks_like
|
from sglang.multimodal_gen.utils import dict_to_3d_list, masks_like
|
||||||
|
from sglang.srt.utils.common import get_compiler_backend
|
||||||
|
|
||||||
logger = init_logger(__name__)
|
logger = init_logger(__name__)
|
||||||
|
|
||||||
@@ -137,16 +138,28 @@ class DenoisingStage(PipelineStage):
|
|||||||
module, nn.Module
|
module, nn.Module
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
try:
|
compile_kwargs: dict[str, Any] = {"fullgraph": False, "dynamic": None}
|
||||||
import torch._inductor.config as _inductor_cfg
|
|
||||||
|
if current_platform.is_npu():
|
||||||
|
backend = get_compiler_backend()
|
||||||
|
compile_kwargs["backend"] = backend
|
||||||
|
compile_kwargs["dynamic"] = False
|
||||||
|
logger.info("Compiling transformer with torchair backend on NPU")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
import torch._inductor.config as _inductor_cfg
|
||||||
|
|
||||||
|
_inductor_cfg.reorder_for_compute_comm_overlap = True
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
mode = os.environ.get(
|
||||||
|
"SGLANG_TORCH_COMPILE_MODE", "max-autotune-no-cudagraphs"
|
||||||
|
)
|
||||||
|
compile_kwargs["mode"] = mode
|
||||||
|
logger.info(f"Compiling transformer with mode: {mode}")
|
||||||
|
|
||||||
_inductor_cfg.reorder_for_compute_comm_overlap = True
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
mode = os.environ.get("SGLANG_TORCH_COMPILE_MODE", "max-autotune-no-cudagraphs")
|
|
||||||
logger.info(f"Compiling transformer with mode: {mode}")
|
|
||||||
# TODO(triple-mu): support customized fullgraph and dynamic in the future
|
# TODO(triple-mu): support customized fullgraph and dynamic in the future
|
||||||
module.compile(mode=mode, fullgraph=False, dynamic=None)
|
module.compile(**compile_kwargs)
|
||||||
|
|
||||||
def _maybe_enable_cache_dit(
|
def _maybe_enable_cache_dit(
|
||||||
self, num_inference_steps: int | tuple[int, int], batch: Req
|
self, num_inference_steps: int | tuple[int, int], batch: Req
|
||||||
|
|||||||
+24
-8
@@ -67,6 +67,7 @@ from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
|
|||||||
from sglang.multimodal_gen.runtime.utils.perf_logger import StageProfiler
|
from sglang.multimodal_gen.runtime.utils.perf_logger import StageProfiler
|
||||||
from sglang.multimodal_gen.runtime.utils.profiler import SGLDiffusionProfiler
|
from sglang.multimodal_gen.runtime.utils.profiler import SGLDiffusionProfiler
|
||||||
from sglang.multimodal_gen.utils import PRECISION_TO_TYPE
|
from sglang.multimodal_gen.utils import PRECISION_TO_TYPE
|
||||||
|
from sglang.srt.utils.common import get_compiler_backend
|
||||||
|
|
||||||
logger = init_logger(__name__)
|
logger = init_logger(__name__)
|
||||||
|
|
||||||
@@ -208,16 +209,31 @@ class MOVADenoisingStage(PipelineStage):
|
|||||||
"""
|
"""
|
||||||
if not server_args.enable_torch_compile or not isinstance(module, nn.Module):
|
if not server_args.enable_torch_compile or not isinstance(module, nn.Module):
|
||||||
return
|
return
|
||||||
try:
|
compile_kwargs: dict[str, object] = {"fullgraph": False, "dynamic": None}
|
||||||
import torch._inductor.config as _inductor_cfg
|
|
||||||
|
if current_platform.is_npu():
|
||||||
|
backend = get_compiler_backend()
|
||||||
|
compile_kwargs["backend"] = backend
|
||||||
|
compile_kwargs["dynamic"] = False
|
||||||
|
logger.info(
|
||||||
|
"Compiling %s with torchair backend on NPU",
|
||||||
|
module.__class__.__name__,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
import torch._inductor.config as _inductor_cfg
|
||||||
|
|
||||||
|
_inductor_cfg.reorder_for_compute_comm_overlap = True
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
mode = os.environ.get(
|
||||||
|
"SGLANG_TORCH_COMPILE_MODE", "max-autotune-no-cudagraphs"
|
||||||
|
)
|
||||||
|
compile_kwargs["mode"] = mode
|
||||||
|
logger.info("Compiling %s with mode: %s", module.__class__.__name__, mode)
|
||||||
|
|
||||||
_inductor_cfg.reorder_for_compute_comm_overlap = True
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
mode = os.environ.get("SGLANG_TORCH_COMPILE_MODE", "max-autotune-no-cudagraphs")
|
|
||||||
logger.info("Compiling %s with mode: %s", module.__class__.__name__, mode)
|
|
||||||
# TODO(triple-mu): support customized fullgraph and dynamic in the future
|
# TODO(triple-mu): support customized fullgraph and dynamic in the future
|
||||||
module.compile(mode=mode, fullgraph=False, dynamic=None)
|
module.compile(**compile_kwargs)
|
||||||
|
|
||||||
def _maybe_compile_dits(self, server_args: ServerArgs):
|
def _maybe_compile_dits(self, server_args: ServerArgs):
|
||||||
if self._torch_compiled or not server_args.enable_torch_compile:
|
if self._torch_compiled or not server_args.enable_torch_compile:
|
||||||
|
|||||||
Reference in New Issue
Block a user