flashinfer.fused_moe.bgmv_moe_gemm2_lora_delta¶
- flashinfer.fused_moe.bgmv_moe_gemm2_lora_delta(gemm1_activation_output: Tensor, expanded_idx_to_permuted_idx: Tensor, w_ptr_a: Tensor, lora_stride_a: int, w_ptr_b: Tensor, lora_stride_b: int, topk_ids: Tensor, topk_weights: Tensor, lora_ids: Tensor, rank: int, hidden_size: int, *, lora_dtype: dtype = torch.bfloat16, scale: float = 1.0, out_dtype: dtype = torch.bfloat16) Tensor¶
FC2 (down_proj) LoRA delta for a routed MoE, to be ADDED to the MoE output.
Consumes the post-SwiGLU activation returned by
trtllm_*_moe(called withgemm1_lora_deltaset anddo_finalize=True). For each routed pair(token t, slot j)with experteand adapterl:delta[t] = scale * Σ_j w[t, j] * ( B_down[l,e] @ (A_down[l,e] @ a[t, j]) )
Weighted and combined over experts (added after FC2, post-combine).
- Parameters:
gemm1_activation_output (torch.Tensor) –
[padded_rows, I]PERMUTED, post-SwiGLU activation (trtllm return).I(the down-projection input width) is read fromshape[1].expanded_idx_to_permuted_idx (torch.Tensor) –
[T*top_k]int — maps expanded indextoken*top_k+slotto the permuted row (trtllm return);< 0marks an inactive slot.w_ptr_a (torch.Tensor) –
[1, num_experts]int64 base-pointer table for[A_down], fromfill_w_ptr().lora_stride_a (int) – Element stride between adapters in the A_down bank.
w_ptr_b (torch.Tensor) –
[1, num_experts]int64 base-pointer table for[B_down].lora_stride_b (int) – Element stride between adapters in the B_down bank.
topk_ids (torch.Tensor) –
[T, top_k]routed expert ids (int) and per-expert combine weights (f32).topk_weights (torch.Tensor) –
[T, top_k]routed expert ids (int) and per-expert combine weights (f32).lora_ids (torch.Tensor) –
[T]int adapter id per token (-1= none).rank (int) – LoRA rank.
hidden_size (int) –
H— the down-projection output width.lora_dtype (torch.dtype) – Dtype of the LoRA weights / activation gather buffer (bf16/fp16).
scale (float) – LoRA
alpha / rankscaling.out_dtype (torch.dtype) – Output dtype (match the MoE output, e.g. bf16).
- Returns:
[T, H]inout_dtype. Add to the MoE output.- Return type:
torch.Tensor