From 86ed98aacaa8b2037aad795abd11cdca122cf39f Mon Sep 17 00:00:00 2001 From: Naozumi Date: Thu, 13 Jul 2023 15:05:35 +0800 Subject: [PATCH] Add .sh run script for macOS & linux, fix error on macs with low vram. (#737) * Add .sh run script * Update extract_feature_print.py * Remove `requirements_macOS.txt` --- extract_feature_print.py | 1 + run.sh | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 run.sh diff --git a/extract_feature_print.py b/extract_feature_print.py index dfa74e2..780ffbc 100644 --- a/extract_feature_print.py +++ b/extract_feature_print.py @@ -1,6 +1,7 @@ import os, sys, traceback os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" +os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0" # device=sys.argv[1] n_part = int(sys.argv[2]) diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..9f7186e --- /dev/null +++ b/run.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +if [[ "$(uname)" == "Darwin" ]]; then + # macOS specific env: + export PYTORCH_ENABLE_MPS_FALLBACK=1 + export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 +elif [[ "$(uname)" != "Linux" ]]; then + echo "Unsupported operating system." + exit 1 +fi + +requirements_file="requirements.txt" + +# Check if Python 3.8 is installed +if ! command -v python3.8 &> /dev/null; then + echo "Python 3.8 not found. Attempting to install..." + if [[ "$(uname)" == "Darwin" ]] && command -v brew &> /dev/null; then + brew install python@3.8 + elif [[ "$(uname)" == "Linux" ]] && command -v apt-get &> /dev/null; then + sudo apt-get update + sudo apt-get install python3.8 + else + echo "Please install Python 3.8 manually." + exit 1 + fi +fi + +# Check if required packages are installed and install them if not +if [ -f "${requirements_file}" ]; then + installed_packages=$(python3.8 -m pip freeze) + while IFS= read -r package; do + [[ "${package}" =~ ^#.* ]] && continue + package_name=$(echo "${package}" | sed 's/[<>=!].*//') + if ! echo "${installed_packages}" | grep -q "${package_name}"; then + echo "${package_name} not found. Attempting to install..." + python3.8 -m pip install --upgrade "${package}" + fi + done < "${requirements_file}" +else + echo "${requirements_file} not found. Please ensure the requirements file with required packages exists." + exit 1 +fi + +# Run the main script +python3.8 infer-web.py --pycmd python3.8 \ No newline at end of file