Skip to content

Instantly share code, notes, and snippets.

@10c8
Last active September 18, 2024 19:01
Show Gist options
  • Save 10c8/1d11361a82d63da4116437e67d4a8f7e to your computer and use it in GitHub Desktop.
Save 10c8/1d11361a82d63da4116437e67d4a8f7e to your computer and use it in GitHub Desktop.
Vast.ai ComfyUI Provisioning Script
#!/bin/bash
DEFAULT_WORKFLOW="https://gist.github.com/10c8/1d11361a82d63da4116437e67d4a8f7e/raw"
APT_PACKAGES=(
# "package-1"
)
PIP_PACKAGES=(
# "package-1"
)
NODES=(
"https://github.com/ltdrdata/ComfyUI-Manager"
"https://github.com/cubiq/ComfyUI_essentials"
"https://github.com/rgthree/rgthree-comfy"
"https://github.com/yolain/ComfyUI-Easy-Use"
"https://github.com/ltdrdata/ComfyUI-Inspire-Pack"
"https://github.com/ssitu/ComfyUI_UltimateSDUpscale"
"https://github.com/Fannovel16/comfyui_controlnet_aux"
"https://github.com/XLabs-AI/x-flux-comfyui"
)
CHECKPOINT_MODELS=(
# "https://civitai.com/api/download/models/505488" # Game icon Institute_mode
)
UNET_MODELS=(
"https://civitai.com/api/download/models/695998" # Flux.1 [DEV] fp8
)
CLIP_MODELS=(
"https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp8_e4m3fn.safetensors"
"https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors"
)
LORA_MODELS=(
# "https://huggingface.co/williampigmeu/celso-portiolli-flux-lora-v1/resolve/main/pytorch_lora_weights.safetensors" # Celso p0rt10ll1
"https://civitai.com/api/download/models/750008" # Deviant Flux
# "https://civitai.com/api/download/models/727681" # gudarziModernCartoonFlux
"https://civitai.com/api/download/models/792184" # Eldritch Comics Flux.1 [DEV]
# "https://civitai.com/api/download/models/305491" # Eldritch Comics SDXL
# "https://civitai.com/api/download/models/134645" # comic-style-xl
)
VAE_MODELS=(
# "https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/ae.safetensors"
"https://civitai.com/api/download/models/692121" # flux dev
# "https://civitai.com/api/download/models/505488" # sdxl
)
ESRGAN_MODELS=(
"https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth"
"https://huggingface.co/Akumetsu971/SD_Anime_Futuristic_Armor/resolve/main/4x_NMKD-Siax_200k.pth"
)
CONTROLNET_MODELS=(
"https://huggingface.co/XLabs-AI/flux-controlnet-collections/resolve/main/flux-canny-controlnet_v2.safetensors"
"https://huggingface.co/XLabs-AI/flux-controlnet-collections/resolve/main/flux-depth-controlnet_v2.safetensors"
)
### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###
function provisioning_start() {
if [[ ! -d /opt/environments/python ]]; then
export MAMBA_BASE=true
fi
source /opt/ai-dock/etc/environment.sh
source /opt/ai-dock/bin/venv-set.sh comfyui
provisioning_print_header
provisioning_get_apt_packages
provisioning_get_nodes
provisioning_get_pip_packages
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/ckpt" \
"${CHECKPOINT_MODELS[@]}"
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/unet" \
"${UNET_MODELS[@]}"
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/clip" \
"${CLIP_MODELS[@]}"
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/lora" \
"${LORA_MODELS[@]}"
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/controlnet" \
"${CONTROLNET_MODELS[@]}"
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/vae" \
"${VAE_MODELS[@]}"
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/esrgan" \
"${ESRGAN_MODELS[@]}"
provisioning_print_end
}
function pip_install() {
if [[ -z $MAMBA_BASE ]]; then
"$COMFYUI_VENV_PIP" install --no-cache-dir "$@"
else
micromamba run -n comfyui pip install --no-cache-dir "$@"
fi
}
function provisioning_get_apt_packages() {
if [[ -n $APT_PACKAGES ]]; then
sudo $APT_INSTALL ${APT_PACKAGES[@]}
fi
}
function provisioning_get_pip_packages() {
if [[ -n $PIP_PACKAGES ]]; then
pip_install ${PIP_PACKAGES[@]}
fi
}
function provisioning_get_nodes() {
for repo in "${NODES[@]}"; do
dir="${repo##*/}"
path="/opt/ComfyUI/custom_nodes/${dir}"
requirements="${path}/requirements.txt"
if [[ -d $path ]]; then
if [[ ${AUTO_UPDATE,,} != "false" ]]; then
printf "Updating node: %s...\n" "${repo}"
( cd "$path" && git pull )
if [[ -e $requirements ]]; then
pip_install -r "$requirements"
fi
fi
else
printf "Downloading node: %s...\n" "${repo}"
git clone "${repo}" "${path}" --recursive
if [[ -e $requirements ]]; then
pip_install -r "${requirements}"
fi
fi
done
}
function provisioning_get_default_workflow() {
if [[ -n $DEFAULT_WORKFLOW ]]; then
workflow_json=$(curl -s "$DEFAULT_WORKFLOW")
if [[ -n $workflow_json ]]; then
echo "export const defaultGraph = $workflow_json;" > /opt/ComfyUI/web/scripts/defaultGraph.js
fi
fi
}
function provisioning_get_models() {
if [[ -z $2 ]]; then return 1; fi
dir="$1"
mkdir -p "$dir"
shift
arr=("$@")
printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
for url in "${arr[@]}"; do
printf "Downloading: %s\n" "${url}"
provisioning_download "${url}" "${dir}"
printf "\n"
done
}
function provisioning_print_header() {
printf "\n##############################################\n# #\n# Provisioning container #\n# #\n# This will take some time #\n# #\n# Your container will be ready on completion #\n# #\n##############################################\n\n"
if [[ $DISK_GB_ALLOCATED -lt $DISK_GB_REQUIRED ]]; then
printf "WARNING: Your allocated disk size (%sGB) is below the recommended %sGB - Some models will not be downloaded\n" "$DISK_GB_ALLOCATED" "$DISK_GB_REQUIRED"
fi
}
function provisioning_print_end() {
printf "\nProvisioning complete: Web UI will start now\n\n"
}
function provisioning_has_valid_hf_token() {
[[ -n "$HF_TOKEN" ]] || return 1
url="https://huggingface.co/api/whoami-v2"
response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
-H "Authorization: Bearer $HF_TOKEN" \
-H "Content-Type: application/json")
# Check if the token is valid
if [ "$response" -eq 200 ]; then
return 0
else
return 1
fi
}
function provisioning_has_valid_civitai_token() {
[[ -n "$CIVITAI_TOKEN" ]] || return 1
url="https://civitai.com/api/v1/models?hidden=1&limit=1"
response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
-H "Authorization: Bearer $CIVITAI_TOKEN" \
-H "Content-Type: application/json")
# Check if the token is valid
if [ "$response" -eq 200 ]; then
return 0
else
return 1
fi
}
# Download from $1 URL to $2 file path
function provisioning_download() {
if [[ -n $HF_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?huggingface\.co(/|$|\?) ]]; then
auth_token="$HF_TOKEN"
elif
[[ -n $CIVITAI_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?civitai\.com(/|$|\?) ]]; then
auth_token="$CIVITAI_TOKEN"
is_civitai=1
fi
if [[ -n $auth_token ]];then
if [[ -n $is_civitai ]];then
wget -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1?token=$auth_token"
else
wget --header="Authorization: Bearer $auth_token" -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
fi
else
wget -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
fi
}
provisioning_start
{
"last_node_id": 25,
"last_link_id": 32,
"nodes": [
{
"id": 8,
"type": "VAEDecode",
"pos": [
940,
-10
],
"size": {
"0": 210,
"1": 46
},
"flags": {
"collapsed": true,
"pinned": true
},
"order": 14,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": 14
},
{
"name": "vae",
"type": "VAE",
"link": 29
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
15
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "VAEDecode"
}
},
{
"id": 11,
"type": "DualCLIPLoader",
"pos": [
0,
-120
],
"size": {
"0": 315,
"1": 106
},
"flags": {
"pinned": true
},
"order": 0,
"mode": 0,
"outputs": [
{
"name": "CLIP",
"type": "CLIP",
"links": [
26
],
"slot_index": 0,
"shape": 3
}
],
"properties": {
"Node name for S&R": "DualCLIPLoader"
},
"widgets_values": [
"clip_l.safetensors",
"t5xxl_fp8_e4m3fn.safetensors",
"flux"
]
},
{
"id": 12,
"type": "BasicGuider",
"pos": [
780,
-10
],
"size": {
"0": 241.79998779296875,
"1": 46
},
"flags": {
"collapsed": true,
"pinned": true
},
"order": 12,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 32
},
{
"name": "conditioning",
"type": "CONDITIONING",
"link": 11
}
],
"outputs": [
{
"name": "GUIDER",
"type": "GUIDER",
"links": [
13
],
"slot_index": 0,
"shape": 3
}
],
"properties": {
"Node name for S&R": "BasicGuider"
}
},
{
"id": 13,
"type": "CLIPTextEncodeFlux",
"pos": [
10,
50
],
"size": {
"0": 386,
"1": 266.79998779296875
},
"flags": {
"pinned": true
},
"order": 11,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 30
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
11
],
"shape": 3
}
],
"properties": {
"Node name for S&R": "CLIPTextEncodeFlux"
},
"widgets_values": [
"30mm, film, kodak, light and shadows, motion blur, chromatic aberration",
"A man with a man bun, wearing light blue puffer jacket, puffy white pants, white Adidas shoes with black stripes. Standing on a staircase, looking back, from below. At a foggy night, lamp posts illuminate the scene.\nAction pose. Taken on a 30mm film camera with flash.",
3
]
},
{
"id": 14,
"type": "SamplerCustomAdvanced",
"pos": [
400,
50
],
"size": {
"0": 240,
"1": 350
},
"flags": {
"pinned": true
},
"order": 13,
"mode": 0,
"inputs": [
{
"name": "noise",
"type": "NOISE",
"link": 19
},
{
"name": "guider",
"type": "GUIDER",
"link": 13
},
{
"name": "sampler",
"type": "SAMPLER",
"link": 17
},
{
"name": "sigmas",
"type": "SIGMAS",
"link": 20
},
{
"name": "latent_image",
"type": "LATENT",
"link": 18
}
],
"outputs": [
{
"name": "output",
"type": "LATENT",
"links": [
14
],
"slot_index": 0,
"shape": 3
},
{
"name": "denoised_output",
"type": "LATENT",
"links": null,
"shape": 3
}
],
"properties": {
"Node name for S&R": "SamplerCustomAdvanced"
}
},
{
"id": 15,
"type": "VAELoader",
"pos": [
0,
-220
],
"size": {
"0": 315,
"1": 58
},
"flags": {
"pinned": true
},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "VAE",
"type": "VAE",
"links": [
28
],
"slot_index": 0,
"shape": 3
}
],
"properties": {
"Node name for S&R": "VAELoader"
},
"widgets_values": [
"ae.safetensors"
]
},
{
"id": 16,
"type": "PreviewImage",
"pos": [
650,
40
],
"size": {
"0": 640,
"1": 620
},
"flags": {
"collapsed": false,
"pinned": true
},
"order": 15,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 15
}
],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 17,
"type": "KSamplerSelect",
"pos": [
10,
470
],
"size": {
"0": 315,
"1": 58
},
"flags": {
"pinned": true
},
"order": 2,
"mode": 0,
"outputs": [
{
"name": "SAMPLER",
"type": "SAMPLER",
"links": [
17
],
"shape": 3
}
],
"properties": {
"Node name for S&R": "KSamplerSelect"
},
"widgets_values": [
"euler"
]
},
{
"id": 18,
"type": "EmptyLatentImage",
"pos": [
400,
440
],
"size": {
"0": 240,
"1": 110
},
"flags": {
"pinned": true
},
"order": 3,
"mode": 0,
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"links": [
18
],
"shape": 3
}
],
"properties": {
"Node name for S&R": "EmptyLatentImage"
},
"widgets_values": [
1024,
1024,
1
]
},
{
"id": 19,
"type": "RandomNoise",
"pos": [
10,
350
],
"size": {
"0": 315,
"1": 82
},
"flags": {
"pinned": true
},
"order": 4,
"mode": 0,
"outputs": [
{
"name": "NOISE",
"type": "NOISE",
"links": [
19
],
"shape": 3
}
],
"properties": {
"Node name for S&R": "RandomNoise"
},
"widgets_values": [
593319983543546,
"randomize"
]
},
{
"id": 20,
"type": "BasicScheduler",
"pos": [
10,
560
],
"size": {
"0": 315,
"1": 106
},
"flags": {
"pinned": true
},
"order": 10,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 31
}
],
"outputs": [
{
"name": "SIGMAS",
"type": "SIGMAS",
"links": [
20
],
"shape": 3
}
],
"properties": {
"Node name for S&R": "BasicScheduler"
},
"widgets_values": [
"simple",
20,
1
]
},
{
"id": 21,
"type": "UNETLoader",
"pos": [
0,
-340
],
"size": {
"0": 315,
"1": 82
},
"flags": {
"pinned": true
},
"order": 5,
"mode": 0,
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"links": [
24
],
"slot_index": 0,
"shape": 3
}
],
"properties": {
"Node name for S&R": "UNETLoader"
},
"widgets_values": [
"flux1DevFp8_v10.safetensors",
"fp8_e5m2"
]
},
{
"id": 22,
"type": "Power Lora Loader (rgthree)",
"pos": {
"0": 350,
"1": -340,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"9": 0
},
"size": {
"0": 340.20001220703125,
"1": 118
},
"flags": {
"pinned": true
},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 24,
"dir": 3
},
{
"name": "clip",
"type": "CLIP",
"link": 26,
"dir": 3
}
],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"links": [
25
],
"slot_index": 0,
"shape": 3,
"dir": 4
},
{
"name": "CLIP",
"type": "CLIP",
"links": [
27
],
"slot_index": 1,
"shape": 3,
"dir": 4
}
],
"properties": {
"Show Strengths": "Single Strength"
},
"widgets_values": [
null,
{
"type": "PowerLoraLoaderHeaderWidget"
},
null,
""
]
},
{
"id": 23,
"type": "Reroute",
"pos": [
780,
-370
],
"size": [
75,
26
],
"flags": {},
"order": 8,
"mode": 0,
"inputs": [
{
"name": "",
"type": "*",
"link": 25
}
],
"outputs": [
{
"name": "",
"type": "MODEL",
"links": [
31,
32
],
"slot_index": 0
}
],
"properties": {
"showOutputText": false,
"horizontal": false
}
},
{
"id": 24,
"type": "Reroute",
"pos": [
780,
-340
],
"size": [
75,
26
],
"flags": {},
"order": 9,
"mode": 0,
"inputs": [
{
"name": "",
"type": "*",
"link": 27
}
],
"outputs": [
{
"name": "",
"type": "CLIP",
"links": [
30
],
"slot_index": 0
}
],
"properties": {
"showOutputText": false,
"horizontal": false
}
},
{
"id": 25,
"type": "Reroute",
"pos": [
780,
-310
],
"size": [
75,
26
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "",
"type": "*",
"link": 28
}
],
"outputs": [
{
"name": "",
"type": "VAE",
"links": [
29
],
"slot_index": 0
}
],
"properties": {
"showOutputText": false,
"horizontal": false
}
}
],
"links": [
[
11,
13,
0,
12,
1,
"CONDITIONING"
],
[
13,
12,
0,
14,
1,
"GUIDER"
],
[
14,
14,
0,
8,
0,
"LATENT"
],
[
15,
8,
0,
16,
0,
"IMAGE"
],
[
17,
17,
0,
14,
2,
"SAMPLER"
],
[
18,
18,
0,
14,
4,
"LATENT"
],
[
19,
19,
0,
14,
0,
"NOISE"
],
[
20,
20,
0,
14,
3,
"SIGMAS"
],
[
24,
21,
0,
22,
0,
"MODEL"
],
[
25,
22,
0,
23,
0,
"*"
],
[
26,
11,
0,
22,
1,
"CLIP"
],
[
27,
22,
1,
24,
0,
"*"
],
[
28,
15,
0,
25,
0,
"*"
],
[
29,
25,
0,
8,
1,
"VAE"
],
[
30,
24,
0,
13,
0,
"CLIP"
],
[
31,
23,
0,
20,
0,
"MODEL"
],
[
32,
23,
0,
12,
0,
"MODEL"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1,
"offset": [
0,
0
]
}
},
"version": 0.4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment