Skip to content

perf(moe): wire lfm2 to the fused decode-MoE kernel - #309

Merged
inureyes merged 1 commit into
mainfrom
perf/issue-305-lfm2-fused-kernel
Jun 16, 2026
Merged

inureyes merged 1 commit into
mainfrom
perf/issue-305-lfm2-fused-kernel

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Wire lfm2 (LFM2-MoE) to the fused single-token decode-MoE kernel. The Lfm2MoeSparseMoeBlock already uses the shared SwitchGLU, which exposes forward_fused_kernel, so no struct migration was needed.

What changed

  • src/models/lfm2.rs: replaced the two-statement switch_mlp.forward + moe_weighted_sum sequence with the standard fused-gated branch, mirroring the dots1 / qwen3_moe pattern. The dense fallback path and all routing logic (sigmoid gating, expert_bias selection, norm_topk_prob, routed_scaling_factor) are unchanged.
  • docs/benchmark_results/fused-moe-decode-kernel-design.md: moved lfm2 from the unwired list to the wired list; count updated from five to six model paths.

Test plan

Closes #305

LFM2-MoE uses the shared SwitchGLU which already exposes
forward_fused_kernel. Add the standard fused-gated branch to
Lfm2MoeSparseMoeBlock::forward, mirroring the dots1 / qwen3_moe pattern.

The existing scores tensor (sigmoid-routed, with norm_topk_prob and
routed_scaling_factor already applied) is passed directly to
forward_fused_kernel. The dense fallback path is unchanged. Update the
fused-moe-decode-kernel-design doc to list lfm2 among the wired models.
@inureyes inureyes added type:performance Performance improvements priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) platform:macos macOS (Apple Silicon) specific status:review Under review status:done Completed and removed status:review Under review labels Jun 16, 2026
@inureyes
inureyes merged commit 9cfc4ff into main Jun 16, 2026
5 checks passed
@inureyes
inureyes deleted the perf/issue-305-lfm2-fused-kernel branch June 16, 2026 08:43
@inureyes inureyes added this to the 0.3 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata platform:macos macOS (Apple Silicon) specific priority:medium Medium priority status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(moe): wire lfm2 (LFM2-MoE) to the fused decode-MoE kernel

1 participant