build_moe_row_adapter_host

Function build_moe_row_adapter_host 

Source
pub fn build_moe_row_adapter_host(
    cu_seqlens_host: &[i32],
    adapter_slots: &[i32],
) -> Option<Vec<i32>>
Expand description

Build the [total_tokens] per-packed-row adapter map for the device-side grouped fold. cu_seqlens_host is the [batch + 1] prefix-sum of per-stream token counts (the packing SSOT); adapter_slots[b] is stream b’s adapter_slot. Each stream’s slot is broadcast across its [cu_seqlens_host[b], cu_seqlens_host[b + 1]) row span. A base stream (adapter_slot < 0) writes -1 (device kernel skips those rows); a stream deferring to the active adapter would resolve < 0 → active at the call site before this, so a genuine base row is a real -1 here (distinct base sentinel — see lora-solid.md §6).

Returns None on a malformed cu_seqlens_host (empty, or a non-monotonic boundary) rather than panicking — the caller then declines the device fold.