IF icon indicating copy to clipboard operation
IF copied to clipboard

Does it work on M1?

Open eleijonmarck opened this issue 2 years ago • 3 comments

eleijonmarck avatar Apr 26 '23 19:04 eleijonmarck

I saw jsindy on the IF Discord (April 28) state that they got it working (slowly?) on Mac and posted what I assume to be the Python inference code. I don't know enough about Python to make use of it, though.

I've got an M2 Max with 64 GB unified memory and think that, barring heavy quantization, the Mac is probably the ideal consumer platform to run IF. I just wish there were more evidence of people working on it. I just don't have the expertise or time.

Adreitz avatar May 02 '23 15:05 Adreitz

No luck on an M1.

ysctl hw | grep BF16

returns

hw.optional.arm.FEAT_BF16: 0

So FEAT_BF16 is not supported on M1 but required by the model.

A full example you can try on your M2:

from deepfloyd_if.modules import IFStageI, IFStageII, StableStageIII
from deepfloyd_if.modules.t5 import T5Embedder
from huggingface_hub import login
from deepfloyd_if.pipelines import dream

login("<your hugginface token>", True)

device = 'mps'
if_I = IFStageI('IF-I-XL-v1.0', device=device)
if_II = IFStageII('IF-II-L-v1.0', device=device)
if_III = StableStageIII('stable-diffusion-x4-upscaler', device=device)
t5 = T5Embedder(device="cpu")


prompt = 'ultra close-up color photo portrait of rainbow owl with deer horns in the woods'
count = 1

result = dream(
    t5=t5, if_I=if_I, if_II=if_II, if_III=if_III,
    prompt=[prompt]*count,
    seed=42,
    if_I_kwargs={
        "guidance_scale": 7.0,
        "sample_timestep_respacing": "smart100",
    },
    if_II_kwargs={
        "guidance_scale": 4.0,
        "sample_timestep_respacing": "smart50",
    },
    if_III_kwargs={
        "guidance_scale": 9.0,
        "noise_level": 20,
        "sample_timestep_respacing": "75",
    },
)

if_III.show(result['III'], size=14)

If you don't have enough RAM, you can also try with the only if_I.

This is the setup (python 3.10.11 installed with pyenv):

pip install deepfloyd_if==1.0.2rc0
pip install xformers==0.0.16
pip install git+https://github.com/openai/CLIP.git --no-deps
pip install protobuf==3.20.3

faxioman avatar May 13 '23 05:05 faxioman

https://github.com/brkirch/DeepFloyd-IF-example-Mac

It will require 64 GB of RAM due to the Diffusers SD x4 upscaler pipeline being very memory inefficient on MPS. Only using the stage I and stage II models requires 32 GB.

brkirch avatar May 13 '23 12:05 brkirch