Skip to content

Unable to run model on iPhone 14 Pro with error: "failed to load ANE model" — works fine from CLI #51

Open
@jverkoey

Description

@jverkoey

When I run:

let config = MLModelConfiguration()
config.computeUnits = .all
let pipeline try! StableDiffusionPipeline(resourcesAt: modelUrl, configuration: config)

I get the following error:

[espresso] [Espresso::handle_ex_plan] exception=ANECF error: failed to load ANE model. Error=ANECCompile(/var/mobile/Library/Caches/com.apple.aned/tmp/com.featherless.MLDemo/CD3F6A18321CD0468900D511BF6E116C1AC2F5D1DB1D65F480343B1E5551B8A8/7204A653B1634F14166A639585DE3E3EDCFE052221F97F3476ECE9475CD8A5DE/) FAILED: err=(
    CompilationFailure
)
[coreml] Error plan build: -1.
[client] doUnloadModel:options:qos:error:: nil _ANEModel

The model is a converted stablediffusion model. I converted it using the following command line invocation:

python3 -m python_coreml_stable_diffusion.torch2coreml --convert-unet \
  --convert-text-encoder --convert-vae-decoder --convert-safety-checker \
  -o /Users/featherless/MLDemo/new-model   --model-version featherless/test-model \
  --chunk-unet --bundle-resources-for-swift-cli

The same model runs fine when invoked via command line:

swift run StableDiffusionSample "a digital portrait of an astronaut riding a horse, futuristic, highly detailed, HDR, 4k, illustration" \
  --resource-path /Users/featherless/MLDemo/new-model/Resources  \
  --seed=1235 --output-path /Users/featherless/MLDemo/output

Environment

Xcode Version 14.1 (14B47b)
Apple M1 Max, Ventura 13.1
iPhone 14 Pro, iOS 16.1.2

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