Last active
July 29, 2023 21:54
-
-
Save x/33a3364ad36bce61a481522660f95ba5 to your computer and use it in GitHub Desktop.
Makefile for https://github.com/apple/ml-stable-diffusion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.DEFAULT: setup | |
SHELL = /bin/bash | |
NAME := coreml_stable_diffusion | |
PYMAJOR := 3 | |
PYREV := 8 | |
PYPATCH := 10 | |
PYVERSION := ${PYMAJOR}.${PYREV}.${PYPATCH} | |
PYENV := ~/.pyenv/versions/${PYVERSION} | |
VENV_NAME := ${NAME}-${PYVERSION} | |
VENV := ${PYENV}/envs/${VENV_NAME} | |
EGGLINK := ${VENV}/lib/python${PYMAJOR}.${PYREV}/site-packages/${NAME}.egg-link | |
MLPACKAGES_DIR=./mlpackages | |
OUT_DIR=./out | |
${PYENV}: | |
pyenv install ${PYVERSION} | |
${VENV}: ${PYENV} | |
pyenv virtualenv ${PYVERSION} ${VENV_NAME} | |
.python-version: ${VENV} | |
echo ${VENV_NAME} >.python-version | |
${EGGLINK}: | |
PYENV_VERSION=${VENV_NAME} VIRTUAL_ENV=${VENV} ${VENV}/bin/pip install -e . | |
# an update-install might not necessarily update this | |
touch ${EGGLINK} | |
setup: .python-version ${EGGLINK} | |
brew install huggingface-cli | |
echo "Create an account for huggingface.co (where we're fetching the models from) if you don't have one already. Create and copy an auth token." | |
open "https://huggingface.co/settings/tokens" | |
huggingface-cli login | |
PYENV_VERSION=${VENV_NAME} VIRTUAL_ENV=${VENV} ${VENV}/bin/python -m python_coreml_stable_diffusion.torch2coreml --convert-unet --convert-text-encoder --convert-vae-decoder --convert-safety-checker -o ${MLPACKAGES_DIR} | |
clean: | |
git clean -fdx | |
nuke: | |
git clean -fdx | |
rm -f .python-version | |
/usr/local/bin/pyenv uninstall -f ${PYVERSION} | |
rm -f ~/.pyenv/versions/${VENV_NAME} | |
generate: | |
PYENV_VERSION=${VENV_NAME} VIRTUAL_ENV=${VENV} ${VENV}/bin/python -m python_coreml_stable_diffusion.pipeline --prompt "${PROMPT}" -i "${MLPACKAGES_DIR}" -o "${OUT_DIR}" --compute-unit ALL --seed 93 && open "${OUT_DIR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment