repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
sglang
test/registered/unit/layers/test_fp8_bpreshuffle_scale.py
.py
import unittest from unittest.mock import patch import torch from sglang.srt.layers.quantization.fp8_utils import ( materialize_bpreshuffle_fp8_scale, materialize_bpreshuffle_fp8_scale_tuple, view_aiter_fused_rms_transposed_fp8_scale, ) from sglang.test.ci.ci_register import register_cpu_ci from sglang.te...
107
4,608
sglang
test/registered/unit/layers/test_radix_attention.py
.py
"""CPU unit tests for the graph-safe ``RadixAttention`` interface.""" import unittest from contextlib import ExitStack from types import SimpleNamespace from unittest.mock import patch import torch import sglang.srt.layers.radix_attention as radix_attention_module from sglang.srt.layers.radix_attention import RadixA...
323
12,004
sglang
test/registered/unit/layers/test_conv_layer.py
.py
from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=7, suite="base-a-test-cpu") import unittest import torch import torch.nn as nn from sglang.srt.layers.conv import Conv2dLayer, Conv3dLayer def _copy_weights(src, dst_nn): """Copy weights from Conv*dLayer to nn.Conv*d for compariso...
364
13,127
sglang
test/registered/unit/layers/test_dsv4_nonpaged_indexer.py
.py
import sys import unittest from types import SimpleNamespace from unittest.mock import MagicMock, patch import torch from sglang.srt.environ import envs from sglang.srt.layers.attention.dsv4.indexer import FP8_DTYPE, C4IndexerBackendMixin from sglang.srt.layers.attention.dsv4.metadata import ( NonPagedIndexerPlan...
325
13,965
sglang
test/registered/unit/layers/test_logprob_chunk_stitching.py
.py
"""Chunked input-logprob processing must match the non-chunked reference. Regression for the cross-chunk stitching accounting: zero-logprob-row sequences (logprob opt-outs in mixed batches, mid-chunked-prefill segments) were skipped or double-emitted, drifting the per-request entry counts that the scheduler asserts on...
142
5,343
sglang
test/registered/unit/layers/quantization/test_int8_linear_methods.py
.py
"""Numerics for the INT8 dense-linear methods. Real layer path vs a dequantized-reference matmul, in two formats: channel W8A8 (W8A8Int8LinearMethod, per-channel weight scale + dynamic per-token int8 activations) and blockwise (BlockInt8LinearMethod, (128, 128) block weight scale). """ import unittest import torch ...
127
4,336
sglang
test/registered/unit/layers/quantization/test_nvfp4_moe_backends.py
.py
"""Numerics for the NVFP4 FusedMoE runner backends (--moe-runner-backend). Real FusedMoE path (NVFP4 checkpoint shards through the real weight_loader -> weight processing -> forward) per backend vs a dequantized torch MoE reference. Single GPU, tp=ep=1. """ import unittest import torch from sglang.srt.layers.moe.ut...
158
6,330
sglang
test/registered/unit/layers/quantization/test_modelopt_nvfp4_moe_scales.py
.py
"""CPU unit tests for NVFP4 fused-MoE GEMM1 global-scale handling. w13 fuses the gate (w1) and up (w3) projections, which can carry separate NVFP4 weight scales. These tests pin the two helpers that handle that: the gate/up split in _compute_gemm1_alphas and the TRT-LLM up-half output scalar in _compute_g1_scale_c. Bo...
309
14,257
sglang
test/registered/unit/layers/quantization/test_compressed_tensors_mixed_precision.py
.py
"""CPU regression tests for multi-group ("mixed-precision") compressed-tensors configs. Such a checkpoint used to load completely unquantized. ``ignore`` was matched by substring, so a parent module entry swallowed its quantized children, and the activation-quantization gate read the top-level format -- which compress...
193
6,647
sglang
test/registered/unit/layers/quantization/test_fp8_utils_mxfp4.py
.py
import unittest import torch from sglang.srt.layers.quantization.fp8_utils import ( quantize_block_fp8_weight_to_mxfp4, ) from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=4, suite="base-a-test-cpu") class TestFp8UtilsMxfp4(unittest.TestCase): def test_quantize_block_fp8_weigh...
51
1,701
sglang
test/registered/unit/layers/quantization/test_nvfp4_linear_backends.py
.py
"""Numerics for the NVFP4 dense-linear GEMM backends (--fp4-gemm-backend). Real layer path (ColumnParallelLinear -> weight_loader -> weight processing -> forward) per SM100 backend vs a dequantized-reference matmul; a merged two-shard case guards the per-partition scale gathering of fused layers. """ import unittest ...
176
6,168
sglang
test/registered/unit/layers/quantization/test_fp8_blockwise_linear_backends.py
.py
"""Numerics for the FP8 dense-linear GEMM backends (--fp8-gemm-backend). Real layer path vs a dequantized-reference matmul, in three formats: FP8 blockwise, MXFP8, and per-tensor FP8 (auto dispatch). Backend sets adapt to the device SM, so one file covers SM90 / SM100 / SM120. """ import unittest from unittest import...
271
9,688
sglang
test/registered/unit/layers/quantization/test_mxfp4_sm120_cutlass.py
.py
"""SM120 FlashInfer MXFP8-by-MXFP4 MoE integration test.""" from __future__ import annotations import builtins import importlib import sys from contextlib import nullcontext from types import SimpleNamespace import pytest import torch from sglang.test.ci.ci_register import register_cuda_ci register_cuda_ci(est_tim...
438
15,582
sglang
test/registered/unit/layers/quantization/test_fp8_kernel_hip_max.py
.py
"""AMD/gfx950 (MI355X) test for the ROCm fp8 range used by per-token-group quant. ROCm fp8 is device-dependent: e4m3fnuz (max 224.0) on gfx94x (MI300) vs e4m3fn (max 448.0) on gfx95x (MI355X). ``_per_token_group_quant_8bit_raw`` previously hardcoded 224.0 for *all* ROCm devices, which silently halved the usable fp8 ra...
62
2,431
sglang
test/registered/unit/layers/quantization/test_deepgemm_ue8m0_requant.py
.py
"""CPU guards for DeepGEMM UE8M0 weight-scale requantization decisions.""" from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=5, suite="base-a-test-cpu") import unittest from unittest.mock import call, patch import torch from compressed_tensors.quantization import QuantizationStrategy ...
223
7,906
sglang
test/registered/unit/layers/quantization/test_fp4_kv_cache_quant_method.py
.py
"""Unit tests for FP4 KV cache quantization strategy pattern - no server, no model loading.""" from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=5, suite="base-a-test-cpu") import unittest import torch from sglang.test.test_utils import CustomTestCase def skip_if_no_blackwell_nvfp4(...
315
11,876
sglang
test/registered/unit/layers/quantization/test_quark_config.py
.py
"""Unit tests for QuarkConfig — CPU-only, no model loading.""" from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=5, suite="base-a-test-cpu") import unittest from unittest.mock import patch import torch from sglang.srt.layers.quantization.quark.quark import ( QuarkConfig, _buil...
212
8,891
sglang
test/registered/unit/layers/quantization/test_mxfp4_sm90_cutlass.py
.py
"""Unit test for the SM90 cutlass MXFP4 path in :class:`Mxfp4MoEMethod`. Builds a single-layer GPT-OSS-style MoE with random MXFP4 weights, drives the SGLang plumbing (``_process_weights_for_sm90_cutlass`` + ``_apply_sm90_cutlass``) and compares against a direct FlashInfer ``cutlass_fused_moe`` call with the same inpu...
590
21,675
sglang
test/registered/unit/layers/quantization/test_modelopt_nvfp4.py
.py
import unittest from unittest.mock import patch import torch import torch.nn as nn from sglang.srt.layers.linear import MergedColumnParallelLinear, QKVParallelLinear from sglang.srt.layers.parameter import PerTensorScaleParameter from sglang.srt.layers.quantization.modelopt_quant import ( ModelOptFp4Config, M...
138
4,892
sglang
test/registered/unit/layers/quantization/test_compressed_tensors_wna16_moe_no_linear.py
.py
"""CPU regression test for WNA16 compressed-tensors MoE with no "Linear" group. CompressedTensorsWNA16MoE used to read ``target_scheme_map["Linear"]`` in its constructor. That raised ``KeyError: 'Linear'`` for compressed-tensors MoE checkpoints whose ``config_groups`` only target the expert projections through a regex...
119
4,874
sglang
test/registered/unit/layers/quantization/test_quark_utils.py
.py
"""Unit tests for sglang.srt.layers.quantization.quark.utils — CPU-only, no model loading.""" from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=5, suite="base-a-test-cpu") import unittest import torch from sglang.srt.layers.quantization.quark.utils import e8m0_to_f32 from sglang.test....
71
2,664
sglang
test/registered/unit/layers/quantization/test_flashinfer_trtllm_fp8_fallback.py
.py
"""Unit test for the FlashInfer TRTLLM block-FP8 GEMM fallback decision. Regression guard for two coupled behaviors in ``flashinfer_gemm_w8a8_block_fp8_linear_with_fallback``: * DeepSeek-R1 perf regression (commit 5da265de): with ``--fp8-gemm-backend flashinfer_trtllm`` the dense block-FP8 weight scales are plain...
104
4,333
sglang
test/registered/unit/layers/moe/test_aiter_runner.py
.py
import sys from types import ModuleType, SimpleNamespace import pytest import torch import sglang.srt.layers.moe.moe_runner.aiter as aiter_runner from sglang.srt.layers.moe.moe_runner.aiter import ( AiterMoeQuantInfo, AiterQuantType, AiterRunnerCore, AiterRunnerInput, ) from sglang.srt.layers.moe.moe_...
120
3,936
sglang
test/registered/unit/layers/moe/test_copy_weight_views_before_h2d.py
.py
import torch from sglang.srt.layers.moe.fused_moe_triton.layer import ( _copy_weight_view_before_h2d, ) from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=2, suite="base-a-test-cpu") def _assert_independent_copy(source: torch.Tensor, result: torch.Tensor) -> None: assert torch.e...
51
1,577
sglang
test/registered/unit/layers/moe/test_w4afp8_deepep_post_reorder.py
.py
"""Regression test for W4AFP8 DeepEP-normal post-reorder scaling.""" import sys import unittest from types import ModuleType, SimpleNamespace from unittest.mock import Mock, patch import torch from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.test_utils import CustomTestCase register_cpu_ci(es...
146
4,976
sglang
test/registered/unit/layers/moe/test_w4afp8_deepep_dtype.py
.py
"""CPU regressions for W4AFP8 DeepEP dispatcher dtypes.""" import unittest from types import SimpleNamespace from unittest.mock import Mock, patch import torch from sglang.srt.layers.moe import utils as moe_utils from sglang.srt.layers.moe.token_dispatcher import deepep from sglang.srt.layers.moe.utils import ( ...
125
4,446
sglang
test/registered/unit/layers/moe/test_fused_moe_triton_config.py
.py
import json from pathlib import Path from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=3, suite="base-a-test-cpu") from sglang.srt.layers.moe.moe_runner.triton_utils import fused_moe_triton_config from sglang.srt.runtime_context import get_context def test_h200_bf16_config_is_availab...
58
1,825
sglang
test/registered/unit/layers/moe/test_hpc_ops_runner_guard.py
.py
"""The hpc_ops MoE runner backend makes the standard dispatcher keep global expert ids, so a quant method that silently falls back to another runner (e.g. an unquantized MoE) would misroute tokens under EP>1. MoeRunner must reject that combination loudly at startup. """ import sys import pytest from sglang.srt.layer...
64
2,413
sglang
test/registered/unit/layers/moe/test_fused_shared_expert_scaling.py
.py
"""Unit tests for fused shared-expert weight scaling on per-rank shared slots. These tests pin the contract of ``remap_topk_for_per_rank_shared_slots`` for the fused shared expert's topk weight on the two paths this fix covers: * aiter (HIP) path: routed_scaling_factor is folded into the routed weights and the ...
118
4,800
sglang
test/registered/unit/layers/moe/test_fused_moe_common_utils.py
.py
import importlib.util from pathlib import Path from types import SimpleNamespace from unittest.mock import patch import torch from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=3, suite="base-a-test-cpu") def _load_common_utils(): source = ( Path(__file__).resolve().parents...
62
1,673
sglang
test/registered/unit/layers/attention/test_vision_seqlens.py
.py
import pytest import torch from sglang.srt.layers.attention.vision import SingletonCache, resolve_max_seqlen from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=2, suite="base-a-test-cpu") def test_resolve_max_seqlen_accepts_raw_tensor_without_attribute_cache(): cu_seqlens = torch.te...
26
738
sglang
test/registered/unit/layers/attention/test_kda_helion_dispatcher.py
.py
import unittest from unittest.mock import ANY, MagicMock, patch import torch from sglang.srt.layers.attention.linear.kda_backend import KDAKernelDispatcher from sglang.srt.layers.attention.linear.kernels.kda_helion import HelionKDAKernel from sglang.srt.layers.attention.linear.kernels.kda_triton import TritonKDAKerne...
198
7,396
sglang
test/registered/unit/layers/attention/test_flashattention_pa_swa_prefill_lens_size.py
.py
"""Regression test for PR #32208 / base-b-test-1-gpu-large CI failure. FlashAttentionBackend's prefill-aware-SWA scratch buffer (``_pa_swa_prefill_lens``) is indexed directly by raw ``req_pool_idx`` values (``self._pa_swa_prefill_lens[forward_batch.req_pool_indices[:batch_size]] = ...``), not by batch position. ``ReqT...
111
4,719
sglang
test/registered/unit/layers/attention/test_verify_mask.py
.py
import unittest from types import SimpleNamespace import torch from sglang.srt.layers.attention.hybrid_attn_backend import HybridAttnBackend from sglang.srt.layers.attention.verify_mask import ( VerifyMask, maybe_create_verify_mask, tree_mask_numel, ) from sglang.srt.speculative.eagle_utils import TreeMas...
177
6,090
sglang
test/registered/unit/layers/attention/test_linear_attn_config.py
.py
"""Each runner carries its own linear-attn kernel choice. A target and its draft coexist in one process and can want different kernels: only the runner whose model is GDN gets the SM100 FlashInfer prefill default, and the operator's explicit flag applies to the launch. So the choice is a per-runner stamp read from the...
162
6,909
sglang
test/registered/unit/layers/attention/test_gdn_prefill_backend_policy.py
.py
import unittest from types import SimpleNamespace from unittest.mock import MagicMock, patch, sentinel import torch from sglang.srt.layers.attention.hybrid_linear_attn_backend import ( MambaAttnBackendBase, ) from sglang.srt.layers.attention.linear import gdn_backend from sglang.srt.layers.attention.linear.gdn_ba...
252
9,810
sglang
test/registered/unit/layers/attention/test_index_topk_share.py
.py
import sys from types import SimpleNamespace import pytest import torch from sglang.srt.layers.attention.index_topk_share import IndexTopKShareState from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=2, suite="base-a-test-cpu") def _batch( reuse: bool, carried, *, is_extend: bool =...
164
5,149
sglang
test/registered/unit/layers/attention/test_vision_backend_selection.py
.py
import sys from types import SimpleNamespace from unittest.mock import Mock import pytest import torch import torch.nn.functional as F from einops import rearrange from sglang.srt.layers.attention import vision from sglang.test.ci.ci_register import register_cpu_ci, register_npu_ci register_cpu_ci(est_time=2, suite=...
153
4,370
sglang
test/registered/unit/layers/attention/test_vision_max_seqlen.py
.py
import sys import pytest import torch from torch import nn from sglang.srt.layers.attention import vision from sglang.srt.models import kimi_k25 from sglang.srt.models.kimi_k25 import MoonViT3dEncoder, MoonViTEncoderLayer from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=1, suite="base-...
242
7,704
sglang
test/registered/unit/layers/attention/linear/kernels/test_kda_nvidia.py
.py
"""Unit tests for the NVIDIA KDA prefill routing/repacking wrapper.""" import unittest from unittest.mock import Mock, patch import torch from sglang.srt.layers.attention.linear.kernels.kda_nvidia import ( NvidiaKDAKernel, _from_nvidia_kda_state_layout, _to_nvidia_kda_state_layout, ) from sglang.test.ci....
203
7,242
sglang
test/registered/unit/entrypoints/test_server_info.py
.py
"""Endpoint-level tests for `/server_info`. `/server_info` is the introspection surface that external consumers (SGLang's own deprecated `/get_server_info` alias, monitoring tools, KV-aware routers) scrape to learn about the running server's configuration. New `/server_info` behaviours should add their test classes to...
347
12,936
sglang
test/registered/unit/entrypoints/test_grpc_bridge.py
.py
import asyncio import enum import unittest from types import SimpleNamespace from sglang.srt.entrypoints.grpc_bridge import RuntimeHandle from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.test_utils import CustomTestCase register_cpu_ci(est_time=1, suite="base-a-test-cpu") class _ChunkStatus(e...
116
3,289
sglang
test/registered/unit/entrypoints/test_ssl_cert_refresher.py
.py
import asyncio import os import tempfile import unittest from unittest.mock import MagicMock from sglang.srt.entrypoints.ssl_utils import SSLCertRefresher from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.test_utils import CustomTestCase register_cpu_ci(est_time=14, suite="base-a-test-cpu") de...
166
5,259
sglang
test/registered/unit/entrypoints/test_http2_server_config.py
.py
import importlib.util import unittest from unittest.mock import patch from sglang.srt.entrypoints.http_server import _run_granian_server from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=2, suite="base-a-test-cpu") @unittest.skipUnless( importlib.util.find_spec("granian"), "granian...
41
1,115
sglang
test/registered/unit/entrypoints/test_server_warmup.py
.py
"""Unit tests for model-specific server warmup inputs.""" import base64 import struct import unittest from sglang.srt.entrypoints.http_server import ( KIMI_K3_VLM_WARMUP_PNG_PICTURE_BASE64, KIMI_VLM_WARMUP_PNG_PICTURE_BASE64, MINIMUM_PNG_PICTURE_BASE64, _get_vlm_warmup_image_base64, ) from sglang.test...
60
2,074
sglang
test/registered/unit/entrypoints/test_v1_loads_aggregate.py
.py
"""Unit tests for /v1/loads load snapshot response behavior.""" import asyncio import os import tempfile import unittest from types import SimpleNamespace from unittest import mock import msgspec.msgpack from sglang.srt.entrypoints import v1_loads from sglang.srt.entrypoints.v1_loads import get_loads from sglang.srt...
229
7,479
sglang
test/registered/unit/entrypoints/test_http_server_warmup.py
.py
import asyncio import unittest from types import SimpleNamespace from unittest.mock import patch from sglang.srt.disaggregation.utils import FAKE_BOOTSTRAP_HOST from sglang.srt.entrypoints.http_server import ( _send_disaggregation_warmup_requests, ) from sglang.test.ci.ci_register import register_cpu_ci register_...
84
2,851
sglang
test/registered/unit/entrypoints/openai/test_serving_responses_stream.py
.py
import unittest from unittest.mock import patch from utils import ( StreamFixture, engine_chunk, event_payloads, event_types, find_completed_event, make_serving, ) from sglang.srt.entrypoints.openai.protocol import ResponsesRequest from sglang.test.ci.ci_register import register_cpu_ci from sg...
318
11,680
sglang
test/registered/unit/entrypoints/openai/test_serving_completions.py
.py
""" Unit-tests for the refactored completions-serving handler (no pytest). Run with: python -m unittest tests.test_serving_completions_unit -v """ from sglang.test.test_utils import maybe_stub_sgl_kernel maybe_stub_sgl_kernel() # must precede any import that pulls in sgl_kernel import json import unittest from ...
475
18,063
sglang
test/registered/unit/entrypoints/openai/utils.py
.py
"""Stub CUDA-only deps before importing sglang.srt serving modules. Must be imported first by every /v1/responses test that runs on CPU.""" try: import torch _ORIGINAL_TORCH_COMPILE = torch.compile def _identity_compile(fn=None, **kwargs): if fn is None: return lambda inner_fn: inner_...
169
5,351
sglang
test/registered/unit/entrypoints/openai/test_protocol.py
.py
# Copyright 2023-2024 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
712
28,044
sglang
test/registered/unit/entrypoints/openai/test_serving_chat.py
.py
""" Unit-tests for OpenAIServingChat -- rewritten to use only the std-lib 'unittest'. Run with either: python tests/test_serving_chat_unit.py -v or python -m unittest discover -s tests -p "test_*unit.py" -v """ from sglang.test.test_utils import maybe_stub_sgl_kernel maybe_stub_sgl_kernel() # must precede an...
3,201
127,268
sglang
test/registered/unit/entrypoints/openai/test_matched_stop.py
.py
import unittest from sglang.srt.sampling.sampling_params import MAX_LEN, get_max_seq_length from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=6, suite="base-a-test-cpu") class TestRegexPatternMaxLength(unittest.TestCase): @classmethod def setUpClass(cls): cls.regex_str_...
59
2,331
sglang
test/registered/unit/entrypoints/openai/test_serving_embedding.py
.py
""" Unit tests for the OpenAIServingEmbedding class from serving_embedding.py. """ import base64 import importlib import importlib.abc import importlib.machinery import struct import sys import types import unittest import uuid from unittest.mock import MagicMock, Mock import jinja2 # Stub out sgl_kernel (and all s...
370
14,725
sglang
test/registered/unit/entrypoints/openai/test_serving_transcription.py
.py
"""Unit tests for OpenAIServingTranscription's streaming fused-autodetect path. Exercises the streaming handler: buffer deltas until the forced-prefix sentinel lands, emit the scrubbed user-visible text, and never leak Whisper special tokens. Covers both streaming modes — cumulative (``incremental_streaming_output=Fal...
738
30,148
sglang
test/registered/unit/entrypoints/openai/test_whisper_adapter.py
.py
"""Unit tests for the Whisper transcription adapter. Focused on ``WhisperAdapter.parse_fused_output`` — a pure static method that parses the fused auto-detect output into ``(language, user_visible_text)``. ``visible=None`` means "forced prefix not yet locatable; streaming callers should keep buffering, non-streaming c...
388
17,131
sglang
test/registered/unit/entrypoints/openai/test_audio_chunking.py
.py
"""Unit tests for energy-aware audio chunking (long-audio transcription). Whisper's encoder window is 30 s; longer audio must be split before prompting. The splitter must cut at low-energy points (pauses) inside the tail search window of each stride — never blindly at the stride boundary, which could land mid-word — a...
123
4,870
sglang
test/registered/unit/entrypoints/openai/test_serving_responses.py
.py
import asyncio import unittest from unittest.mock import Mock, patch from openai.types.responses import ( ResponseOutputMessage, ResponseOutputText, ResponseReasoningItem, ) from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall from utils import make_serving from sglang.s...
956
34,262
sglang
test/registered/unit/entrypoints/openai/test_exa_search.py
.py
import asyncio import os import unittest from unittest.mock import patch from utils import make_serving from sglang.srt.entrypoints.openai.protocol import ResponsesRequest from sglang.srt.entrypoints.openai.tool_server import NativeToolServer from sglang.srt.entrypoints.search.exa_client import ( EXA_INTEGRATION_...
304
10,756
sglang
test/registered/unit/entrypoints/openai/test_responses_protocol.py
.py
import json import unittest from utils import make_serving # noqa: F401 — bootstrap import from sglang.srt.entrypoints.openai.protocol import ( PromptTokensDetails, ResponsesRequest, ResponsesResponse, UsageInfo, ) from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.test_utils imp...
411
15,520
sglang
test/registered/unit/entrypoints/anthropic/test_serving.py
.py
import asyncio import json import unittest from types import SimpleNamespace from sglang.test.test_utils import maybe_stub_sgl_kernel maybe_stub_sgl_kernel() # must precede imports that may pull in sgl_kernel from fastapi.responses import JSONResponse # noqa: E402 from jinja2 import Environment # noqa: E402 from...
1,577
64,888
sglang
test/registered/unit/scripted_runtime/test_scripted_runtime_utils.py
.py
from __future__ import annotations import json import os import sys import unittest from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.scripted_runtime.utils import ensure_script_importable, resolve_fn from sglang.test.test_utils import CustomTestCase register_cpu_ci(est_time=2, suite="base-a-te...
80
2,371
sglang
test/registered/unit/scripted_runtime/test_background_http_poster.py
.py
from __future__ import annotations import asyncio import threading import unittest from concurrent.futures import Future from unittest.mock import MagicMock from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.scripted_runtime import background_http_poster as bg_poster from sglang.test.scripted_run...
181
5,778
sglang
test/registered/unit/scripted_runtime/test_tokenizer_recv_proxy.py
.py
from __future__ import annotations from collections import deque from dataclasses import dataclass import zmq from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.scripted_runtime.tokenizer_recv_proxy import ( ScriptedTokenizerRecvProxy, ) from sglang.test.test_utils import CustomTestCase reg...
160
5,257
sglang
test/registered/unit/scripted_runtime/test_http_server.py
.py
from __future__ import annotations import threading import unittest import uuid import zmq from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.scripted_runtime.http_server import ScriptedHttpServer from sglang.test.scripted_runtime.io_struct import ( HookReady, RunScript, ScriptFailed...
151
5,007
sglang
test/registered/unit/scripted_runtime/test_scheduler_hook.py
.py
from __future__ import annotations import unittest from unittest.mock import MagicMock from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.scripted_runtime import scheduler_hook from sglang.test.test_utils import CustomTestCase register_cpu_ci(est_time=10, suite="base-a-test-cpu") def _yielding...
57
1,583
sglang
test/registered/unit/distributed/test_cuda_wrapper.py
.py
import io import pytest from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=2, suite="base-a-test-cpu") from sglang.srt.distributed.device_communicators import cuda_wrapper def test_find_loaded_library_prefers_real_cudart_over_tilelang_stub(monkeypatch): maps = """\ 7f000000-7f0100...
39
1,093
sglang
test/registered/unit/distributed/test_parallel_state.py
.py
""" Test file to verify the correctness of parallel group calculations. This test validates that the parallel group initialization creates the correct groups for different parallelism configurations including: - Tensor parallelism (TP) - Pipeline parallelism (PP) - Attention context parallelism (attn_cp) - Attention d...
359
12,838
sglang
test/registered/unit/distributed/test_get_default_distributed_backend.py
.py
"""Unit tests for sglang.srt.distributed.parallel_state — no server, no model loading.""" import unittest import sglang.srt.platforms as platforms_mod from sglang.srt.distributed.parallel_state import get_default_distributed_backend from sglang.srt.platforms.interface import SRTPlatform from sglang.test.ci.ci_registe...
78
3,182
sglang
test/registered/unit/batch_invariant_ops/test_batch_invariant_ops.py
.py
# Adapted from https://github.com/thinking-machines-lab/batch_invariant_ops/blob/main/test_batch_invariance.py import math import unittest import torch from sglang.srt.batch_invariant_ops import batch_invariant_ops from sglang.srt.batch_invariant_ops.batch_invariant_ops import set_batch_invariant_mode from sglang.tes...
250
9,992
sglang
test/registered/unit/model_executor/test_prefill_cuda_graph_runner.py
.py
"""CPU coverage for chunked-prefix Full prefill CUDA-graph state.""" import unittest from types import SimpleNamespace from unittest.mock import patch import torch import sglang.srt.model_executor.model_runner_components.cuda_graph_setup as graph_setup import sglang.srt.model_executor.runner.prefill_cuda_graph_runne...
355
13,620
sglang
test/registered/unit/model_executor/test_prefill_cuda_graph_runner_helpers.py
.py
"""Unit tests for prefill CUDA graph wrapper helpers.""" import unittest from types import SimpleNamespace from sglang.srt.model_executor.runner.prefill_cuda_graph_runner import ( _resolve_transformer_layer_model, ) from sglang.srt.model_loader.utils import resolve_language_model from sglang.test.ci.ci_register i...
64
2,260
sglang
test/registered/unit/model_executor/test_chunked_prefix_cache_gate.py
.py
"""The load-time chunked-prefix gate must land on the published config bag. Regression: the gate wrote the ServerArgs instance while every attention backend reads ``get_schedule().disable_chunked_prefix_cache`` — the bag never saw the flip, so an unsupported backend kept chunked prefix enabled. """ from sglang.test.c...
67
3,017
sglang
test/registered/unit/model_executor/test_cuda_graph_buffer_registry.py
.py
"""Unit tests for ``cuda_graph_buffer_registry`` — CPU-only. Covers: * ``GraphSlot`` shape / axis / device validation. * ``register_slot`` allocation + ``FILL_SENTINEL`` init. * ``fill_from`` D2D copy across all four ``PaddingPolicy`` modes. * ``extract_buffer`` returns a ``ForwardBatch`` view backed by slot ...
1,419
55,206
sglang
test/registered/unit/model_executor/test_hisparse_pool_configurator.py
.py
import unittest from types import SimpleNamespace from unittest.mock import MagicMock import torch from sglang.srt.model_executor.pool_configurator import DefaultPoolConfigurator from sglang.srt.runtime_context import get_parallel from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.test_utils impo...
77
2,646
sglang
test/registered/unit/model_executor/test_pool_configurator.py
.py
"""Unit tests for pool_configurator.py -- CPU only, no GPU required. Tests the end-to-end computation: available_bytes -> MemoryPoolConfig, verifying tokens are correct, constraints are respected, and memory invariants hold (tokens * per_token_cost <= available_bytes). """ import contextlib import unittest from types...
770
29,621
sglang
test/registered/unit/model_executor/test_forward_metadata_plan_record.py
.py
"""Unit tests for the ForwardBatch attention plan marker / plan record. Covers the contract behind ``skip_attn_backend_init`` deprecation: * fresh batches need planning; marked batches don't * the plan record (planned bs / num tokens) snapshots mark-time shapes * reshape after marking triggers a re-plan only for...
128
5,189
sglang
test/registered/unit/model_executor/test_mlp_sync_pad_unpad.py
.py
"""Unit tests for the DP-attention MLP-sync pad/unpad round-trip. ``prepare_mlp_sync_batch`` pads per-request tensors (positions / seq_lens / req_pool_indices) by appending dummy rows after the real ones so all DP ranks agree on tensor shapes. ``post_forward_mlp_sync_batch`` must slice them back so post-forward consum...
176
6,955
sglang
test/registered/unit/model_executor/runner/test_decode_cuda_graph_runner.py
.py
"""Unit tests for ``DecodeCudaGraphRunner`` capture-phase profiling — CPU-only. Two capture-trace modes plus their precedence: * **Original single-trace** (``SGLANG_ENABLE_CUDA_GRAPH_CAPTURE_TRACE``): ``_init_profile_context_and_memory_record`` builds an *unscheduled* profiler (``record_shapes`` only, no sc...
295
13,009
sglang
test/registered/unit/model_executor/runner/test_prefill_cuda_graph_padding.py
.py
import unittest from types import SimpleNamespace from sglang.srt.model_executor.cuda_graph_config import Backend from sglang.srt.model_executor.forward_batch_info import ( CaptureHiddenMode, ForwardMode, ) from sglang.srt.model_executor.runner.prefill_cuda_graph_runner import ( PrefillCudaGraphRunner, ) f...
58
1,875
sglang
test/registered/unit/model_executor/runner/test_decode_cuda_graph_shared_read_fence.py
.py
import contextlib from types import SimpleNamespace import pytest import torch from sglang.srt.layers.attention.base_attn_backend import SharedReadBoundary from sglang.srt.model_executor.forward_batch_info import ForwardMode, PPProxyTensors from sglang.srt.model_executor.runner.decode_cuda_graph_runner import ( D...
137
4,653
sglang
test/registered/unit/model_executor/runner/test_prefill_shared_read_done.py
.py
from types import SimpleNamespace import pytest from sglang.srt.environ import envs from sglang.srt.layers.attention.base_attn_backend import SharedReadBoundary from sglang.srt.model_executor.forward_batch_info import ForwardMode from sglang.srt.model_executor.runner_utils import ( maybe_publish_prefill_shared_re...
76
2,714
sglang
test/registered/unit/model_executor/runner/test_hidden_state_graph_recapture.py
.py
import unittest from types import SimpleNamespace from unittest.mock import Mock from sglang.srt.model_executor.cpu_graph_runner import CPUGraphRunner from sglang.srt.model_executor.cuda_graph_config import Backend from sglang.srt.model_executor.forward_batch_info import ( CaptureHiddenMode, ForwardMode, g...
172
6,168
sglang
test/registered/unit/model_executor/runner_backend/test_full_cuda_graph_backend.py
.py
"""Unit tests for ``FullCudaGraphBackend.capture_one`` profiling hooks — CPU-only. These cover the changes from the "cuda graph profile traces" PR that wire the runner's torch profiler into the capture loop: * When profiling is disabled, ``capture_one`` runs exactly two warmups + one capture and never touches a...
163
6,440
sglang
test/registered/unit/model_executor/model_runner_components/test_cuda_graph_setup.py
.py
import sys from types import SimpleNamespace import pytest from sglang.srt.model_executor.model_runner_components import cuda_graph_setup from sglang.srt.model_executor.model_runner_components.cuda_graph_setup import ( capture_decode_graph, ) from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci...
54
1,713
sglang
test/registered/unit/model_executor/model_runner_components/test_layer_setup.py
.py
"""Unit tests for model-runner layer discovery.""" import unittest from types import SimpleNamespace from sglang.srt.model_executor.model_runner_components.layer_setup import ( compute_attention_and_moe_layers, ) from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=1, suite="base-a-tes...
37
1,095
sglang
test/registered/unit/model_executor/model_runner_components/test_attention_backend_setup.py
.py
import sys from types import SimpleNamespace from unittest.mock import patch import pytest from sglang.srt.layers.attention.hybrid_attn_backend import HybridAttnBackend from sglang.srt.model_executor.model_runner_components import ( attention_backend_setup, ) from sglang.srt.model_executor.model_runner_components...
74
2,332
sglang
test/registered/unit/model_executor/model_runner_components/test_ngram_embedding_manager.py
.py
"""Unit tests for LongCat ngram token table updates.""" import unittest from types import SimpleNamespace from unittest.mock import patch import torch from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.test_utils import CustomTestCase, maybe_stub_sgl_kernel maybe_stub_sgl_kernel() from sglang....
129
4,969
sglang
test/registered/unit/model_executor/model_runner_components/test_startup_weight_load.py
.py
"""Unit tests for the post-capture startup weight-loading component.""" import dataclasses import re import unittest from types import SimpleNamespace from unittest.mock import call, patch import torch from torch import nn from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.test_utils import Cust...
744
25,263
sglang
test/registered/unit/model_loader/test_modelopt_loader.py
.py
""" Unit tests for ModelOptModelLoader class. This test module verifies the functionality of ModelOptModelLoader, which applies NVIDIA Model Optimizer quantization to models during loading. """ import unittest from types import SimpleNamespace from unittest.mock import MagicMock, patch import torch import torch.nn a...
912
36,865
sglang
test/registered/unit/model_loader/test_runai_model_streamer_loader.py
.py
import concurrent.futures import sys import threading import unittest from types import SimpleNamespace from typing import cast from unittest.mock import patch import torch import sglang.srt.model_loader.loader as loader_mod import sglang.srt.model_loader.utils as model_loader_utils import sglang.srt.model_loader.wei...
309
11,676
sglang
test/registered/unit/model_loader/test_presharded_loader.py
.py
"""Unit tests for PreshardedModelLoader's pure helpers. These tests exercise the deterministic pieces of the presharding algorithm (tensor hashing, plan construction, file naming, dedup, file-size cap, and per-rank workload balance) without needing a GPU or distributed setup. """ import json import os import tempfile...
969
41,763
sglang
test/registered/unit/model_loader/test_weight_utils.py
.py
"""Unit tests for srt/model_loader/weight_utils.py shard-index consistency.""" import json import os import tempfile import unittest from sglang.srt.model_loader.weight_utils import filter_duplicate_safetensors_files from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.test_utils import CustomTestC...
89
2,893
sglang
test/registered/unit/model_loader/test_weight_cache_protocol.py
.py
""" CPU-only unit tests for the weight cache protocol layer. These cover the pure-Python logic that the GPU end-to-end test (test_weight_cache_daemon.py) cannot exercise cheaply: - length-prefixed socket framing (send_msg/recv_msg) over socketpair() - CacheConfig fingerprint matching / (de)serialization - quant...
367
13,241
sglang
test/registered/unit/model_loader/test_prefetch_checkpoints.py
.py
""" Unit tests for coordinated checkpoint prefetch. Verifies that weights loaded with prefetch enabled are bit-identical to weights loaded without prefetch. """ import os import tempfile import threading import unittest from concurrent.futures import Future from types import SimpleNamespace from unittest.mock import ...
696
24,879
sglang
test/registered/unit/model_loader/test_modelopt_export.py
.py
""" Unit tests for ModelOpt export functionality in SGLang. These tests verify the integration of ModelOpt export API with SGLang's model loading and quantization workflow. """ import json import os import tempfile import unittest from unittest.mock import Mock, patch import torch from sglang.srt.configs.device_con...
319
12,053
sglang
test/registered/unit/spec/test_dflash_overlap_hostsync.py
.py
"""Unit tests for the DFlash spec-v2 host-sync removal: compact-rebuild kernel bit-exactness, vocab-parallel draft sampler select, host seq-lens upper bound, hybrid needs_cpu_seq_lens delegation, filter_batch host keep-list.""" import unittest from types import SimpleNamespace import torch from sglang.test.ci.ci_reg...
280
11,101
sglang
test/registered/unit/spec/test_eagle_draft_cuda_graph_runner.py
.py
"""Regression test for EAGLE draft CUDA graph seq_lens_sum padding. This is a white-box unit test: it constructs a bare ``EAGLEDraftCudaGraphRunner`` via ``__new__`` and stubs the fields/methods that ``execute()`` touches, so the padding bookkeeping can be exercised on CPU without a captured CUDA graph. It is therefor...
200
8,462
sglang
test/registered/unit/spec/test_decode_bookkeeping_ownership.py
.py
"""Ownership contract for per-request bookkeeping clocks. Per-request accounting state (`decode_batch_idx` / `extend_batch_idx` iter clocks, `kv_committed_len` / `kv_allocated_len` KV watermarks, `spec_verify_ct`, and the `maybe_evict_swa()` call) must only be advanced by the reviewed owner sites in _OWNER_SITES; spec...
240
9,452
sglang
test/registered/unit/spec/test_decoupled_spec_io.py
.py
"""Unit tests for srt/speculative/decoupled_spec_io. decoupled_spec_io is the schema-only IPC layer for decoupled speculative decoding: protocol message dataclasses, the cross-process request id codec, and the drafter-side reconciliation helpers. These tests drive the real logic (id round-trip + parse errors, commit v...
273
11,351