diff --git a/test/registered/unit/mem_cache/test_cp_shared_kv_runtime.py b/test/registered/unit/mem_cache/test_cp_shared_kv_runtime.py index d6a7b0850..48d69e6b1 100644 --- a/test/registered/unit/mem_cache/test_cp_shared_kv_runtime.py +++ b/test/registered/unit/mem_cache/test_cp_shared_kv_runtime.py @@ -6,6 +6,20 @@ from unittest.mock import patch import torch +# Prefer the real compiled sgl_kernel when it is available (e.g. on a GPU box). +# The CPU-CI stubs below register torch.library ops and a sys.modules module stub +# at import time. If this module is imported before the real sgl_kernel loads, the +# empty stub permanently shadows it process-wide, so a later test that needs the +# genuine kernel (e.g. fast_topk_transform_ragged_fused) calls a None-returning +# lambda. Loading the real module first makes the FRAGMENT defines hit the +# already-registered path and keeps sys.modules["sgl_kernel"] pointing at the real +# module (setattr only fills genuinely-missing names). On CPU-CI the import fails +# and the stubs are built exactly as before. +try: + import sgl_kernel # noqa: F401 +except Exception: + pass + _sgl_kernel_lib = torch.library.Library("sgl_kernel", "FRAGMENT")