[Fix] weight_checker: Make the checksum device-agnostic (#45918)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HEJIAN SANG
2026-10-22 16:57:49 -07:00
committed by GitHub
co-authored by Claude Opus 5.5
parent bb9e9d5632
commit 77f90ade97
2 changed files with 35 additions and 2 deletions
+3 -2
View File
@@ -9,6 +9,7 @@ from pydantic import BaseModel, ConfigDict
from sglang.srt.managers.mm_utils import tensor_hash
from sglang.srt.mem_cache.storage.mmap.mmap_allocator import alloc_mmap
from sglang.srt.platforms import current_platform
from sglang.srt.runtime_context import get_parallel
from sglang.srt.utils.weight_checker_comparator import (
CHUNK_NUMEL,
@@ -205,7 +206,7 @@ class WeightChecker:
def _compute_checksum(
self, skip_tensor_list: Optional[List[str]] = None, *, role: str
) -> Dict:
torch.cuda.synchronize()
current_platform.synchronize()
start = time.perf_counter()
quantized_set = _build_quantized_set(self._get_model())
@@ -222,7 +223,7 @@ class WeightChecker:
overall = overall_checksum(checksums)
torch.cuda.synchronize()
current_platform.synchronize()
elapsed = time.perf_counter() - start
logger.info(
f"[WeightChecker] checksum computed for {len(checksums)} tensors in {elapsed:.3f}s"
@@ -0,0 +1,32 @@
"""WeightChecker checksum on a non-CUDA device (CPU stands in for TPU)."""
import unittest
from unittest.mock import patch
import torch
from torch import nn
from sglang.srt.utils.weight_checker import ChecksumInfo, WeightChecker
from sglang.test.ci.ci_register import register_cpu_ci
from sglang.test.test_utils import CustomTestCase, enter_scope, published_topology
register_cpu_ci(est_time=5, suite="base-a-test-cpu")
class TestChecksumWithoutCuda(CustomTestCase):
def test_checksum_does_not_require_cuda(self):
"""The checksum action must work on hosts without CUDA, e.g. TPU engines
checked by an RL trainer after every weight update."""
model = nn.Linear(4, 4)
enter_scope(self, published_topology())
checker = WeightChecker(get_model=lambda: model)
with patch.object(
torch.cuda, "synchronize", side_effect=RuntimeError("no CUDA device")
):
out = checker.handle("checksum", role="target")
info = ChecksumInfo.model_validate(out)
self.assertEqual(set(info.checksums), {"weight", "bias"})
if __name__ == "__main__":
unittest.main()