vllm.v1.kv_offload.cpu.engines.base
¶
Contract for a copy mechanism used by the CPU offload worker.
A mechanism (torch, plus the NIXL prototype in engines/nixl.py) implements
CopyEngine and returns CopyStream objects. Neither type exposes
stream/event primitives, so a thread- or RDMA-based mechanism fits the same
contract. Platform details -- memory registration, capabilities, and the
configuration of a mechanism -- are supplied by the runtime in platforms/.
Classes:
-
CopyBatch–Descriptor storage for one transfer, owned by its copy engine.
-
CopyEngine–One copy mechanism, instantiated once per transfer direction.
-
CopyStream–One ordered async transfer on a mechanism's execution context.
CopyBatch
dataclass
¶
Descriptor storage for one transfer, owned by its copy engine.
Addresses are always uint64, whatever pointer dtype the platform's copy
op takes, so the planner never needs to know the platform. payload is
engine-private storage; where an engine needs backing storage (the torch
engine's pinned tensors, say), the three arrays are views into it and it
must stay alive until the transfer completes. Engines that address memory
directly (NIXL) leave it None.
CopyEngine
¶
Bases: ABC
One copy mechanism, instantiated once per transfer direction.
Attributes:
-
device_to_cpu(bool) –True for a device->CPU engine, False for CPU->device.
Methods:
-
new_batch–Allocate descriptor storage for at least
num_opscopies. -
new_stream–Return a transfer stream for this engine's direction.
CopyStream
¶
Bases: ABC
One ordered async transfer on a mechanism's execution context.
Streams are created by a CopyEngine, pooled by the worker, and submitted
in order. A mechanism that runs transfers on a single FIFO worker may
implement wait_for as a no-op.
Error contract: a transfer failure is reported as RuntimeError. The
worker records a failed job and continues. Any other exception -- for
example TimeoutError for a request that may still land -- is fatal: on
shutdown the worker keeps host memory mapped and re-raises it. A mechanism
that gives up on a transfer in flight therefore must not assume the buffer
is released afterwards.
Methods:
-
abort–Finish a stream whose
submitraised. -
done–Whether the transfer has completed.
-
elapsed_seconds–Duration of a completed transfer.
-
submit–Run the first
num_opscopies ofbatch. -
synchronize–Block until the transfer completes.
-
wait_for–Order this transfer after
previouscompletes. -
wait_for_compute–Wait for work already queued on the device's compute stream.
abort()
abstractmethod
¶
Finish a stream whose submit raised.
Clears any pending device error and makes done/synchronize usable.
Raises:
-
RuntimeError–The mechanism reports a failure while finishing.
done()
abstractmethod
¶
elapsed_seconds()
abstractmethod
¶
submit(batch, num_ops)
abstractmethod
¶
synchronize()
abstractmethod
¶
wait_for(previous)
abstractmethod
¶
Order this transfer after previous completes.
wait_for_compute()
abstractmethod
¶
Wait for work already queued on the device's compute stream.