T-Stitch / run_examples.sh
Ouzhang's picture
Add files using upload-large-folder tool
e5371e6 verified
Raw
History Blame Contribute Delete
8.07 kB
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
usage() {
cat <<'EOF'
T-Stitch command helper.
This script groups the main runnable entrypoints in this repository.
Most commands assume you are using a GPU environment and have already
downloaded the required model weights or datasets.
Usage:
./run_examples.sh <command> [extra args...]
Commands:
help
Print this help.
install-basic
Install the root-level Python dependencies from requirements.txt.
gradio
Launch the Gradio demo for SD 1.x, SDXL, and SDXL + LCM examples.
sd-demo
Run the Stable Diffusion T-Stitch demo at the repo root.
sdxl-demo
Run the SDXL T-Stitch ratio sweep demo.
sdxl-canny
Run the SDXL + ControlNet canny demo.
Use -- --image /path/to/image.jpg to override the synthetic fallback image.
sdxl-depth
Run the SDXL + ControlNet depth demo.
Use -- --image /path/to/image.jpg to override the synthetic fallback image.
sdxl-pose
Run the SDXL + ControlNet openpose demo.
Note: this downloads a reference image from Hugging Face.
sdxl-lcm
Run the SDXL + LCM-LoRA T-Stitch demo.
train-sdxl -- <train args...>
Launch SDXL T-Stitch training with accelerate.
Example:
./run_examples.sh train-sdxl -- \
--train_data_dir /path/to/images \
--metadata_file /path/to/metadata.jsonl \
--ratio 0.3
dit-sample
Run the DiT T-Stitch sampling example from dit/sample_t_stitch.py.
dit-sample-all
Run the DiT all-tradeoffs sampling example.
dit-train -- <train args...>
Launch DiT T-Stitch training from dit/train_t_stitch.py.
Example:
./run_examples.sh dit-train -- \
--data-path /path/to/imagenet_train \
--ratio 0.3 \
--ratio-schedule fixed \
--image-size 256 \
--global-batch-size 4 \
--epochs 1
dit-fid
Run distributed DiT T-Stitch sample generation for FID evaluation.
Extra args are passed to dit/sample_ddp_t_stitch.py.
dit-fid-xl-b
Generate the Figure 5 DiT-B/XL ratio sweep.
dit-fid-b-s
Generate the Figure 5 DiT-S/B ratio sweep.
dit-fid-three
Generate the Figure 6 DiT-S/B/XL three-model sweep.
dit-fid-dpm
Generate Figure 8-style DiT-S/XL samples with DPM-Solver++.
sd-coco-generate -- --prompts /path/to/captions_val2014.json --output-dir outputs/sd_coco
Generate SD/BK-SDM T-Stitch images for MS-COCO prompt evaluation.
sd-pack -- --image-dir outputs/sd_coco/ratio-0.3 --output outputs/sd_coco/ratio-0.3.npz
Pack generated images into an ADM-style .npz file for FID/IS.
clip-score -- --metadata outputs/sd_coco/ratio-0.3/metadata.jsonl
Compute CLIP cosine score for generated prompt-image pairs.
sdxl-prompts -- --prompts prompts.txt --output-dir outputs/sdxl_prompts
Generate SDXL/SSD-1B prompt sweeps for quantitative or qualitative evaluation.
sdxl-controlnet -- --control canny --prompts prompts.txt --output-dir outputs/controlnet_canny
Generate SDXL ControlNet T-Stitch prompt sweeps.
ldm-sample
Run the LDM T-Stitch sampling example.
ldm-sample-all
Run the LDM all-ratios sampling example.
ldm-train
Print a commented LDM training template.
ldm-fid
Run distributed LDM T-Stitch sample generation for FID evaluation.
EOF
}
require_passthrough_args() {
if [[ $# -eq 0 ]]; then
echo "This command needs extra arguments after --." >&2
exit 1
fi
}
cmd="${1:-help}"
if [[ $# -gt 0 ]]; then
shift
fi
case "$cmd" in
help|-h|--help)
usage
;;
install-basic)
cd "$ROOT_DIR"
pip install -r requirements.txt
;;
gradio)
cd "$ROOT_DIR"
python sd/gradio_demo.py
;;
sd-demo)
cd "$ROOT_DIR"
python sd/sd_demo.py
;;
sdxl-demo)
cd "$ROOT_DIR"
python sd/sdxl_demo.py
;;
sdxl-canny)
cd "$ROOT_DIR"
if [[ "${1:-}" == "--" ]]; then
shift
fi
python sd/sdxl_canny.py "$@"
;;
sdxl-depth)
cd "$ROOT_DIR"
if [[ "${1:-}" == "--" ]]; then
shift
fi
python sd/sdxl_depth.py "$@"
;;
sdxl-pose)
cd "$ROOT_DIR"
python sd/sdxl_pose.py
;;
sdxl-lcm)
cd "$ROOT_DIR"
python sd/sdxl_lcm_lora.py
;;
train-sdxl)
cd "$ROOT_DIR"
if [[ "${1:-}" == "--" ]]; then
shift
fi
require_passthrough_args "$@"
accelerate launch sd/train_sdxl_tstitch.py "$@"
;;
dit-sample)
cd "$ROOT_DIR/dit"
python sample_t_stitch.py --solver ddim --num-sampling-steps 100 --seed 4 --ratio 0.5
;;
dit-sample-all)
cd "$ROOT_DIR/dit"
python sample_t_stitch.py --solver ddim --num-sampling-steps 100 --seed 4 --all_tradeoffs
;;
dit-train)
cd "$ROOT_DIR/dit"
if [[ "${1:-}" == "--" ]]; then
shift
fi
require_passthrough_args "$@"
torchrun --master_port=29501 --nnodes=1 --nproc_per_node=1 train_t_stitch.py "$@"
;;
dit-fid)
cd "$ROOT_DIR/dit"
if [[ "${1:-}" == "--" ]]; then
shift
fi
torchrun --nnodes=1 --nproc_per_node=8 sample_ddp_t_stitch.py --num-fid-samples 5000 --solver ddim --num-sampling-steps 100 "$@"
;;
dit-fid-xl-b)
cd "$ROOT_DIR/dit"
torchrun --nnodes=1 --nproc_per_node=8 sample_ddp_t_stitch.py --num-fid-samples 5000 --solver ddim --num-sampling-steps 100 --small-model DiT-B/2 --large-model DiT-XL/2
;;
dit-fid-b-s)
cd "$ROOT_DIR/dit"
torchrun --nnodes=1 --nproc_per_node=8 sample_ddp_t_stitch.py --num-fid-samples 5000 --solver ddim --num-sampling-steps 100 --small-model DiT-S/2 --large-model DiT-B/2
;;
dit-fid-three)
cd "$ROOT_DIR/dit"
if [[ "${1:-}" == "--" ]]; then
shift
fi
torchrun --nnodes=1 --nproc_per_node=8 sample_ddp_t_stitch.py --three_combo --num-fid-samples 5000 --solver ddim --num-sampling-steps 100 "$@"
;;
dit-fid-dpm)
cd "$ROOT_DIR/dit"
if [[ "${1:-}" == "--" ]]; then
shift
fi
torchrun --nnodes=1 --nproc_per_node=8 sample_ddp_t_stitch.py --num-fid-samples 5000 --solver dpm-solver++ --num-sampling-steps 50 "$@"
;;
sd-coco-generate)
cd "$ROOT_DIR"
if [[ "${1:-}" == "--" ]]; then
shift
fi
require_passthrough_args "$@"
python sd/generate_tstitch_prompts.py --pipeline sd --height 256 --width 256 --steps 50 --guidance-scale 7.5 "$@"
;;
sd-pack)
cd "$ROOT_DIR"
if [[ "${1:-}" == "--" ]]; then
shift
fi
require_passthrough_args "$@"
python sd/images_to_npz.py "$@"
;;
clip-score)
cd "$ROOT_DIR"
if [[ "${1:-}" == "--" ]]; then
shift
fi
require_passthrough_args "$@"
python sd/clip_score.py "$@"
;;
sdxl-prompts)
cd "$ROOT_DIR"
if [[ "${1:-}" == "--" ]]; then
shift
fi
require_passthrough_args "$@"
python sd/generate_tstitch_prompts.py --pipeline sdxl "$@"
;;
sdxl-controlnet)
cd "$ROOT_DIR"
if [[ "${1:-}" == "--" ]]; then
shift
fi
require_passthrough_args "$@"
python sd/generate_tstitch_controlnet.py "$@"
;;
ldm-sample)
cd "$ROOT_DIR/ldm"
python scripts/sample_imagenet_32_t_stitch.py --ratio 0.5 --sampling-steps 100 --cfg-scale 3.0
;;
ldm-sample-all)
cd "$ROOT_DIR/ldm"
python scripts/sample_imagenet_32_t_stitch.py --all_ratios --sampling-steps 100 --cfg-scale 3.0
;;
ldm-train)
cat <<'EOF'
# LDM T-Stitch training template.
# Run this from the repo root or adapt the paths first.
cd /Users/ouzhang/Desktop/nips/T-Stitch/ldm
python main.py \
--base configs/latent-diffusion/cin-ldm-vq-f8-t-stitch.yaml \
-t True \
--gpus 0, \
model.params.small_ratio=0.3 \
model.params.ratio_schedule=fixed \
model.params.distill_weight=0.0
EOF
;;
ldm-fid)
cd "$ROOT_DIR/ldm"
python -m torch.distributed.launch --nproc_per_node=8 --master_port 1236 --use_env scripts/sample_imagenet_ddp_t_stitch.py --num-fid-samples 5000 --num-sampling-steps 100 --cfg-scale 3.0 --ratio 0.5
;;
*)
echo "Unknown command: $cmd" >&2
echo >&2
usage
exit 1
;;
esac