[NPU]Support torch_npu profiler patch API drift (#26356)
Co-authored-by: leland17 <lileliao@foxmail.com> Co-authored-by: OmX <omx@oh-my-codex.dev> Co-authored-by: ronnie_zheng <zl19940307@163.com>
This commit is contained in:
co-authored by
leland17
OmX
ronnie_zheng
parent
280280ace9
commit
4e14b50c48
@@ -5,6 +5,7 @@ import torch
|
||||
|
||||
from sglang.multimodal_gen.runtime.platforms import current_platform
|
||||
from sglang.multimodal_gen.runtime.utils.logging_utils import CYAN, RESET, init_logger
|
||||
from sglang.srt.utils.torch_npu_patch_utils import apply_torch_npu_patches
|
||||
|
||||
if current_platform.is_npu():
|
||||
import torch_npu
|
||||
@@ -13,7 +14,7 @@ if current_platform.is_npu():
|
||||
["profiler.profile", torch_npu.profiler.profile],
|
||||
["profiler.schedule", torch_npu.profiler.schedule],
|
||||
]
|
||||
torch_npu._apply_patches(patches)
|
||||
apply_torch_npu_patches(torch_npu, patches)
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from sglang.srt.model_executor.forward_batch_info import ForwardMode
|
||||
from sglang.srt.server_args import get_global_server_args
|
||||
from sglang.srt.utils import is_npu
|
||||
from sglang.srt.utils.profile_merger import ProfileMerger
|
||||
from sglang.srt.utils.torch_npu_patch_utils import apply_torch_npu_patches
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sglang.srt.managers.schedule_batch import ScheduleBatch
|
||||
@@ -34,7 +35,7 @@ if _is_npu:
|
||||
["profiler.ProfilerActivity.CUDA", torch_npu.profiler.ProfilerActivity.NPU],
|
||||
["profiler.ProfilerActivity.CPU", torch_npu.profiler.ProfilerActivity.CPU],
|
||||
]
|
||||
torch_npu._apply_patches(patches)
|
||||
apply_torch_npu_patches(torch_npu, patches)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ from sglang.srt.managers.io_struct import ProfileReqOutput
|
||||
from sglang.srt.model_executor.forward_batch_info import ForwardMode
|
||||
from sglang.srt.server_args import get_global_server_args
|
||||
from sglang.srt.utils import is_npu
|
||||
from sglang.srt.utils.torch_npu_patch_utils import apply_torch_npu_patches
|
||||
|
||||
_is_npu = is_npu()
|
||||
if _is_npu:
|
||||
@@ -23,7 +24,7 @@ if _is_npu:
|
||||
["profiler.ProfilerActivity.CUDA", torch_npu.profiler.ProfilerActivity.NPU],
|
||||
["profiler.ProfilerActivity.CPU", torch_npu.profiler.ProfilerActivity.CPU],
|
||||
]
|
||||
torch_npu._apply_patches(patches)
|
||||
apply_torch_npu_patches(torch_npu, patches)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from collections.abc import Sequence
|
||||
from typing import Any
|
||||
|
||||
|
||||
def apply_torch_npu_patches(torch_npu: Any, patches: Sequence[Sequence[Any]]) -> None:
|
||||
"""Apply torch_npu patches across old and new torch_npu patch APIs."""
|
||||
if hasattr(torch_npu, "_apply_patches"):
|
||||
torch_npu._apply_patches(patches)
|
||||
return
|
||||
|
||||
if hasattr(torch_npu, "_apply_all_patches"):
|
||||
torch_npu._apply_all_patches()
|
||||
return
|
||||
|
||||
raise AttributeError(
|
||||
"torch_npu must provide either _apply_patches or _apply_all_patches"
|
||||
)
|
||||
Reference in New Issue
Block a user