Skip to content

Instantly share code, notes, and snippets.

@TheEricMiller
Last active July 29, 2023 21:53
Show Gist options
  • Select an option

  • Save TheEricMiller/1180de8a1f302875fd994284c56b3a12 to your computer and use it in GitHub Desktop.

Select an option

Save TheEricMiller/1180de8a1f302875fd994284c56b3a12 to your computer and use it in GitHub Desktop.
Setup Stable-Diffusion on MacOS with Apple Silicon (M1 +) CPU

Setup Stable-Diffusion on MacOS with Apple Silicon (M1 +) CPU

Try Stable-Diffusion in Discord

Install UI and Run Stable Diffusion Locally

Download & Install MacOS Converted Models

  1. DOWNLOAD THIS EXAMPLE MODEL <=== (Large File ~2-5GB)

  2. Extract the downloaded zip file in Downloads folder

  3. Move the extracted folder to a local model folder

    • Open Fresh Terminal

    • Following command will open Downloads folder & create a new local folder for the model & open it in Finder

    • $cd ~/Downloads ; open . ; mkdir ~/zDev/AI/stable-diffusion ; cd ~/zDev/AI/stable-diffusion ; open .

    • Manually Extract & Move the folder from the zip file to the local model folder

      • For example $mv ~/Downloads/stable-diffusion-v2.1-base_split-einsum_compiled ~/zDev/AI/stable-diffusion/
  4. Update Settings in Mochi Diffusion App

    • Open Mochi Diffusion App (if not already open) with (CMD ⌘ + Space) and typing Mochi and pressing enter
    • Click Settings with (CMD ⌘ + COMMA ,)
    • Click "Model Folder" and search for the local model folder (for example the one created at ~/zDev/AI/stable-diffusion/)
    • Click "Apply" to save changes
  5. Pick Model in UI

    • At bottom left of the UI, click the dropdown and select the model you'd like to use
    • For example, choose "stable-diffusion-v2.1-base_split-einsum_compiled"
    • As it notes, select "Nueral Engine" for best performance with CoreML "split-einsum" models
  6. Enter Prompt text like "yachts in bahamas" & click "Generate" button

    • First time you run the app, it will take a few minutes to load the model, you can see progress by clicking spinning icon to left of trash can icon

Explore Different Models and Diffusers

Try Different Models

  • Download THIS PRE-CONVERTED MODEL

  • Do steps 2-5 above

  • Click the Refresh icon at bottom left of the UI, and select the "ProGen" model

  • Try with:

    • Prompt: modelshoot style, (extremely detailed CG unity 8k wallpaper), full shot body photo, medieval armor, professional majestic oil painting by Ed Blinkey, Atey Ghailan, Studio Ghibli, by Jeremy Mann, Antonio Moro, trending on CGSociety, Intricate, High Detail, dramatic, photorealistic
    • Remove: canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((extra limbs)),((close up)),((b&w)), wierd colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], mutated hands
    • Seed: 105259061
  • Review & Download CoreML (Apple Silicon) Models from HuggingFace

  • For Advanced Users explore how to Convert models to be Core ML. More on Converting HERE. Some pre-converted examples here

Install Diffusers

  • Update pip with Run $pip install --upgrade pip
  • Install diffusers with Run $pip install diffusers transformers accelerate scipy safetensors

Notes:

  • Folder with "split_einsum" version is compatible with all compute unit options including Neural Engine (BEST & MOST NATIVE)

  • Folder with "original" version is only compatible with CPU & GPU option By default, the app's model folder will be created under the Documents folder. This location can be customized under Settings In the model folder, create a new folder with the name you'd like displayed in the app then move or extract the converted models here Your directory should look like this:

  • Checkout MacOS UI App Mochi Diffusion

  • Check Out Community Projects & Models on https://huggingface.co/

  • For Example an Upscaller Check Here

Setup MacOS Dev Environment

Some Dev Env(iroment) Basics

  • Open Fresh Terminal Window with Spotlight Search (CMD ⌘ + Space), typing Terminal and pressing enter; OR if already open (CMD ⌘ + N) for a new window, or (CMD ⌘ + T) for a new tab. This will confirm latest settings are loaded after recent installs or changes.

  • Check what is installed...

    • Run combined check with $ echo " " && echo "——— ——— CHECKING VERSIONS ––– ——— " && sw_vers; echo "~~~" && git -v; echo "~~~" && brew -v; echo "~~~" && echo "VScode" && code -v; echo "~~~" && echo "NVM" && nvm -v && echo "~~~" && echo "NodeJS" && node -v && echo "~~~" && echo "Yarn" && yarn -v && echo "~~~" && pyenv -v && echo "~~~" && python --version && echo "~~~" && rustup --version && echo "~~~" && rustc --version && echo "~~~" && solana --version && echo "~~~" && avm --version && echo "~~~" && anchor --version && echo "===~===~===~===~===~===~===~===" && echo " " && code .

    Or individually if something fails...

    • Run $brew -v to see if Homebrew is installed

    • Run $code -v to see if VScode is installed

    • Run $nvm -v to see if NVM is installed

    • Run $node -v to see if Node is installed

    • Run $yarn -v to see if Yarn is installed

    • Run $pyenv -v to see if Python Version Manager is installed

    • Run $python --version to see if Python is installed

    • Run $rustup --version to see if Rust Version Manager is installed

    • Run $rustc --version to see if Rust is installed

    • Run $solana --version to see if Solana is installed

    • Run $avm --version to see if Anchor Version Manager is installed

    • Run $anchor --version to see if Anchor is installed

Install Homebrew

(and confirm Xcode Command Line Tools are installed)

  • Install Homebrew

    • Open Fresh Terminal (See "Basics" Above)
    • Copy and paste the following command into the Terminal and press enter
    • /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • Open Fresh Terminal, close old Terminal windows/tabs
    • Run $brew update and brew upgrade to make sure everything is up to date
    • Run $brew doctor and follow the instructions to fix any issues
    • If you get a message saying Your system is ready to brew, you're good to go!
  • Install wget

    • Run $brew install wget
    • Run $wget --version to confirm it's installed

Install Rosetta

  • Install Rosetta for Apple Silicon
    • Open Fresh Terminal
    • Run $arch to verify the architecture is arm64
    • Run $softwareupdate --install-rosetta --agree-to-license to install Rosetta

Install Python w/ Version Manager

  • Install pyenv Version Manager
    • Open Fresh Terminal
    • Run $brew install pyenv
    • Check to see latest version of Python at Python.org MacOS
    • Run $pyenv install #.#.# where # is the latest version of Python
    • Run $pyenv global #.#.# to set the version of Python the system will use
    • Open Fresh Terminal
    • Run $python --version to verify the version is set and correct

Install X

Optional Tools

Install VScode Editor

  • Install VScode via Homebrew Cask
    • Open Fresh Terminal
    • Run $brew install --cask visual-studio-code
    • After install, Launch VScode...
      • Install VScode Command Line Tools
      • Open the Command Palette (CMD ⌘ + Shift + P) in VScode
      • type shell command to find the Shell Command: Install 'code' command in PATH command.
    • Open Fresh Terminal
    • Run $code --version to verify the version is set and correct
    • Now you can Run $code . to open the current directory in VScode

Other Languages

For Web Projects

  • Install NodeJS via NVM (Node Version Manager) via Homebrew Formula

    • Open Fresh Terminal

    • Run $brew install nvm

    • After install (linked above), confirm update to your PATH in your Terminal with the following command:

      • Open Fresh Terminal
      • Run $nvm --version
    • If you get a message saying that fails to update your PATH, you can do it manually, then try again in a fresh terminal window...

      • export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - nvm install node - nvm use node - node --version
    • Open Fresh Terminal

      • Install Node via NVM https://github.com/nvm-sh/nvm#usage
      • Run $nvm ls-remote to see all versions available
      • Run $nvm install node to isntall the latest stable version
      • Open Fresh Terminal
      • Run $node -v or --version to verify the version is set and correct
    • Install Yarn

For Crypto Projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment