Skip to content

Commit 8af4b3b

Browse files
committed
Try using TCMalloc on Linux by default
1 parent 22bcc7b commit 8af4b3b

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ sudo pacman -S wget git python3
120120
bash <(wget -qO- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh)
121121
```
122122
3. Run `webui.sh`.
123+
4. Check `webui-user.sh` for options.
123124
### Installation on Apple Silicon
124125

125126
Find the instructions [here](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon).

webui-user.sh

+3
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@
4343
# Uncomment to enable accelerated launch
4444
#export ACCELERATE="True"
4545

46+
# Uncomment to disable TCMalloc
47+
#export NO_TCMALLOC="True"
48+
4649
###########################################

webui.sh

+18-3
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ case "$gpu_info" in
113113
printf "Experimental support for Renoir: make sure to have at least 4GB of VRAM and 10GB of RAM or enable cpu mode: --use-cpu all --no-half"
114114
printf "\n%s\n" "${delimiter}"
115115
;;
116-
*)
116+
*)
117117
;;
118118
esac
119119
if echo "$gpu_info" | grep -q "AMD" && [[ -z "${TORCH_COMMAND}" ]]
120120
then
121121
export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2"
122-
fi
122+
fi
123123

124124
for preq in "${GIT}" "${python_cmd}"
125125
do
@@ -172,15 +172,30 @@ else
172172
exit 1
173173
fi
174174

175+
# Try using TCMalloc on Linux
176+
prepare_tcmalloc() {
177+
if [[ "${OSTYPE}" == "linux"* ]] && [[ -z "${NO_TCMALLOC}" ]] && [[ -z "${LD_PRELOAD}" ]]; then
178+
TCMALLOC="$(ldconfig -p | grep -Po "libtcmalloc.so.\d" | head -n 1)"
179+
if [[ ! -z "${TCMALLOC}" ]]; then
180+
echo "Using TCMalloc: ${TCMALLOC}"
181+
export LD_PRELOAD="${TCMALLOC}"
182+
else
183+
printf "\e[1m\e[31mCannot locate TCMalloc (improves CPU memory usage)\e[0m\n"
184+
fi
185+
fi
186+
}
187+
175188
if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ]
176189
then
177190
printf "\n%s\n" "${delimiter}"
178191
printf "Accelerating launch.py..."
179192
printf "\n%s\n" "${delimiter}"
193+
prepare_tcmalloc
180194
exec accelerate launch --num_cpu_threads_per_process=6 "${LAUNCH_SCRIPT}" "$@"
181195
else
182196
printf "\n%s\n" "${delimiter}"
183197
printf "Launching launch.py..."
184-
printf "\n%s\n" "${delimiter}"
198+
printf "\n%s\n" "${delimiter}"
199+
prepare_tcmalloc
185200
exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@"
186201
fi

0 commit comments

Comments
 (0)