Files
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

211 lines
5.8 KiB
Python

"""
Benchmark for comparing CPU overhead of segment tracking methods:
1. nccl_allocator_register_segments_with_comm() - C++ registration with index tracking
2. torch.cuda.memory.memory_snapshot() - PyTorch memory snapshot
Usage:
python benchmark/bench_pynccl_allocator/bench_segment_tracking.py --num-segments 50 --num-iters 1000
"""
import argparse
import time
import warnings
from typing import List
import torch
warnings.filterwarnings("ignore")
def setup_segments(num_segments: int, segment_size: int = 1024 * 1024):
"""
Allocate a specified number of segments using the NCCL allocator.
"""
import os
import torch.distributed as dist
from sglang.srt.distributed.device_communicators.pynccl_allocator import (
get_nccl_mem_pool,
)
# Initialize distributed if not already done
if not dist.is_initialized():
os.environ.setdefault("MASTER_ADDR", "localhost")
os.environ.setdefault("MASTER_PORT", "29500")
dist.init_process_group(
backend="nccl",
rank=0,
world_size=1,
device_id=torch.device(f"cuda:{torch.cuda.current_device()}"),
)
mem_pool = get_nccl_mem_pool()
# Allocate segments in the pool
tensors: List[torch.Tensor] = []
with torch.cuda.use_mem_pool(mem_pool):
for _ in range(num_segments):
t = torch.empty(segment_size, dtype=torch.uint8, device="cuda")
tensors.append(t)
# Keep tensors alive by returning them (caller should hold reference)
return tensors, mem_pool
def bench_register_segments_with_comm(
nccl_lib, comm_ptr: int, num_iters: int = 10000
) -> float:
"""
Benchmark nccl_allocator_register_segments_with_comm() function.
Args:
nccl_lib: The loaded NCCL allocator library
comm_ptr: The communicator pointer value
num_iters: Number of iterations
Returns:
Average time per call in microseconds.
"""
import ctypes
# Setup the C function signature
register_func = nccl_lib.nccl_allocator_register_segments_with_comm
register_func.restype = ctypes.c_int
register_func.argtypes = [ctypes.c_uint64]
# Warmup
for _ in range(100):
register_func(comm_ptr)
# Benchmark
start = time.perf_counter()
for _ in range(num_iters):
register_func(comm_ptr)
end = time.perf_counter()
avg_us = (end - start) / num_iters * 1e6
return avg_us
def bench_mempool_snapshot(
mem_pool: torch.cuda.MemPool, num_iters: int = 10000
) -> float:
"""
Benchmark torch.cuda.MemPool.snapshot() function.
Returns:
Average time per call in microseconds.
"""
# Warmup
for _ in range(100):
mem_pool.snapshot()
# Benchmark
start = time.perf_counter()
for _ in range(num_iters):
mem_pool.snapshot()
end = time.perf_counter()
avg_us = (end - start) / num_iters * 1e6
return avg_us
def bench_with_various_segment_counts(
segment_counts: List[int],
num_iters: int = 10000,
segment_size: int = 1024 * 1024, # 1MB per segment
):
"""
Run benchmarks with various numbers of tracked segments.
"""
print("=" * 80)
print("Benchmark: Segment Registration CPU Overhead")
print("=" * 80)
print(f"Segment size: {segment_size / 1024 / 1024:.2f} MB")
print(f"Iterations per measurement: {num_iters}")
print()
print(
f"{'Segments':<12} {'register_segments (µs)':<30} {'snapshot (µs)':<20} {'Speedup':<10}"
)
print("-" * 80)
all_tensors = [] # Keep all tensors alive
comm_ptr = 0 # Use dummy comm_ptr for benchmarking (no actual NCCL registration)
for num_segments in segment_counts:
# Clean up previous segments
all_tensors = []
# Allocate segments (this initializes _nccl_allocator_lib via get_nccl_mem_pool)
tensors, mem_pool = setup_segments(num_segments, segment_size)
all_tensors.extend(tensors)
# Sync to ensure allocations are complete
torch.cuda.synchronize()
# Import _nccl_allocator_lib after setup_segments (ensures library is loaded)
from sglang.srt.distributed.device_communicators.pynccl_allocator import (
_nccl_allocator_lib,
)
# Run benchmarks
time_register = bench_register_segments_with_comm(
_nccl_allocator_lib, comm_ptr, num_iters
)
time_snapshot = bench_mempool_snapshot(mem_pool, num_iters)
speedup = time_snapshot / time_register if time_register > 0 else float("inf")
print(
f"{num_segments:<12} {time_register:<30.3f} {time_snapshot:<20.3f} {speedup:<10.2f}x"
)
print("-" * 80)
print()
def main():
parser = argparse.ArgumentParser(
description="Benchmark segment tracking methods in pynccl_allocator"
)
parser.add_argument(
"--num-segments",
type=int,
nargs="+",
default=[10, 50, 100, 200, 500, 1000],
help="Number of segments to track (can specify multiple values)",
)
parser.add_argument(
"--num-iters",
type=int,
default=10000,
help="Number of iterations for each measurement",
)
parser.add_argument(
"--segment-size",
type=int,
default=1024 * 1024, # 1MB
help="Size of each segment in bytes",
)
args = parser.parse_args()
# Check CUDA availability
if not torch.cuda.is_available():
print("Error: CUDA is not available. This benchmark requires a GPU.")
return
# Initialize CUDA context by creating a small tensor
_ = torch.zeros(1, device="cuda")
# Run benchmarks
bench_with_various_segment_counts(
segment_counts=args.num_segments,
num_iters=args.num_iters,
segment_size=args.segment_size,
)
if __name__ == "__main__":
main()