Skip to content

vllm.distributed.kv_transfer.kv_connector.v1.nixl.utils

Shared constants, lazy imports and helpers for the NIXL connector.

Functions:

  • get_base_request_id

    Strip the per-request -<8 hex> randomization suffix, if present.

  • zmq_ctx

    Context manager for a ZMQ socket

get_base_request_id(request_id)

Strip the per-request -<8 hex> randomization suffix, if present.

Source code in vllm/distributed/kv_transfer/kv_connector/v1/nixl/utils.py
def get_base_request_id(request_id: str) -> str:
    """Strip the per-request ``-<8 hex>`` randomization suffix, if present."""
    return _RANDOM_SUFFIX_RE.sub("", request_id)

zmq_ctx(socket_type, addr)

Context manager for a ZMQ socket

Source code in vllm/distributed/kv_transfer/kv_connector/v1/nixl/utils.py
@contextlib.contextmanager
def zmq_ctx(socket_type: Any, addr: str) -> Iterator[zmq.Socket]:
    """Context manager for a ZMQ socket"""

    if socket_type not in (zmq.ROUTER, zmq.REQ):
        raise ValueError(f"Unexpected socket type: {socket_type}")

    ctx: zmq.Context | None = None
    try:
        ctx = zmq.Context()  # type: ignore[attr-defined]
        yield make_zmq_socket(
            ctx=ctx, path=addr, socket_type=socket_type, bind=socket_type == zmq.ROUTER
        )
    finally:
        if ctx is not None:
            ctx.destroy(linger=0)