Support releasing CUDA graph memory when paused (#7873)
Co-authored-by: ryang-max <y1cunhui.yang@gmail.com> Co-authored-by: ryang <38470282+ryang-max@users.noreply.github.com>
This commit is contained in:
@@ -21,12 +21,14 @@ import inspect
|
||||
import logging
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
from functools import partial
|
||||
from typing import TYPE_CHECKING, Callable, Optional, Union
|
||||
|
||||
import torch
|
||||
import tqdm
|
||||
from torch.profiler import ProfilerActivity, profile
|
||||
|
||||
from sglang.srt.constants import GPU_MEMORY_TYPE_CUDA_GRAPH
|
||||
from sglang.srt.custom_op import CustomOp
|
||||
from sglang.srt.distributed import get_tensor_model_parallel_rank
|
||||
from sglang.srt.distributed.device_communicators.pynccl_allocator import (
|
||||
@@ -64,6 +66,7 @@ from sglang.srt.utils import (
|
||||
require_mlp_tp_gather,
|
||||
)
|
||||
from sglang.srt.utils.patch_torch import monkey_patch_torch_compile
|
||||
from sglang.srt.utils.torch_memory_saver_adapter import TorchMemorySaverAdapter
|
||||
|
||||
try:
|
||||
from kt_kernel import AMXMoEWrapper
|
||||
@@ -518,7 +521,16 @@ class CudaGraphRunner:
|
||||
logger.info(log_message)
|
||||
|
||||
def _capture_graph(self, graph, pool, stream, run_once_fn):
|
||||
with self.device_module.graph(graph, pool=pool, stream=stream):
|
||||
memory_saver_adapter = TorchMemorySaverAdapter.create(
|
||||
enable=self.model_runner.server_args.enable_memory_saver
|
||||
and get_bool_env_var("SGLANG_MEMORY_SAVER_CUDA_GRAPH")
|
||||
)
|
||||
graph_fn = (
|
||||
partial(memory_saver_adapter.cuda_graph, tag=GPU_MEMORY_TYPE_CUDA_GRAPH)
|
||||
if memory_saver_adapter.enabled
|
||||
else self.device_module.graph
|
||||
)
|
||||
with graph_fn(cuda_graph=graph, pool=pool, stream=stream):
|
||||
out = run_once_fn()
|
||||
return out
|
||||
|
||||
|
||||
Reference in New Issue
Block a user