Skip to content

How I got this repo (entirely) running with pip (no conda) on M1 Mac #302

Closed
@stillmatic

Description

@stillmatic

Update: everything is working great

  1. Follow instructions in https://replicate.com/blog/run-stable-diffusion-on-m1-mac to get your environment setup, but of course clone this repo instead.
  2. You should use Python 3.10, not the suggested 3.9 (there is a bug with TypingAlias, as discussed in this thread)
  3. Apply chore: update requirements.txt to run on m1 w/pip #337 or check out my fork directly to install the updates.
  4. pip install -r requirements.txt; pip install -e .
  5. PYTORCH_ENABLE_MPS_FALLBACK=1 python scripts/dream.py --full_precision -A plms --web

You should see a warning >> cuda not available, using device mps - this is good! On fully loaded M1 Max, this is 1.5 it/s on keuler or 3.91it/s on PLMS.


I got various errors attempting to run the main repo as is (commit 3ee82d8), with pip install instead of conda install. this laptop doesn't have conda on it at all.

workaround is to setup a python env with 3.10 and update requirements.txt

-numpy==1.19.2
+numpy==1.23.1
+--pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
 omegaconf==2.1.1
-opencv-python==4.1.2.30
+opencv-python==4.6.0.66

also need to run pip install -e . to find ldm.

this enables me to run scripts and get output:

python ./scripts/orig_scripts/txt2img.py --prompt "ocean" --ddim_steps 5 --n_samples 1 --n_iter 1

grid-0000

✨ ✨ ✨ ✨ (output isn't great, but it works!)

however, dream.py has trouble running, even with the full_precision flag. that shows some errors like:

RuntimeError: expected scalar type BFloat16 but found Float

searching issues, I see that this is possibly due to hardcoded assumptions of CPU vs GPU (see #44 (comment)), internally somewhere the code expects a half-precision for GPU vs full-precision for CPU. since other scripts work but dream.py doesn't work, is there somewhere in dream.py with similar hard coded assumptions that we need to update? -- this is fixed in #319


everything runs great now on M1, though I have to set env var PYTORCH_ENABLE_MPS_FALLBACK=1. so, running

PYTORCH_ENABLE_MPS_FALLBACK=1 python scripts/dream.py --full_precision -A plms --web

works great!

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