• Stars
    star
    130
  • Rank 271,018 (Top 6 %)
  • Language
  • Created almost 2 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Stable Diffusion: macOS install help with homebrew, python, anaconda, dream, etc.

Stable Diffusion: macOS install help

Stable Diffusion macOS install help is our guide for this kind of setup:

See our Stable Diffusion image gallery:

➀ https://github.com/joelparkerhenderson/stable-diffusion-image-gallery

Guide Goals

This guide is our notes about our preferred way of installing Stable Diffusion.

  • If you want an easy way to try Stable Diffusion on macOS, then try this first: https://diffusionbee.com/

  • If you want an easy way to try Stable Diffusion on macOS and other operating systems, then try this first: https://github.com/invoke-ai/InvokeAI

  • If you want maximum configurability on macOS, and you willing to install a bunch of software pieces, then try this guide.

This guide is intentionally step-by-step, because we want to help more people be successful, including people who are trying these kinds of software installs for the first time.

  • This guide is intentionally using steps that help multiple macOS users on the same system, because we want this guide to be able to help people who share a computer, such as teachers and students in schools.

  • This guide is intentionally doing a "kitchen sink" approach of installing everything, because this can help our people with more capabilities as they try Stable Diffusion.

We welcome constructive feedback via GitHub issues, or pull requests, or email to [email protected].

Thanks

Thanks to many developers working on Stable Diffusion and help for it, and special thanks to:

➀ https://www.assemblyai.com/blog/how-to-run-stable-diffusion-locally-to-generate-images/

➀ https://github.com/lstein/stable-diffusion/blob/main/README-Mac-MPS.md

➀ https://news.ycombinator.com/item?id=32678664

Homebrew

Install:

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Verify the path is typical:

% brew --prefix
/opt/homebrew

Verify your system can locate the program:

% which brew
/opt/homebrew/bin/brew

Verify the version is 3.5.10 or higher:

% brew --version
Homebrew 3.5.10

Do any brew upgrades:

% brew upgrade
% brew upgrade --cask --greedy

Verify brew is working:

% brew doctor

Python

Install:

brew install python

Verify the path is typical:

% brew --prefix python
/opt/homebrew/opt/[email protected]

Verify your system can locate the program:

% which python3
/opt/homebrew/bin/python3

Verify the version is 3.11 or higher:

% python3 --version
Python 3.11.3

cmake

Install:

% brew install cmake

Verify the path is typical:

% brew --prefix cmake 
/opt/homebrew/opt/cmake

Verify your system can locate the program:

% which cmake
/opt/homebrew/bin/cmake

Verify the version is 3.26 or higher:

% cmake --version
cmake version 3.26.3

git

Install:

% brew install git

Verify the path is typical:

% brew --prefix git  
/opt/homebrew/opt/git

Verify your system can locate the program:

% which git
/opt/homebrew/bin/git

Verify the version is 2.40 or higher:

% git --version
git version 2.40.0

protobuf

Install:

% brew install protobuf

Verify the path is typical:

% brew --prefix protobuf
/opt/homebrew/opt/protobuf

Anaconda

Install:

% brew install anaconda

Verify the version is 2023.03 or higher, and verify that the auto-update version is identical to the Caskroom version:

% brew info --cask anaconda
==> anaconda: 2023.03 (auto_updates)
…
/opt/homebrew/Caskroom/anaconda/2023.03 (304.8MB)
…

If the version is not 2023.03 or higher, or the auto-update version is not identical to the Caskroom version, then reinstall and reverify:

% brew reinstall --cask anaconda
…
==> Uninstalling Cask anaconda
…
==> Installing Cask anaconda
…
🍺  anaconda was successfully installed!

% brew info --cask anaconda

Create /opt directory

We like to install software such as anaconda within a system-wide top-level directory named "/opt", rather than within your personal user directory named "/Users/me" or similar.

This is because:

  • The directory "/opt" is what brew does by default

  • The "/opt" convention tends help with tutorials and troubleshooting as needed.

  • The system-wide directory makes it easier for multiple system users to all use the same Anaconda installation; for us, this tends to helps teachers and students who need to use shared systems.

Ensure the system-wide top-level directory exists:

