From d48ab2d386e0287f471d5fafd1e39f35de148eed Mon Sep 17 00:00:00 2001 From: Mohammad Miadh Angkad <176301910+mmangkad@users.noreply.github.com> Date: Mon, 3 Aug 2026 16:53:16 +0800 Subject: [PATCH] Fix BCG circular import during server startup (#33371) --- python/sglang/srt/layers/cp/bcg.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/sglang/srt/layers/cp/bcg.py b/python/sglang/srt/layers/cp/bcg.py index ed6ea4b79..f657eca8e 100644 --- a/python/sglang/srt/layers/cp/bcg.py +++ b/python/sglang/srt/layers/cp/bcg.py @@ -28,7 +28,6 @@ from sglang.srt.layers.cp.utils import ( prepare_cp_forward, ) from sglang.srt.model_executor.forward_batch_info import PPProxyTensors -from sglang.srt.model_executor.runner.shape_key import ShapeKey if TYPE_CHECKING: from sglang.srt.model_executor.forward_batch_info import ForwardBatch @@ -197,6 +196,12 @@ def execute_prefill_cp_bcg( **kwargs, ): """Replay a CP-local body and run the global gather/logits tail eagerly.""" + # Importing a runner submodule while server arguments are being resolved + # executes runner/__init__.py, which imports this module through the prefill + # runner. Defer the runtime-only dependency until runner initialization has + # completed to keep the server-argument compatibility check acyclic. + from sglang.srt.model_executor.runner.shape_key import ShapeKey + cp_input = runner.prefill_cp_bcg_input assert cp_input is not None model = runner.model_runner.model