Runtime and operators#

See residency and leases and retained-rank serving for lifetime and graph-capture requirements.

Compact CPU/GPU residency and explicit slot ownership.

class GPUAdapterSlots(capacity: int, *, device: str, max_tensor_bytes: int | None = None)[source]#

Explicit GPU slots; use factors only inside borrow() on its current stream.

Each load allocates compact storage rather than overwriting old device addresses. Active leases prevent replacement/eviction. record_stream protects enqueued work after lease exit. Captured graphs and mutation are unsupported.

borrow(handle: SlotHandle)[source]#

Lease read-only factors for work enqueued on the current pool-device stream.

The lease must cover all enqueue calls. Do not keep tensor references or enqueue on another stream outside its scope. Scaling remains explicit.

collect() → None[source]#

Release completed pinned staging without waiting for GPU completion.

evict(handle: SlotHandle) → None[source]#

Invalidate residency; allocator stream tracking protects queued consumers.

load(source: str | Path, slot: int) → SlotHandle[source]#

Validate on CPU, stage pinned copies, enqueue H2D on current pool stream.

A returned handle can be borrowed immediately on another stream; borrow inserts an event wait. File parsing and pinning are synchronous host work. Failure preserves the previous occupant and generation.

property tensor_bytes: int#

Committed factor payload bytes, excluding staging and retired allocations.

class AdapterSlots(capacity: int, *, max_tensor_bytes: int | None = None)[source]#

Own compact CPU snapshots in a bounded number of explicitly managed slots.

Loading clones tensors into contiguous storage. A failed load leaves the old occupant and its handle intact. Successful replacement or eviction invalidates old handles. resolve() returns a fresh clone, so callers cannot mutate pool storage. No automatic eviction, GPU copies, graph replay or async lifetime is implied. Operations are serialized by a per-pool lock.

evict(handle: SlotHandle) → None[source]#

Release residency and invalidate the handle; external copies remain valid.

load(source: str | Path, slot: int) → SlotHandle[source]#

Validate a local PEFT file snapshot and atomically replace one CPU slot.

resolve(handle: SlotHandle) → tuple[AdapterModule, ...][source]#

Return detached compact CPU copies, preserving rank and effective scaling.

property tensor_bytes: int#

Resident factor payload bytes; excludes Python and transient load copies.

class SlotHandle(pool: str, slot: int, generation: int)[source]#

Opaque ownership token; valid only in its originating pool generation.

Decode operations#

Lazy graph-compatible decode operators; metadata stays on device.

lora_shrink(x, weights, ranks, token_map, num_slices: int = 1)[source]#

Apply packed LoRA A to decode tokens, preserving the activation dtype.

A is [slots, slices*max_rank, input]; actual slices are packed with stride rank[slot]. Caller guarantees device metadata values are valid: mappings in [0, slots), ranks in [0, max_rank]. Rank zero represents base-model tokens. BF16 uses sequential matrix-dot blocks to avoid split-K rounding drift. No device values are read on the host, so warmed calls support graph capture.

lora_expand(x, weights, ranks, scales, token_map, offsets, max_slice_size: int, base=None)[source]#

Apply padded LoRA B and add a scaled delta to optional base in place.

B is [slots, total_output, max_rank]. x has the packed shrink layout. Slice offsets are increasing, start at zero and end at total_output; each slice length is <= max_slice_size. Caller guarantees these device values, metadata ranges and non-overlapping output storage. The scaled delta is rounded to the activation dtype before base addition. BF16 uses sequential matrix-dot blocks matching the pinned SGLang default reduction geometry.