% mkdir -p /opt

In the next step, we will install anaconda to this directory:

/opt/anaconda3

Script

Anaconda uses an installation shell script that you must run.

Find the script:

% find /opt/homebrew/Caskroom/anaconda -name "*.sh" 

Output shows the shell script name, which may use different version numbers depending on when you install Anaconda:

/opt/homebrew/Caskroom/anaconda/2023.03/Anaconda3-2023.03-MacOSX-arm64.sh

Run the shell script via sudo and sh and the script name from above:

% sudo sh /opt/homebrew/Caskroom/anaconda/2023.03/Anaconda3-2023.03-MacOSX-arm64.sh

Your system should prompt you to type your password, then should run the shell script.

License

Anaconda prompts you to agree to the license:

Do you accept the license terms? [yes|no]

Type yes, then return.

Directory

Anaconda prompts you to choose an installation directory:

Anaconda3 will now be installed into this location:
/Users/…/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

If you are generally a novice user, then use the Anaconda default directory, such as:

/Users/me/anaconda3

If you are generally an advanced user, then you may want to use our preferred naming convention, which installs many programs into the user's opt directory, such as:

/Users/me/opt/anaconda3

Type your installation directory, then return.

conda init

Anaconda prompts you to run this:

Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]

Type yes, then return.

Success

Anaconda installs and advises you:

For changes to take effect, close and re-open your current shell.

Close your current shell.

Open a new shell.

Verify the installation works by running Anaconda using its full path:

% /opt/anaconda3/condabin/conda --version
conda 23.1.0

Path

Export your preferred path such as:

export PATH="$PATH:/opt/anaconda3/condabin"

Optionally, you can append the Anaconda path to your environment, such as by editing whichever of these files you use, then closing your shell and opening a new shell:

  • /etc/bashrc

  • /etc/zshrc

  • $HOME/.bashrc

  • $HOME/.zshrc

Verify there is exactly one conda program on your path:

% which conda
/opt/anaconda3/condabin/conda

If you have more than one conda program on your path, then you'll need to be sure you're doing the rest of this guide using conda that you want.

  • You can adjust your path, so it chooses the right conda program first.

  • You can run conda via the full path /opt/anaconda3/condabin/conda.

  • You can uninstall the other conda programs, if no one on your system needs them.

Verify the version is 23.1.0 or higher:

% conda --version
conda 23.1.0

Update

Update conda just in case it's changed recently:

% sudo conda update -n base -c defaults conda

Stable Diffusion weights file

Download the Stable Diffusion weights file; heads up that the file is somewhat large, more than 4GB.

Stable Diffusion verison 2

Download the Stable Diffision version 2 checkpoint file:

curl -O -L https://huggingface.co/stabilityai/stable-diffusion-2-base/resolve/main/512-base-ema.ckpt

We prefer to move the file into its own directory because that makes it easier to use among all the system users:

% sudo mkdir -p /opt/stable-diffusion-checkpoints/2.0/
% sudo mv 512-base-ema.ckpt /opt/stable-diffusion-checkpoints/2.0/

Stable Diffision version 1 - DEPRECATED

Download the Stable Diffision version 1 checkpoint weights file:

curl -L https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt > sd-v1-4.ckpt

We prefer to put the file in its own directory so it's easier to access for all our macOS users:

% sudo mkdir -p /opt/stable-diffusion-checkpoints/1.4/
% sudo mv sd-v1-4.ckpt /opt/stable-diffusion-checkpoints/1.4/

Stable Diffusion repository

This section comes from:

➀ https://github.com/lstein/stable-diffusion/blob/main/README-Mac-MPS.md

Install

Install:

% cd ~
% git clone https://github.com/lstein/stable-diffusion.git
% cd stable-diffusion

If you have previously installed the repository, then change into its directory, and reset the branch:

% git reset --hard origin/master.

Link

Link to the CKPT file:

% mkdir -p models/ldm/stable-diffusion-v1/
% PATH_TO_CKPT="/opt/stable-diffusion-ckpt"  # use your own directory that contains your CPKT file
% ln -sfn "$PATH_TO_CKPT/sd-v1-4.ckpt" models/ldm/stable-diffusion-v1/model.ckpt

