flashinfer.gemm.PreparedNvFp4LoraAdapter

class flashinfer.gemm.PreparedNvFp4LoraAdapter(b_folded: Tensor, lora_b: Tensor, lora_scale: Tensor, alpha: Tensor, pins: dict, n: int, rank: int)

A LoRA adapter prepared for the NVFP4 prepared path of mm_nvfp4_lora() (lora_adapter=).

b_folded = bf16(lora_b * lora_scale / alpha) ([N, rank] bf16: ONE bf16 rounding of the fp32 product of lora_b and the fp32 ratio div.rn.f32(fp32(lora_scale), fp32(alpha)) – bit-identical to the l1 fold of mm_nvfp4_svdquant()). lora_scale is the adapter’s own device scalar; the kernel reads it on the device (lora_scale == 0 takes the zero-adapter path, bitwise the adapter-off call). Snapshot semantics: the adapter keeps references to its source tensors lora_b / lora_scale / alpha and pins = their (data_ptr, _version, shape, device) at prepare time; every call compares these host integers (no sync) and raises StaleAdapterError naming the tensor that moved without a re-prepare. Writes that bypass torch’s version counter (NCCL into an existing buffer, a raw memcpy) need an explicit prepare. alpha is fixed per prepared adapter: the call requires the SAME alpha tensor (identity) at its pinned version – re-prepare when alpha changes (no value comparison).

__init__(b_folded: Tensor, lora_b: Tensor, lora_scale: Tensor, alpha: Tensor, pins: dict, n: int, rank: int) → None

Methods

__init__(b_folded, lora_b, lora_scale, ...)

check_fresh()

Raise StaleAdapterError when a source tensor moved since the prepare (host integers only, no sync).

Attributes

b_folded

lora_b

lora_scale

alpha

pins

n

rank