| #!/usr/bin/env bash |
| set -euo pipefail |
|
|
| ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| ENV_DIR="${PFT_TRAIN_ENV_DIR:-/tmp/pft-venv-node-full}" |
| PYTHON_BIN="${PYTHON_BIN:-/home/dyvm6xra/dyvm6xrauser11/miniforge3/bin/python}" |
| PYTHON="${ENV_DIR}/bin/python" |
| PIP="${ENV_DIR}/bin/pip" |
|
|
| MODE="${1:-dummy}" |
| shift || true |
|
|
| EXTRA_ARGS=("$@") |
|
|
| usage() { |
| cat <<'EOF' |
| Usage: |
| scripts/run_train_official.sh [dummy|imnet-pft-b|imnet-pft-xl] [extra hydra overrides...] |
|
|
| Modes: |
| dummy |
| Official Patch Forcing B training stack on dummy256 data. |
| Good for verifying the training pipeline on a single GPU. |
|
|
| imnet-pft-b |
| Full official ImageNet-256 Patch Forcing B training command. |
| Requires configs/data/imagenet256.yaml to be filled in. |
|
|
| imnet-pft-xl |
| Full official ImageNet-256 Patch Forcing XL training command. |
| Requires configs/data/imagenet256.yaml to be filled in. |
|
|
| Examples: |
| scripts/run_train_official.sh dummy |
| scripts/run_train_official.sh dummy train_params.max_steps=100 data.params.batch_size=4 |
| scripts/run_train_official.sh imnet-pft-b |
|
|
| Recommended flow: |
| 1. On the login node, request a GPU shell: |
| /home/dyvm6xra/dyvm6xrauser11/workspace/cz/debug_apply.sh 1 patch-forcing --debug |
| 2. On the allocated compute node, run this script. |
| EOF |
| } |
|
|
| if [[ "${MODE}" == "-h" || "${MODE}" == "--help" ]]; then |
| usage |
| exit 0 |
| fi |
|
|
| require_gpu() { |
| if ! command -v nvidia-smi >/dev/null 2>&1; then |
| echo "nvidia-smi not found. Run this script on a GPU compute node." |
| exit 1 |
| fi |
| nvidia-smi >/dev/null |
| } |
|
|
| ensure_env() { |
| if [[ ! -x "${PYTHON}" ]]; then |
| rm -rf "${ENV_DIR}" |
| "${PYTHON_BIN}" -m venv "${ENV_DIR}" |
| fi |
|
|
| if ! "${PYTHON}" - <<'PY' >/dev/null 2>&1 |
| import accelerate, cv2, diffusers, hydra, jutils, lightning, matplotlib, pandas, tensorboard |
| import timm, torch, torch_fidelity, torchvision, wandb, webdataset |
| PY |
| then |
| env HTTPS_PROXY= HTTP_PROXY= ALL_PROXY= https_proxy= http_proxy= all_proxy= \ |
| "${PIP}" install torch==2.8.0+cu128 torchvision==0.23.0+cu128 --index-url https://download.pytorch.org/whl/cu128 |
|
|
| env HTTPS_PROXY= HTTP_PROXY= ALL_PROXY= https_proxy= http_proxy= all_proxy= \ |
| "${PIP}" install \ |
| hydra-core lightning accelerate tensorboard webdataset opencv-python h5py pandas \ |
| wandb torch-fidelity scipy requests packaging omegaconf PyYAML tqdm einops jaxtyping \ |
| termcolor matplotlib ipython |
|
|
| env HTTPS_PROXY= HTTP_PROXY= ALL_PROXY= https_proxy= http_proxy= all_proxy= \ |
| "${PIP}" install --no-deps timm diffusers git+https://github.com/joh-schb/jutils.git |
| fi |
| } |
|
|
| prepare_sd_ae() { |
| mkdir -p "${ROOT_DIR}/checkpoints" |
|
|
| if [[ ! -f "${ROOT_DIR}/checkpoints/sd_ae_full.ckpt" ]]; then |
| env HTTPS_PROXY= HTTP_PROXY= ALL_PROXY= https_proxy= http_proxy= all_proxy= \ |
| curl -L --retry 5 -C - \ |
| -o "${ROOT_DIR}/checkpoints/sd_ae_full.ckpt" \ |
| https://huggingface.co/stabilityai/sd-vae-ft-ema-original/resolve/main/vae-ft-ema-560000-ema-pruned.ckpt |
| fi |
|
|
| if [[ ! -f "${ROOT_DIR}/checkpoints/sd_ae.ckpt" ]]; then |
| "${PYTHON}" - <<'PY' |
| import torch |
| src = "checkpoints/sd_ae_full.ckpt" |
| dst = "checkpoints/sd_ae.ckpt" |
| ckpt = torch.load(src, map_location="cpu", weights_only=False) |
| state_dict = ckpt["state_dict"] if "state_dict" in ckpt else ckpt |
| state_dict = {k: v for k, v in state_dict.items() if not k.startswith("model_ema.")} |
| torch.save(state_dict, dst) |
| print(f"Saved converted SD autoencoder weights to {dst}") |
| PY |
| fi |
| } |
|
|
| check_imagenet_cfg() { |
| if grep -q "tar_base: ..." "${ROOT_DIR}/configs/data/imagenet256.yaml"; then |
| echo "configs/data/imagenet256.yaml is still unconfigured." |
| echo "Fill tar_base and shard patterns before running ${MODE}." |
| exit 1 |
| fi |
| } |
|
|
| build_train_cmd() { |
| case "${MODE}" in |
| dummy) |
| cat <<'EOF' |
| train.py experiment=imnet-pft-b data=dummy256 autoencoder=sd_ae model.params.compile=false train_params.max_steps=100 train_params.val_check_interval=1000 train_params.limit_val_batches=0 data.params.batch_size=4 data.params.num_workers=0 name=debug/train-official |
| EOF |
| ;; |
| imnet-pft-b) |
| check_imagenet_cfg |
| cat <<'EOF' |
| train.py experiment=imnet-pft-b |
| EOF |
| ;; |
| imnet-pft-xl) |
| check_imagenet_cfg |
| cat <<'EOF' |
| train.py experiment=imnet-pft-xl |
| EOF |
| ;; |
| *) |
| echo "Unknown mode: ${MODE}" |
| usage |
| exit 1 |
| ;; |
| esac |
| } |
|
|
| require_gpu |
| cd "${ROOT_DIR}" |
| ensure_env |
| prepare_sd_ae |
|
|
| TRAIN_CMD="$(build_train_cmd)" |
|
|
| echo "Using Python: ${PYTHON}" |
| echo "Mode : ${MODE}" |
| echo "Train cmd : ${TRAIN_CMD} ${EXTRA_ARGS[*]:-}" |
|
|
| env HTTPS_PROXY= HTTP_PROXY= ALL_PROXY= https_proxy= http_proxy= all_proxy= \ |
| LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}" \ |
| "${PYTHON}" ${TRAIN_CMD} "${EXTRA_ARGS[@]}" |
|
|