Files
sglang/test/registered/unit
LuminolT ebf11be355
Some checks failed
CI Failure Monitor / failure-analysis (push) Has been cancelled
Release PyPI Nightly Wheels / build-nightly-wheel (push) Has been cancelled
Release PyPI Nightly Wheels / release-nightly (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Nightly Release SGLang Model Gateway to PyPI / Upload to TestPyPI (push) Has been cancelled
CI Coverage Overview / Summary (push) Has been cancelled
CI Coverage Overview / Tests by Folder (push) Has been cancelled
CI Coverage Overview / Tests by Suite (push) Has been cancelled
CI Coverage Overview / Unit Test Code Coverage (push) Has been cancelled
CI Coverage Overview / JSON Export (push) Has been cancelled
Runner Utilization Report / Generate Report (push) Has been cancelled
Release Docker Images ROCm 7.2.0 Nightly Preview (AMD) / publish (all, gfx942-rocm720) (push) Has been cancelled
Release Docker Images ROCm 7.2.0 Nightly Preview (AMD) / publish (all, gfx950-rocm720) (push) Has been cancelled
Release Docker Images Nightly (AMD) / publish (all, gfx942) (push) Has been cancelled
Release Docker Images Nightly (AMD) / publish (all, gfx950) (push) Has been cancelled
Release Docker Images Nightly (AMD) / cache (all, gfx942) (push) Has been cancelled
AMD AITER Scout / resolve-aiter (push) Has been cancelled
AMD AITER Scout / call-nightly-amd (push) Has been cancelled
AMD AITER Scout / call-nightly-amd-rocm720 (push) Has been cancelled
AMD AITER Scout / call-pr-test-amd (push) Has been cancelled
AMD AITER Scout / call-pr-test-amd-rocm720 (push) Has been cancelled
AMD AITER Scout / check-all-jobs (push) Has been cancelled
Release Docker Images Nightly (NPU) / build (8.5.0, 910b) (push) Has been cancelled
Release Docker Images Nightly (NPU) / build (8.5.0, a3) (push) Has been cancelled
Build and Push Development Docker Images / build-dev (arm64, all, 1, linux/arm64, arm-docker-build-node, 12.9.1) (push) Has been cancelled
Build and Push Development Docker Images / build-dev (arm64-cu13, all, 1, linux/arm64, arm-docker-build-node, 13.0.1) (push) Has been cancelled
Build and Push Development Docker Images / build-dev (x86, all, 0, linux/amd64, x64-docker-build-node, 12.9.1) (push) Has been cancelled
Build and Push Development Docker Images / build-dev (x86-cu13, all, 0, linux/amd64, x64-docker-build-node, 13.0.1) (push) Has been cancelled
Build and Push Development Docker Images / create-manifests (map[arm64:arm64 base:dev x86:x86]) (push) Has been cancelled
Build and Push Development Docker Images / create-manifests (map[arm64:arm64-cu13 base:dev-cu13 x86:x86-cu13]) (push) Has been cancelled
Close Inactive Issues / close-inactive-issues (push) Has been cancelled
AMD CI Job Monitor / Custom Job Report (push) Has been cancelled
AMD CI Job Monitor / Parse Workflow Jobs (push) Has been cancelled
AMD CI Job Monitor / PR - ${{ matrix.job_name }} (push) Has been cancelled
AMD CI Job Monitor / Nightly - ${{ matrix.job_name }} (push) Has been cancelled
Weekly Test (Nvidia) / weekly-test-8-gpu-h200 (push) Has been cancelled
fix(moe): gate fp8 megamoe on deepgemm capability
Avoid entering the FP8 MegaMoE fused path when the installed DeepGEMM exposes fp8_mega_moe but cannot allocate an fp8xfp8 MegaMoE symmetric buffer. Current B300 sgl-deep-gemm asserts that MegaMoE buffer mma_type is fp8xfp4, so FP8 weights must fall back until dependency support lands.

Tested: PYTHONPYCACHEPREFIX=/private/tmp/sglang_pycache python3 -m py_compile python/sglang/srt/layers/moe/mega_moe.py test/registered/unit/moe/test_glm_megamoe.py

Tested: git diff --check

Remote-tested: root@95.133.252.48 B300 DeepGEMM capability probe showed fp8xfp8 MegaMoE buffer fails with mma_type_str == fp8xfp4.
2026-07-08 12:05:46 +08:00
..

Unit Tests

Component-level tests that do not launch a server or load model weights. Tests can use CPU or GPU — the key criterion is no server process.

Quick Start

  1. Find the source file under python/sglang/srt/.
  2. Create the corresponding test here, mirroring the source tree:
    srt/mem_cache/radix_cache.py       →  unit/mem_cache/test_radix_cache.py
    srt/sampling/sampling_params.py    →  unit/sampling/test_sampling_params.py
    
  3. Register for CI at the top of the file (after imports, before test classes):
    from sglang.test.ci.ci_register import register_cpu_ci
    register_cpu_ci(est_time=5, suite="stage-a-test-cpu")
    # or: register_cuda_ci(est_time=10, suite="stage-b-test-1-gpu-small")
    
  4. Run locally:
    pytest test/registered/unit/ -v            # all unit tests
    pytest test/registered/unit/mem_cache/ -v  # one module
    
  5. Run with coverage:
    # summary
    pytest test/registered/unit/ --cov --cov-config=.coveragerc -v
    
    # PR incremental check (require ≥60% on changed lines)
    pytest test/registered/unit/ --cov --cov-config=.coveragerc --cov-report=xml
    diff-cover coverage.xml --compare-branch=origin/main --fail-under=60
    

Example

"""Unit tests for <module> — no server, no model loading."""

from sglang.test.ci.ci_register import register_cpu_ci

register_cpu_ci(est_time=5, suite="stage-a-test-cpu")

import unittest

from sglang.srt.<module> import TargetClass
from sglang.test.test_utils import CustomTestCase


class TestTargetClass(CustomTestCase):
    def test_basic_behavior(self):
        obj = TargetClass(...)
        self.assertEqual(obj.method(), expected)


if __name__ == "__main__":
    unittest.main()

Rules

  • No popen_launch_server() or Engine(...).
  • No model weight loading.
  • Use CustomTestCase (from sglang.test.test_utils, adds CI retry).
  • Use unittest.mock for dependencies that are expensive to construct.