Runs DeepSeek-V4.1-Flash-1017 (GSQ-RCO IQ2_XXS GGUF + Engram IQ4_NL + DSpark5 draft) on 4x V100-32G (TP4, one x16 PCIe uplink, 62 GB host RAM) with expert offloading. All new paths are lossless and switchable. Prefill (G1-G7): - G1 activation memory: per-tile MoE scratch + FP32 accumulator, in-place expand_hc / large all-reduce, windowed hc_transition, pynccl all_gather, empty_cache before big passes; chunks up to 16K. - G2 cold-expert staging ring issued ahead across tiles and layers. - G3 routed down projection split by output rows (no duplicated TP boundary blocks, -2.25 GiB/GPU) with an IPC peer gather for decode. - G5 Engram readers, adaptive indexer tile, persistent activation grid. - G6 routed-only staging for short prompts. - G7 same-session prefix cache (scheduler guard + worker restore_prefix). Long context (G4): - Window layers keep 256-row private rings. - Packed KV (VLLM_V41_PACKED_KV): FP4 + E4M3 compressed latents in a shared host memfd plus a 32K GPU hot ring, FP4 index keys on GPU, CUDA decode index scores and segment-parallel exact top-k. Enables 512K. - RoPE rotates on the fly past its table; C2/Engram/guard limits and the DSpark draft length cap are lifted to the target length. Results vs phase 1: TTFT short 5.6 -> 0.8-1.1 s, 8K 27.7 -> 5.8 s, 15K 44.0 -> 11.1 s; 128K 110 s and 500K 651 s (needle passes); follow-up turns hit the prefix cache in ~1-1.7 s; fresh-text decode 57.8 -> 53.5 ms/round. Tokens at <=16K are identical with packed KV. Tooling: benchmarks/deepseek_v41/ gains the v41k SM70 extension source and build script, serve configs (phase 2: 16K, phase 3: 512K + prefix cache + tools + thinking), launch/validation tools, GPU micro-tests and HANDOFF.md. V4.1 switches are registered in vllm/envs.py and read through vllm.envs. Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
157 lines
5.2 KiB
Python
157 lines
5.2 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
import array
|
|
import fcntl
|
|
import mmap
|
|
import multiprocessing as mp
|
|
import os
|
|
import socket
|
|
import struct
|
|
|
|
import pytest
|
|
|
|
from vllm.utils.shared_host import SharedHostArena
|
|
|
|
pytestmark = pytest.mark.skipif(
|
|
not hasattr(os, "memfd_create"), reason="shared host arena requires Linux"
|
|
)
|
|
|
|
|
|
def _child(connection):
|
|
with connection, SharedHostArena.receive(connection) as arena:
|
|
assert arena.buffer[:4] == b"seed"
|
|
arena.buffer[4:8] = b"peer"
|
|
connection.send(struct.pack("!QQ", arena.identity.device, arena.identity.inode))
|
|
|
|
|
|
def test_spawned_process_maps_same_object_and_updates_parent():
|
|
context = mp.get_context("spawn")
|
|
parent, child = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
|
with parent, child, SharedHostArena.create(4097) as arena:
|
|
assert arena.size == 2 * mmap.PAGESIZE
|
|
arena.buffer[:4] = b"seed"
|
|
process = context.Process(target=_child, args=(child,))
|
|
process.start()
|
|
try:
|
|
parent.settimeout(15)
|
|
arena.send(parent)
|
|
identity = struct.unpack("!QQ", parent.recv(16))
|
|
assert identity == (arena.identity.device, arena.identity.inode)
|
|
process.join(15)
|
|
assert process.exitcode == 0
|
|
assert arena.buffer[4:8] == b"peer"
|
|
finally:
|
|
if process.is_alive():
|
|
process.terminate()
|
|
process.join(5)
|
|
|
|
|
|
def test_size_seal_prevents_peer_truncating_a_live_mapping():
|
|
with SharedHostArena.create(mmap.PAGESIZE) as arena:
|
|
with pytest.raises(OSError):
|
|
os.ftruncate(arena._fd, 0)
|
|
with pytest.raises(OSError):
|
|
os.ftruncate(arena._fd, arena.size * 2)
|
|
# The pool remains writable because GPU evictions write into it.
|
|
arena.buffer[0] = 23
|
|
assert arena.buffer[0] == 23
|
|
|
|
|
|
def test_close_rejects_live_export_and_can_be_retried():
|
|
arena = SharedHostArena.create(4096)
|
|
view = memoryview(arena.buffer)
|
|
with pytest.raises(BufferError):
|
|
arena.close()
|
|
view.release()
|
|
arena.close()
|
|
arena.close()
|
|
with (
|
|
socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET) as connection,
|
|
pytest.raises(ValueError, match="closed"),
|
|
):
|
|
arena.send(connection)
|
|
|
|
|
|
@pytest.mark.parametrize("version,wrong_identity", [(99, False), (1, True)])
|
|
def test_invalid_handle_closes_received_descriptor(version, wrong_identity):
|
|
parent, child = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
|
with parent, child, SharedHostArena.create(4096) as arena:
|
|
before = len(os.listdir("/proc/self/fd"))
|
|
parent.sendmsg(
|
|
[
|
|
struct.pack(
|
|
"!IQQQ",
|
|
version,
|
|
arena.size,
|
|
arena.identity.device,
|
|
arena.identity.inode + int(wrong_identity),
|
|
)
|
|
],
|
|
[(socket.SOL_SOCKET, socket.SCM_RIGHTS, array.array("i", [arena._fd]))],
|
|
)
|
|
with pytest.raises(ValueError):
|
|
SharedHostArena.receive(child)
|
|
assert len(os.listdir("/proc/self/fd")) == before
|
|
|
|
|
|
def test_unsealed_file_is_rejected():
|
|
fd = os.memfd_create("unsealed", os.MFD_ALLOW_SEALING)
|
|
os.ftruncate(fd, mmap.PAGESIZE)
|
|
with pytest.raises(ValueError, match="not sealed"):
|
|
SharedHostArena(fd)
|
|
with pytest.raises(OSError):
|
|
fcntl.fcntl(fd, fcntl.F_GETFD)
|
|
|
|
|
|
def test_stream_socket_is_not_accepted_as_atomic_handle_transport():
|
|
parent, child = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
with (
|
|
parent,
|
|
child,
|
|
SharedHostArena.create(4096) as arena,
|
|
pytest.raises(ValueError, match="SEQPACKET"),
|
|
):
|
|
arena.send(parent)
|
|
|
|
|
|
def _registration_child(connection):
|
|
with connection, SharedHostArena.receive(connection) as arena:
|
|
connection.send(b"ready")
|
|
with arena.registration_guard():
|
|
arena.buffer[0] = 71
|
|
connection.send(b"acquired")
|
|
|
|
|
|
def test_registration_record_lock_excludes_received_descriptor_process():
|
|
context = mp.get_context("spawn")
|
|
parent, child = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
|
with parent, child, SharedHostArena.create(mmap.PAGESIZE) as arena:
|
|
process = context.Process(target=_registration_child, args=(child,))
|
|
process.start()
|
|
try:
|
|
parent.settimeout(15)
|
|
with arena.registration_guard():
|
|
arena.send(parent)
|
|
assert parent.recv(16) == b"ready"
|
|
parent.settimeout(0.1)
|
|
with pytest.raises(TimeoutError):
|
|
parent.recv(16)
|
|
assert arena.buffer[0] == 0
|
|
parent.settimeout(15)
|
|
assert parent.recv(16) == b"acquired"
|
|
process.join(15)
|
|
assert process.exitcode == 0
|
|
assert arena.buffer[0] == 71
|
|
finally:
|
|
if process.is_alive():
|
|
process.terminate()
|
|
process.join(5)
|
|
|
|
|
|
def test_closed_arena_cannot_take_registration_lock():
|
|
arena = SharedHostArena.create(mmap.PAGESIZE)
|
|
arena.close()
|
|
with pytest.raises(ValueError, match="closed"), arena.registration_guard():
|
|
pass
|