Skip to content

Fix MIL syntax + M1/M2 support#6

Open
imperatormk wants to merge 4 commits intomaderix:mainfrom
imperatormk:fix/mil-scalar-syntax
Open

Fix MIL syntax + M1/M2 support#6
imperatormk wants to merge 4 commits intomaderix:mainfrom
imperatormk:fix/mil-scalar-syntax

Conversation

@imperatormk
Copy link

MIL scalar types used shorthand syntax that only compiles on M4. Changed to the canonical verbose format that CoreML's compiler emits (tensor<string, []>("x") instead of string("x")), targets program(1.0)/<ios16>, and simplifies buildInfo.

For conv kernels, adds runtime fp16 I/O fallback — M1/M2 ANE can't do the cast op, so on first compile failure it retries with fp16 inputs/outputs and converts on the CPU side.

Tested on M1 Pro, macOS 26.3.

The MIL scalar types used shorthand syntax (string("x"), int32(1)) that
only works on M4. Changed to the canonical verbose format that CoreML's
own compiler emits (tensor<string, []>("x"), tensor<int32, []>(1)).

Also targets program(1.0) with <ios16> instead of program(1.3)/<ios18>,
and simplifies buildInfo to just coremlc-version.

For conv-based kernels, adds runtime fp16 I/O fallback — M1/M2 ANE
doesn't support the cast op (fp32<->fp16), so on first compile failure
it retries with native fp16 inputs/outputs and does the conversion on
the CPU side. The fallback is persisted across exec() restarts.

Note: matmul and scaled_dot_product_attention ops still fail on M1/M2 —
these are M4+ ANE ops. The attention tests (test_ane_causal_attn,
test_ane_sdpa5, test_full_fused attention part) require M4 hardware.
Conv-based kernels (training, QKV projections, FFN) work on all generations.

Tested on M1 Pro, macOS 26.3 (Tahoe).
@abhishekgahlot2
Copy link

abhishekgahlot2 commented Mar 2, 2026

you need to fix the other files too not just the training dir files to make it work on m1/m2.

@imperatormk
Copy link
Author

From what I see should be complete now although I'd like to fix attn too, would be keen to train a nice UNet like this

codegen-sh bot referenced this pull request in dermitchell1993/ANE Mar 2, 2026
Port upstream PR #6 (imperatormk) - fixes MIL scalar type syntax
from M4-only shorthand to canonical verbose format that compiles
on all Apple Silicon (M1/M2/M3/M4).

Changes:
- program(1.3) to program(1.0), ios18 to ios16 target
- Scalar type shorthand to canonical verbose format
- Simplified buildInfo dict (no M4-specific version strings)
- fp16 I/O fallback: g_fp16_io flag with auto-retry on compile
  failure for M1/M2 where cast op is unsupported
- Dynamic IOSurface byte calculation (bpe: 2 for fp16, 4 for fp32)

Tested on M1 Pro, macOS 26.3 (per upstream PR author).
dev-erik added a commit to dev-erik/ANE that referenced this pull request Mar 3, 2026
…program(1.0), ios16 target, tensor types across 18 files
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.

2 participants