Skip to content

perf(models): fused/compiled xIELU activation for Apertus decode #409

Closed

Description

@inureyes

Problem / Background

#269 (PR #399) characterized the Apertus dense decode gap. The bulk of the original 0.83x gap had already been recovered by the earlier #290 fix (the bf16-scale quant decode regression), so Apertus now runs at roughly 0.98x of mlx-lm. PR #399 additionally trimmed one bit-exact elementwise op in apertus_xielu (src/models/apertus.rs).

Profiling the forward path showed the per-token decode step is GPU-bound: host-side graph build is around 0.7ms while GPU eval is around 13ms. With that ratio, further host-side op-count reductions have very little headroom. The implementer of #269 (PR #399) recommended this as the one remaining meaningful decode lever, left explicitly as a documented follow-up.

Proposed Solution

Fuse or compile the xIELU activation for Apertus. apertus_xielu currently issues roughly 11-12 separate elementwise MLX ops per layer per token (beta*x, x^2, mul_scalar, add, min, expm1, sub, mul_scalar, add, greater, where). A single mx::compile window over that elementwise graph, or a custom Metal kernel covering it, could cut per-op launch and epilogue overhead.

This was intentionally not implemented in #269 because it is not a "cheap" recovery: it touches the C++ FFI bridge / Metal kernel path and risks f16 reassociation/jitter.

Caveats

  1. Modest expected gain. Apertus is already near parity (~0.98x) and the remaining decode gap is diffuse GPU-bound overhead with no single high-value lever. The project's prior AsType reduction campaign capped around +2.6%. Triage should weigh whether the realized gain justifies the FFI/kernel complexity before committing to this work.
  2. Native bf16 precision. Apertus runs NATIVE bf16. A fused kernel must either preserve greedy temp-0 output as byte-identical, or be explicitly accepted as f16/bf16 jitter-class with documented RMS bounds. This mirrors the fused-MoE kernel's "byte-identical OR jitter-class" parity policy.
  3. Scope. This touches the C++ FFI bridge / Metal kernel path, not just src/models/apertus.rs.

Acceptance Criteria

  • A fused or compiled xIELU path for Apertus that measurably improves decode tok/s on Apple Silicon.
  • Greedy temp-0 output is kept byte-identical, OR documented as jitter-class within stated RMS bounds (mirroring the fused-MoE parity policy).
  • The new path is gated and benched against the current elementwise implementation.
  • No regression for other models sharing any touched code (FFI bridge / Metal kernel / shared layers).

Technical Considerations

Activity

  1. added
    type:performance
    area:models
    area:inference
    priority:low
    platform:macos
    status:backlog
    status:in-progress
    status:review
    status:done
    and removed
    status:backlog
    status:in-progress
    status:review
    on Jun 23, 2026
  2. self-assigned this
    on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencearea:modelsplatform:macospriority:lowstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions