Skip to content
Open
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
12 changes: 8 additions & 4 deletions python/sglang/srt/model_executor/model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
MultiprocessingSerializer,
cpu_has_amx_support,
dynamic_import,
empty_context,
enable_show_time_cost,
get_available_gpu_memory,
get_cpu_ids_by_node,
Expand Down Expand Up @@ -1858,12 +1859,14 @@ def _flashinfer_autotune(self):

logger.info("Running FlashInfer autotune...")

with torch.inference_mode(), autotune():
self._dummy_run(batch_size=self.req_to_token_pool.size)
self._dummy_run(
batch_size=self.req_to_token_pool.size,
run_ctx=autotune(),
)

logger.info("FlashInfer autotune completed.")

def _dummy_run(self, batch_size: int):
def _dummy_run(self, batch_size: int, run_ctx=None):
"""Run a dummy forward pass for warmup/profiling."""
if self.is_generation:
capture_forward_mode = ForwardMode.DECODE
Expand Down Expand Up @@ -2103,7 +2106,8 @@ def run_once():

torch.get_device_module(self.device).synchronize()
self.tp_group.barrier()
run_once()
with torch.inference_mode(), run_ctx or empty_context():
run_once()

def init_device_graphs(self):
"""Capture device graphs."""
Expand Down
Loading