Skip to content

Wire flash attention kernel into ASR/FLUX encoder paths #339

Description

@ymote

Context

A custom flash attention Metal kernel with online softmax was added in mlx-rs-core/src/metal_kernels.rs (flash_attention()). It avoids materializing the full attention matrix, supports GQA and causal masking.

Benchmarking showed it's slower than MLX SDPA for Q=1 decode (TTS), but should excel on long-prefill encoder paths (ASR encoder, FLUX spatial attention) where Q >> 1 and MLX falls back to regular operations.

TODO

  • Benchmark flash kernel vs MLX SDPA at Step-Audio-2 encoder dimensions (1500 tokens, 20 heads) — need model weights
  • If faster, wire into step-audio2-mlx/src/encoder.rs behind a feature flag
  • Test on FLUX double-block spatial attention (4096 tokens)
  • Consider integrating the now-fixed MFA library as an alternative backend

Measured dimensions where gains are expected

Model Seq tokens Heads SDPA ms (24L) Manual ms (24L)
Step-Audio-2 1500 20 59ms 119ms
Qwen3-VL 1024 16 28ms 54ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions