项目文件夹

文件
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

210 行
7.5 KiB
Python

"""Unit tests for the VMM cross-process handle helpers in ``vmm_utils``.
Round-trips export -> exchange -> import/map across ranks for both transports
(POSIX, FABRIC) and both mapping shapes (single base, multi-chunk span). The
only in-tree consumer, ``register_graph_inputs``, reaches this path only under
``expandable_segments``, so the tests allocate shareable buffers directly. A
POSIX-only allocation forces ``export_shareable_handles`` down its POSIX
fallback (otherwise unreachable on FABRIC hardware); FABRIC cases need an
NVLink fabric (GB200/GB300) and skip elsewhere.
"""
from __future__ import annotations
import atexit
import os
import numpy as np
import pytest
import torch
import torch.distributed as dist
from cuda.bindings import driver as drv
from sglang.jit_kernel.tests.utils import multigpu_pytest_main
from sglang.jit_kernel.utils import cache_once
from sglang.srt.distributed.device_communicators.vmm_utils import (
check_drv,
exchange_posix_fds,
export_shareable_handles,
import_and_map_alloc,
make_rw_access_desc,
map_chunk_into_span,
release_mappings,
)
from sglang.test.ci.ci_register import register_cuda_ci
register_cuda_ci(est_time=60, stage="base-b", runner_config="2-gpu-large")
_FABRIC = drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_FABRIC
_POSIX_FD = drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR
_RECOMMENDED = drv.CUmemAllocationGranularity_flags.CU_MEM_ALLOC_GRANULARITY_RECOMMENDED
_ALLOC_BYTES = 2 * 1024 * 1024
@cache_once
def _gloo_group() -> dist.ProcessGroup:
torch.cuda.set_device(int(os.environ["LOCAL_RANK"]))
dist.init_process_group(backend="gloo")
atexit.register(dist.destroy_process_group)
return dist.group.WORLD
def _make_prop(handle_type, device_id: int):
prop = drv.CUmemAllocationProp()
prop.type = drv.CUmemAllocationType.CU_MEM_ALLOCATION_TYPE_PINNED
prop.location.type = drv.CUmemLocationType.CU_MEM_LOCATION_TYPE_DEVICE
prop.location.id = device_id
prop.requestedHandleTypes = handle_type
return prop
@cache_once
def _fabric_available() -> bool:
"""True if this device can create + export FABRIC handles (GB200/GB300)."""
prop = _make_prop(_FABRIC, torch.cuda.current_device())
err, gran = drv.cuMemGetAllocationGranularity(prop, _RECOMMENDED)
if err != drv.CUresult.CUDA_SUCCESS:
return False
err, handle = drv.cuMemCreate(int(gran), prop, 0)
if err != drv.CUresult.CUDA_SUCCESS:
return False
err, _ = drv.cuMemExportToShareableHandle(handle, _FABRIC, 0)
drv.cuMemRelease(handle)
return err == drv.CUresult.CUDA_SUCCESS
def _create_alloc(handle_type, size_hint: int):
"""Create a mapped, RW, shareable VMM allocation. Returns (handle, va, size)."""
device_id = torch.cuda.current_device()
prop = _make_prop(handle_type, device_id)
gran = check_drv(
drv.cuMemGetAllocationGranularity(prop, _RECOMMENDED),
"cuMemGetAllocationGranularity",
)
size = ((size_hint + gran - 1) // gran) * gran
handle = check_drv(drv.cuMemCreate(size, prop, 0), "cuMemCreate")
va = check_drv(drv.cuMemAddressReserve(size, gran, 0, 0), "cuMemAddressReserve")
check_drv(drv.cuMemMap(int(va), size, 0, handle, 0), "cuMemMap")
check_drv(
drv.cuMemSetAccess(int(va), size, [make_rw_access_desc(device_id)], 1),
"cuMemSetAccess",
)
return handle, int(va), size
def _byte(rank: int, chunk: int) -> int:
"""A distinct nonzero fill byte per (rank, chunk)."""
return (rank * 16 + chunk + 1) & 0xFF
def _assert_region(va: int, expected: int, peer: int, chunk: int) -> None:
host = np.empty(16, dtype=np.uint8)
check_drv(drv.cuMemcpyDtoH(host.ctypes.data, va, host.nbytes), "cuMemcpyDtoH")
assert (
host == expected
).all(), (
f"read {host.tolist()} from peer {peer} chunk {chunk}, expected all {expected}"
)
@pytest.mark.parametrize("n_chunks", [1, 3])
@pytest.mark.parametrize("transport", ["posix", "fabric"])
def test_handle_roundtrip(transport: str, n_chunks: int) -> None:
group = _gloo_group()
if transport == "fabric" and not _fabric_available():
pytest.skip("FABRIC handles require an NVLink fabric (GB200/GB300)")
rank = dist.get_rank(group)
world = dist.get_world_size(group)
device_id = torch.cuda.current_device()
handle_type = _FABRIC if transport == "fabric" else _POSIX_FD
handles, vas, sizes = [], [], []
for chunk in range(n_chunks):
handle, va, size = _create_alloc(handle_type, _ALLOC_BYTES)
check_drv(drv.cuMemsetD8(va, _byte(rank, chunk), size), "cuMemsetD8")
handles.append(handle)
vas.append(va)
sizes.append(size)
torch.cuda.synchronize()
posix_fds, peer_fds, mappings = [], {}, []
try:
fabric_handles, posix_fds, use_fabric = export_shareable_handles(
handles, group, rank
)
assert use_fabric == (transport == "fabric")
# FABRIC handles travel inline; POSIX fds are exchanged out-of-band
# (process-local).
local_meta = [
(sizes[c], fabric_handles[c] if use_fabric else None)
for c in range(n_chunks)
]
all_meta = [None] * world
dist.all_gather_object(all_meta, local_meta, group=group)
if not use_fabric:
peer_fds = exchange_posix_fds(
group, rank, world, posix_fds, [n_chunks] * world
)
for peer in range(world):
if peer == rank:
continue
peer_meta = all_meta[peer]
if n_chunks == 1:
size, fabric_handle = peer_meta[0]
fd = None if use_fabric else peer_fds[(peer, 0)]
peer_va = import_and_map_alloc(
fabric_handle,
fd,
size,
device_id,
use_fabric=use_fabric,
peer_rank=peer,
)
mappings.append((peer_va, size, [(0, size)]))
_assert_region(peer_va, _byte(peer, 0), peer, 0)
continue
span_size = sum(size for size, _ in peer_meta)
span_va = int(
check_drv(
drv.cuMemAddressReserve(span_size, 0, 0, 0),
"cuMemAddressReserve(span)",
)
)
rel, mapped = 0, []
for chunk, (size, fabric_handle) in enumerate(peer_meta):
fd = None if use_fabric else peer_fds[(peer, chunk)]
map_chunk_into_span(
fabric_handle,
fd,
span_va,
rel,
size,
device_id,
use_fabric=use_fabric,
peer_rank=peer,
)
mapped.append((rel, size))
rel += size
mappings.append((span_va, span_size, mapped))
rel = 0
for chunk, (size, _) in enumerate(peer_meta):
_assert_region(span_va + rel, _byte(peer, chunk), peer, chunk)
rel += size
finally:
release_mappings(mappings)
for fd in peer_fds.values():
os.close(fd)
for fd in posix_fds:
os.close(fd)
for handle, va, size in zip(handles, vas, sizes):
check_drv(drv.cuMemUnmap(va, size), "cuMemUnmap")
check_drv(drv.cuMemAddressFree(va, size), "cuMemAddressFree")
check_drv(drv.cuMemRelease(handle), "cuMemRelease")
if __name__ == "__main__":
multigpu_pytest_main(__name__, __file__, num_gpus=(2,))