Live data from Hacker News

Stretch iPhone to its limit: 2GiB Stable Diffusion model runs locally on device

liuliu.me

121–130 of 184 posts

Re: Stretch iPhone to its limit: 2GiB Stable Diffusion model runs locally on device

#121

It works extremely fast on an iPad Pro M1 (kind of expected, but it's _impressive_) although the app is built as "iPhone only", and strangely enough the iPad is cropping the upscaled iPhone app so the lower bar of image controls don't show at all, which is a pity

Reach out to the author, they can likely fix this easily.

Re: Stretch iPhone to its limit: 2GiB Stable Diffusion model runs locally on device

#125
post #80

Congrats on the release! I gave this and other available applications a try and I don’t understand what people see in ai image generation. A simple prompt generated a person with 3 nostrils, 7 squished fingers, deformities everywhere I look, it just mashes a bunch of photographs together and generates abominations. Pay close attention to generated models and you will find details which are simply wrong. What is the u…

The use cases that are being explored now are:

Movie preparation, storytelling https://twitter.com/juliendorra/status/1590058518174134272 https://twitter.com/mrjonfinger/status/1590021753979670528

Fan art! https://twitter.com/rainisto/status/1581169461167816704 https://twitter.com/rainisto/status/1579474636202708993

Product shots and generative marketing https://twitter.com/dtcforeverr/status/1589916644939161600 https://twitter.com/kylebrussell/status/1590563734317338624

2D game assets, character design https://twitter.com/emmanuel_2m/status/1588249026272448512 https://twitter.com/elsableda/status/1562465392563351552

Imaginary selfies (self-portrait is a huge human use case!) https://twitter.com/stevenpargett/status/1590047241183821824 https://twitter.com/dh7net/status/1581298913637646336 https://twitter.com/fabianstelzer/status/1579818105672302592

Styling by example https://twitter.com/norod78/status/1590056501544386560

Raw sketch to final image https://twitter.com/nousr_/status/1564797121412210688

Editing in the most generic sense (replacing part of an image) https://twitter.com/bigblueboo/status/1585761916718383110

Re: Stretch iPhone to its limit: 2GiB Stable Diffusion model runs locally on device

#126
post #45

This is super cool. I just tried the default prompt on my iPhone 13 with the image size set to 768x512 and using the 3D Model (Redshift v1) and it just crashed the whole phone and restarted. Just like when I get BSOD's at work on my Windows GPU desktop :)

You should see a warning when selecting that size? 4GiB model cannot run at that resolution until someone implemented FlashAttention on Metal :)

Nice work :)

Porting FlashAttention to Metal will be quite hard. Because for performance reasons, they did a lot of shenanigans to respect the memory hierarchy.

Thankfully, you can probably do something slower but more adapted to your memory constraints.

If you relax this need for performance and allow some re-computations, you can write a qkvatt function which takes q,k,v and a buffer to store the resulting attention, and compute without needing any extra memory.

The algorithm is still quadratic in time with respect to the attention horizon (although with a bigger constant (2x or 3x) due to the re computation). But it doesn't need any extra memory allocation which makes it easy to parallelize.

Alternatively you can use an O(attention horizon * number of thread in parallel) (like flash attention) extra memory buffer to avoid the re-computation.

Concerning the backward pass, that's the same thing, you don't need extra memory if you are willing to do some re-computation, or linear in attention horizon to not do re-computation.

One interesting thing to notice in the backward pass, is that it doesn't use the attn of the forward pass, so it doesn't need to be kept preserved (only need to preserve Q,K,V).

One little caveat of the backward pass (which you only need for training) is that it needs atomic_add to be easy to parallelize. This mean, it will be hard on Metal (afaik they don't have atomics for floats though they do have atomics for integer so you can probably use fixed points numbers).

Re: Stretch iPhone to its limit: 2GiB Stable Diffusion model runs locally on device

#128
post #6

Earlier quoted context omitted.

It does warn you on startup about the download if you're not on wifi.

Good time to try 5G ultra capacity if you have it on an unlimited plan - will be faster than most people's wifi.

Pivot alert

I reached 3Gbps over Verizon 5G in San Antonio last year and this year i get about 4Mbps over Verizon 5G in Ohio. It’s so bad I disabled it. I did read an article that iPhone 12 (which is what I have) have some kind of radio issue with 5G. Can anyone in here confirm?

Re: Stretch iPhone to its limit: 2GiB Stable Diffusion model runs locally on device

#130
post #7

Earlier quoted context omitted.

MacOS has transparent memory compression. Unclear to me if that's made its way to iPhone, but if it hasn't yet it will sooner or later.

Memory compression is a generalization of swap, which is only for dynamic memory; files on disk don't need it because you can just read them off the disk. The problem is that GPUs don't support virtual memory paging, so they can't read files nor decompress nor swap anything unless you write it yourself, which is a lot slower. Also, ML models (probably) can't be compressed because they already are compressed; learning…

> Also, ML models (probably) can't be compressed because they already are compressed; learning and compression are the same thing!

I feel like they're kind of two sides of the same coin: learning is about putting more information in the same data, while compression is about putting the same information in less data.

I'm wondering if some lossy floating-point compressor (such as zfp) would work.

Post reply on HN