From b60444c62169c7992b98f102cbc4e86d9d117294 Mon Sep 17 00:00:00 2001 From: ix-48 <90045377+ix-48@users.noreply.github.com> Date: Tue, 13 Oct 2026 03:31:18 +0800 Subject: [PATCH] Fix autograd retention in CUDA graph capture tail hooks (#43854) --- python/sglang/srt/managers/scheduler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/sglang/srt/managers/scheduler.py b/python/sglang/srt/managers/scheduler.py index 61f2dc08a1..97e19ff859 100644 --- a/python/sglang/srt/managers/scheduler.py +++ b/python/sglang/srt/managers/scheduler.py @@ -1086,6 +1086,9 @@ class Scheduler( if self.draft_worker is not None: self.draft_worker.init_attention_backends() + # Not DynamicGradMode: tensors created under inference mode here could not + # be written in place by the no_grad disagg event loops. + @torch.no_grad() def init_all_cuda_graphs(self): """Capture cuda graphs for all workers.""" self.tp_worker.init_cuda_graphs()