Create conda environment

Create:

% CONDA_SUBDIR=osx-arm64 conda env create -f environment-mac.yaml

You should see output such as:

Collecting package metadata (repodata.json)

Restart your terminal.

Activate

Activate:

% conda activate ldm

Preload models

Preload python models:

% python3 scripts/preload_models.py

Heads up that the script does downloads that are somewhat large, more than 1GB.

You should set output such as:

preloading bert tokenizer...
preloading Kornia requirements ...
preloading CLIP model ...

Run dream

Run:

% python3 scripts/dream.py --full_precision

You should see output such as:

* Initializing, be patient...
…
* Initialization done! Awaiting your command (-h for help, 'q' to quit)
dream> 

Note: we use the option --full-precision, and not the option --half-precision. This is because the option --half-precision requires autocast and won't work.

Troubleshooting TypeAlias

If you get this error...

File "…/stable-diffusion/src/k-diffusion/k_diffusion/sampling.py", line 10, in <module>
    from typing import Optional, Callable, TypeAlias
ImportError: cannot import name 'TypeAlias' from 'typing' ("…/opt/anaconda3/envs/ldm/lib/python3.9/typing.py)

Then try editing this file:

src/k-diffusion/k_diffusion/sampling.py`

Change this line:

from typing import Optional, Callable, TypeAlias

To:

from typing import Optional, Callable
from typing_extensions import TypeAlias

➀ invoke-ai/InvokeAI#302

Generating

When you have the dream prompt:

dream>

Then you can enter your own command such as:

"photography of a cat on the moon" -s 20 -n 3 --sampler k_euler -W 384 -H 384

You should see output such as:

Generating…
Outputs:
outputs/img-samples/000001.2080708373.png …
outputs/img-samples/000001.1839445463.png …
outputs/img-samples/000001.2463981689.png …

You might see warning messages that you can ignore for now:

…/stable-diffusion/ldm/modules/embedding_manager.py:152: 
UserWarning: The operator 'aten::nonzero' is not currently supported 
on the MPS backend and will fall back to run on the CPU. 
This may have performance implications.

Your output files are now ready in this directory:

outputs/img-samples

Troubleshooting

Troubleshooting can start with running these command line diagnostics:

brew --version

python3 --version

cmake --version

git --version

conda --version

which conda

# This may take a while because it's searching your entire system
find / -regex '.*/bin/conda' -type f -perm +111 -print

# This may show unexpected results if you have more than one conda
CONDA_SUBDIR=osx-arm64 conda env create -f environment-mac.yaml

conda activate ldm

python3 scripts/dream.py --full_precision

More Repositories

1

architecture-decision-record

Architecture decision record (ADR) examples for software planning, IT leadership, and template documentation
11,128
star
2

queueing-theory

Queueing theory: an introduction for software development
2,078
star
3

monorepo-vs-polyrepo

Monorepo vs. polyrepo: architecture for source code management (SCM) version control systems (VCS)
991
star
4

git-commit-message

Git commit message: how to write a great git commit message and commit template for version control
915
star
5

ways-of-working

Ways of Working (WoW) with team principles, values, tenets, ground rules, aspirations, norms, working agreements, shared expectations, and group understandings
619
star
6

objectives-and-key-results

Objectives and Key Results (OKR) examples for goals, tasks, plans, projects, and strategy.
344
star
7

pitch-deck

Pitch deck advice for startup founders who want to raise venture capital investment
285
star
8

demo-rust-axum

Demo of Rust and axum web framework with Tokio, Tower, Hyper, Serde
Rust
278
star
9

github-special-files-and-paths

GitHub special files and paths, such as README, LICENSE, .github, docs, dependabot, workflows.
192
star
10

stable-diffusion-image-prompt-gallery

Stable Diffusion: image prompt gallery of examples for various prompts
Shell
178
star
11

maturity-models

Maturity models for IT, Agile, DevOps, TOGAF, Six Sigma, P3M3, etc.
172
star
12

plantuml-examples

PlantUML eaxmples for UML, ERD, wireframes, mind maps, JSON, YAML, WBS, ASCII art, Gantt charts, C4 models, and more
168
star
13

git-commit-template

Git commit template for better commit messages
163
star
14

key-performance-indicator

Key performance indicator (KPI) examples for metrics, measurements, objectives and key results (OKRs)
129
star
15

brewfile

Brewfile
Ruby
111
star
16

crucial-conversations

Crucial conversations: lessons from the worldwide bestseller book
95
star
17

decision-record

Decision record: how to initiate and complete decisions for teams, organizations, and systems
92
star
18

statement-of-work

Statement Of Work (SOW) example
67
star
19

demo-swift-excel-xlsx-reader-writer

Demo Swift Excel Xlsx Reader Writer
Swift
60
star
20

inclusive-language

Inclusive language
57
star
21

strategic-balanced-scorecard

Strategic Balanced Scorecard: planning business by using OKRs, KPIs, and initiatives
49
star
22

issues

Issues: feature requests, bug reports, customer complaints, security alerts, etc.
44
star
23

oblique-strategies

Oblique Strategies: ideas for creative lateral thinking
42
star
24

care-plan

Care plan: a free open source care plan template for caregivers to help with medical, financial, government, legal, and practical care.
41
star
25

startup-superset

Startup superset: summaries of key concepts, ideas, insights
40
star
26

functional-specifications-template

Functional specifications template
40
star
27

always-improving

Book summaries by "alwaysimproving" for business, productivity, life skills, etc.
35
star
28

milestones

Milestones ideas and examples for project management
32
star
29

software-development-methodologies

Software development methodologies: summaries of agile, scrum, DAD, SAFe, etc.
31
star
30

social-network-plan

Social network plan - goals, ideas, step, and tasks for a new site
30
star
31

company-culture

Company culture ideas from Amazon, Netflix, Harvard, Ultimate, etc.
28
star
32

versioning

Versioning: what it is, how to do it, comments and discussion
28
star
33

leadership

Leadership and management ideas
27
star
34

spade-decision-framework

SPADE decision framework: Setting, People, Alternatives, Decide, Explain
27
star
35

system-quality-attributes

Cross-Functional Requirements a.k.a. Quality Attributes
26
star
36

ooda-loop

OODA loop: notes on John Boyd, strategy, tactics, planning, and paradigms
25
star
37

powerful-questions

Powerful questions - catalyzing insight, innovation, action
25
star
38

business-model-canvas

Business model canvas for value propositions, customer relationships, partner collaborations, etc.
25
star
39

thought-leadership-writing

Thought leadership writing tips for content creators, bloggers, authors, and editors
24
star
40

awesome-developing

Awesome developing: ideas for how to create better software code and collaboration
24
star
41

value-stream-mapping

Value Stream Mapping (VSM) tutorial (work in progress)
24
star
42

big-five-personality-traits

Big Five personality traits: domains, aspects, facets
22
star
43

source-code-management

Source code management β†’ notes and ideas β†’ mono-repos, trunk-based-development, etc.
21
star
44

key-risk-indicator

Key risk indicator (KRI) for risk management and business strategy
20
star
45

wordbooks

Demo wordbooks for business, projects, industries, software, consulting, and more
Lua
20
star
46

code-of-conduct-guidelines

Code of Conduct Guidelines
Shell
19
star
47

git-branch-name

Git branch name ideas, naming conventions, and how to use git branch edit description
19
star
48

git-workflow-help

Git flow help: research on Git flow, GitHub flow, GitLab flow, etc.
18
star
49

demo-tailwind-css

Demo Tailwind CSS along with Gulp and PostCSS
JavaScript
18
star
50

functional-specifications-tutorial

Functional specifications tutorial
17
star
51

sha256-sentence

SHA256 sentence: discover a SHA256 checksum that matches a sentence's description of hex digit words.
Rust
17
star
52

team-focus

TEAM FOCUS concepts by Paul N. Friga in McKinsey Engagement.
17
star
53

stakeholder-analysis

Stakeholder analysis for business project management
HTML
17
star
54

smart-criteria

SMART criteria for goals, objectives, plans, etc.
16
star
55

interviewing

Interviewing ideas for hiring managers, job seekers, and recruiting candidates
16
star
56

vision_mission_statements

Vision statements and mission statements by many companies and organizations
16
star
57

goals-ideas-steps-tasks

Goals, Ideas, Steps, Tasks: GIST Planning
14
star
58

icebreaker-questions

Icebreaker questions to help people, groups, teams, meetings, and such
14
star
59

coordinated-disclosure

Coordinated disclosure for security discoveries, bug reports, etc.
13
star
60

outputs-vs-outcomes

Outputs vs. outcomes: what's the different and why does it matter?
12
star
61

discovery-assessment

Discovery assessment for project management
12
star
62

critical-success-factor

Critical Success Factor (CSF) tutorial
12
star
63

software-operations-items

Software operations items
12
star
64

demo-rust-cargo-tdd

Demo of Rust and Cargo for TDD (test driven development)
Rust
11
star
65

agile-assessment

Agile assessment exercise ideas
11
star
66

metrics

Metrics
10
star
67

responsibility-assignment-matrix

Responsibility assignment matrix (RAM) a.k.a. linear responsibility chart (LRC)
10
star
68

social-value-orientation

Social value orientation (SVO) notes for pro-social pro-self concepts
10
star
69

demo-elixir-phoenix

Demonstration of Elixir language and Phoenix framework
Elixir
10
star
70

pgp-gpg-help

Pretty Good Privacy (PGP) GNU Privacy Guard (GPG) help for encryption
9
star
71

causal-analysis-based-on-system-theory

Causal Analysis based on System Theory (CAST)
9
star
72

demo-job-descriptions

Demo job descriptions
9
star
73

demo-terraform-aws

Demo of Terraform by Hasicorp for AWS
HCL
9
star
74

lean-business-lists

Lean business lists
9
star
75

issue-postmortem-template

Issue postmortem template for incident response documentation
8
star
76

net-promoter-score

Net Promoter Score (NPS) introduction and recommendations
8
star
77

initiatives-and-experiments

Initiatives and experiments
8
star
78

demo-rust-cursive

Demo Rust Cursive crate for terminal user interface (TUI)
Rust
8
star
79

demo-swift-rest

Demo Swift REST
HTML
8
star
80

git-hooks

Git hooks
Shell
7
star
81

demo-devops

Demo devops
7
star
82

adkar-change-management-model

ADKAR change management model: awareness, desire, knowledge, ability, reinforcement
7
star
83

demo-optaplanner

Demo OptaPlanner constraint solver
Java
6
star
84

intent-plan

Intent plan for mision, state, sequence, decisions, antigoals, constraints, expressives
6
star
85

demo-rust-rocket

Demo of Rust Rocket web application framework
Rust
6
star
86

task-life-cycle

Task life cycle (TLC)
5
star
87

feedback-request-template

Feedback request template
5
star
88

first-aid-kit

First Aid Kit
5
star
89

inspiring-people

Inspiring people: one hundred living people with short bios thanks to Wikipedia
5
star
90

principles

Principles: summaries of ethical prinicples, leadership principles, teamwork principles, ui/ux design principles, software programming principles, etc.
5
star
91

demo-aws-ses-smtp

Demo of Amazon Web Services (AWS) Simple Email Service (SES) Simple Mail Transfer Protocol (SMTP)
4
star
92

aberystwyth-wales-book

Aberystwth Wales Book - Photos of the Town
Shell
4
star
93

safety-philosophy

Safety philosopy: example principles for an organization and management
4
star
94

demo-shopping-cart-exercise-with-ruby

Shopping cart exercise with Ruby: how to program a shop, cart, till, checkout, etc. with TDD
Ruby
4
star
95

demo-gulp

Demo gulpfile.js using Gulp, PostCSS, Tailwind CSS, Pino, unfold, and more
JavaScript
4
star
96

git-troubleshooting

Git troubleshooting
4
star
97

demo-svelte-hello-world

Demo Svelte JavaScript framework "hello world" app
JavaScript
4
star
98

demo-ansible

Demo Ansible configuration tool for install, update, users, groups, etc.
4
star
99

quad-chart

Quad chart: a rapid project planning summary guide
4
star
100

adventure-gear

Adventure gear for traveling, backpacking, camping, and more
4
star