Skip to content

fix: macOS 26 BNNS compiler compatibility for Sortformer#11

Merged
Alex-Wengg merged 1 commit intomainfrom
fix/macos26-sortformer-bnns
Jan 29, 2026
Merged

fix: macOS 26 BNNS compiler compatibility for Sortformer#11
Alex-Wengg merged 1 commit intomainfrom
fix/macos26-sortformer-bnns

Conversation

@Alex-Wengg
Copy link
Contributor

@Alex-Wengg Alex-Wengg commented Jan 25, 2026

Summary

  • Fixes macOS 26 BNNS compiler error where input/output tensors cannot share the same name
  • Adds explicit identity ops to create distinct output tensors
  • Renames outputs to *_out suffix (chunk_pre_encoder_embs_out, chunk_pre_encoder_lengths_out)

Problem

macOS 26 introduced stricter validation in the BNNS graph compiler:

Function main has tensor chunk_pre_encoder_embs as both an input and output.
Inputs and outputs must be distinct, please add an explicit identity op.

Solution

  1. coreml_wrappers.py: Add identity ops (+ 0.0) in SortformerHeadWrapper to create distinct output tensors
  2. convert_to_coreml.py: Rename output tensor names to avoid collision

Breaking Change

Models converted with this fix require FluidAudio to read from new output names:

  • chunk_pre_encoder_embschunk_pre_encoder_embs_out
  • chunk_pre_encoder_lengthschunk_pre_encoder_lengths_out

V2 models uploaded to HuggingFace use these new names.

Fixes FluidInference/FluidAudio#265

macOS 26 introduced stricter validation in the BNNS graph compiler that
rejects CoreML models where input and output tensors share the same name.

The Sortformer head module had `chunk_pre_encoder_embs` as both an input
and output (pass-through for state management), which now fails with:
"Function main has tensor chunk_pre_encoder_embs as both an input and
output. Inputs and outputs must be distinct, please add an explicit
identity op."

Changes:
- coreml_wrappers.py: Add explicit identity ops (+ 0.0) to create
  distinct output tensors in SortformerHeadWrapper
- convert_to_coreml.py: Rename output tensors to *_out suffix
  (chunk_pre_encoder_embs_out, chunk_pre_encoder_lengths_out)

Models converted with this fix require FluidAudio to be updated to read
from the new output names.

Fixes FluidInference/FluidAudio#265
@Alex-Wengg Alex-Wengg force-pushed the fix/macos26-sortformer-bnns branch from 46ed4cc to 119b54d Compare January 25, 2026 22:57
Alex-Wengg added a commit to FluidInference/FluidAudio that referenced this pull request Jan 26, 2026
## Summary

- Fixes macOS 26 BNNS compiler error for Sortformer models
- Updates to use V2 models with renamed output tensors
- Adds Float16 support for head module outputs

## Problem

macOS 26 introduced stricter validation in the BNNS graph compiler that
rejects CoreML models where input and output tensors share the same
name:

```
Failed to configure ML Program for the feature types declared in the model description.
Function main has tensor chunk_pre_encoder_embs as both an input and output.
Inputs and outputs must be distinct, please add an explicit identity op.
```

## Solution

### Code Changes
1. **SortformerModelInference.swift**: 
- Read from renamed outputs (`chunk_pre_encoder_embs_out`,
`chunk_pre_encoder_lengths_out`)
   - Handle Float16 output (head module uses fp16 precision)

2. **ModelNames.swift**: 
- Update model names to V2 (`SortformerV2`, `SortformerNvidiaLowV2`,
`SortformerNvidiaHighV2`)

### Model Changes (separate PR)
V2 models converted with:
- Explicit identity ops (`+ 0.0`) to create distinct output tensors
- Renamed output tensor names to `*_out` suffix

See: FluidInference/mobius#11

## Testing

Tested on macOS 26.1 (Build 25B78), Apple M2:
- Model loads successfully (~90ms warm, ~1.2s cold)
- Inference works correctly (9-10x RTFx)
- DER results match expected values

Fixes #265
@Alex-Wengg Alex-Wengg merged commit 79365c5 into main Jan 29, 2026
@Alex-Wengg Alex-Wengg deleted the fix/macos26-sortformer-bnns branch January 29, 2026 01:17
Alex-Wengg pushed a commit that referenced this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sortformer model fails to compile - BNNS Graph Compile errors

1 participant