ml-stable-diffusion icon indicating copy to clipboard operation
ml-stable-diffusion copied to clipboard

Terminated due to memory issue (when deploying on iOS)

Open martinlexow opened this issue 2 years ago • 11 comments

I was able to get StableDiffusion up and running in an app for macOS. Thanks for your incredible work, CoreML team!

However the same setup does not work on my iPhone 14 with iOS 16.2 (20C5058d) (no Simulator involved, tried it on a physical device).

Execution seems to struggle at line:

let pipeline = try StableDiffusionPipeline(resourcesAt: resourceURL)

...after a short freeze the app crashes and I’m getting an error from Xcode saying Terminated due to memory issue.

As recommended I’ve added the Increased Memory Limit capability to my project but without luck.

I also did use --chunk-unet, resulting in two unet chunks of about 850 MB each.

I am working with Xcode 14.1 (14B47) on a MBP 16 M1 Pro, 16 GB, macOS 13.0.1 Ventura.

What am I missing?

martinlexow avatar Dec 03 '22 19:12 martinlexow

In case it’s helpful, here’s the error log → errorlog.txt

martinlexow avatar Dec 03 '22 20:12 martinlexow

And here’s how it looks in Instruments. Screenshot 2022-12-03 at 21 15 34

martinlexow avatar Dec 03 '22 20:12 martinlexow

Terminated due to memory on an M1 iPad Pro too.

I don't see any way to set the image size to be generated which seems odd. Am I missing something?

3DTOPO avatar Dec 03 '22 21:12 3DTOPO

Ugh the model has a fixed output shape.

3DTOPO avatar Dec 03 '22 21:12 3DTOPO

I just built it with "--latent-w" and "--latent-h" set to 384 and still terminated do to memory.

I'm thinking it still uses the same amount of RAM since it looks like the Unet uses 64x64 regardless of the latent shape.

3DTOPO avatar Dec 04 '22 01:12 3DTOPO

Has anyone successfully run it on an iOS device? I found out not working properly , macOS 13.1 iPhone 14 simultor iOS 16.1

jiangdi0924 avatar Dec 04 '22 06:12 jiangdi0924

I believe it is a requirement to use iOS 16.2, but only iPad with M2 works for me, iPhone 13 Mini crashes as well :(

outcoldman avatar Dec 06 '22 07:12 outcoldman

I have this problem too, tested on an iPhone 13 pm

BIGPPWONG avatar Dec 07 '22 11:12 BIGPPWONG

Same here, iPhone 12. Looks like it doesn't have enough RAM

smocer avatar Dec 07 '22 12:12 smocer

I can run it on iPad Pro 12.9" M2 iOS 16.2. It fails on iPhone Mini 13 iOS 16.2 (compute units was set to cpuAndNL). And my primary iPhone 14 Pro is not updated yet to 16.2 (and it crashes on 16.1).

outcoldman avatar Dec 07 '22 16:12 outcoldman

I had it running on M1 iPad 16.2 Beta just fine, but crashed due to memory limit once updated to Today's 16.2 RC

legolasW avatar Dec 08 '22 06:12 legolasW