Files
sgl-project--sglang/python/sglang/test/scripted_runtime/context/queries.py
T
wehub-resource-sync 94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:38:16 +08:00

140 lines
4.3 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING, Dict, Iterator, List, Optional
if TYPE_CHECKING:
from sglang.srt.managers.schedule_batch import Req
from sglang.test.scripted_runtime.context.api import ScriptedContext
def _get_all_reqs(ctx: ScriptedContext) -> Iterator[Req]:
s = ctx.scheduler
if s.chunked_req is not None:
yield s.chunked_req
yield from s.waiting_queue
if s.ps.pp_size > 1:
for mb in (*s.mbs, *s.last_mbs, *s.running_mbs):
if mb is not None:
yield from mb.reqs
else:
if s.running_batch is not None:
yield from s.running_batch.reqs
if s.last_batch is not None:
yield from s.last_batch.reqs
def list_active_reqs(ctx: ScriptedContext) -> List[Req]:
return list(set(_get_all_reqs(ctx)))
def batch_composition(ctx: ScriptedContext) -> Dict[str, List[str]]:
s = ctx.scheduler
chunked_rid = s.chunked_req.rid if s.chunked_req is not None else None
chunked = [chunked_rid] if chunked_rid is not None else []
running = (
[r.rid for r in s.running_batch.reqs] if s.running_batch is not None else []
)
prefill: List[str] = []
decode: List[str] = []
batch = s.last_batch
if batch is not None and not batch.is_empty() and batch.forward_mode is not None:
bucket = prefill if batch.forward_mode.is_extend() else decode
bucket.extend(r.rid for r in batch.reqs if r.rid != chunked_rid)
return {
"prefill": prefill,
"decode": decode,
"chunked": chunked,
"running": running,
}
def is_idle(ctx: ScriptedContext) -> bool:
s = ctx.scheduler
return (
s.chunked_req is None
and len(s.waiting_queue) == 0
and (s.running_batch is None or s.running_batch.is_empty())
)
def is_fully_idle(ctx: ScriptedContext) -> bool:
s = ctx.scheduler
return is_idle(ctx) and (s.last_batch is None or s.last_batch.is_empty())
def last_batch_forward_mode(ctx: ScriptedContext) -> Optional[str]:
s = ctx.scheduler
if s.last_batch is not None and s.last_batch.forward_mode is not None:
return s.last_batch.forward_mode.name
return None
def find_req_by_rid(ctx: ScriptedContext, rid: str) -> Optional[Req]:
req = next((r for r in _get_all_reqs(ctx) if r.rid == rid), None)
if req is not None:
ctx._seen_rids.add(rid)
return req
def is_finished(ctx: ScriptedContext, rid: str) -> bool:
req = find_req_by_rid(ctx, rid)
if req is not None:
return req.finished()
if rid in ctx._seen_rids:
return True
# Fallback: if the req ran in a forward batch (recorded in _batch_log) but
# is now absent from all active scheduler sets, it must have finished.
# This catches requests that completed without ever being observed via
# find_req_by_rid (e.g. when Python short-circuit evaluation prevents the
# query while another request is still running).
log = ctx._scheduler_hook._batch_log
if any(rid in record.rids for record in log):
ctx._seen_rids.add(rid)
return True
return False
def is_chunking(ctx: ScriptedContext, rid: str) -> bool:
s = ctx.scheduler
return s.chunked_req is not None and s.chunked_req.rid == rid
def status(ctx: ScriptedContext, rid: str) -> str:
s = ctx.scheduler
if rid in {r.rid for r in s.waiting_queue}:
return "waiting"
req = find_req_by_rid(ctx, rid)
if req is not None:
return "finished" if req.finished() else "running"
if rid in ctx._seen_rids:
return "finished"
return "unknown"
def remaining_prompt_tokens(ctx: ScriptedContext, rid: str) -> int:
req = find_req_by_rid(ctx, rid)
if req is None:
return 0
return max(0, len(req.origin_input_ids) - req.kv_committed_len)
def chunks_done(ctx: ScriptedContext, rid: str) -> int:
log = ctx._scheduler_hook._batch_log
held = sum(1 for record in log if record.chunked_rid == rid and rid in record.rids)
if held == 0:
return 0
completed = any(
rid in record.extend_rids and record.chunked_rid != rid for record in log
)
return held + (1 if completed else 0)
def chunked_parks(ctx: ScriptedContext, rid: str) -> int:
return sum(
1
for record in ctx._scheduler_hook._batch_log
if record.chunked_rid == rid and rid not in record.rids
)