File size: 2,978 Bytes
2cf4a54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
set -uo pipefail

if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
  cat <<'USAGE'
Usage: bash scripts/run_nf_reference_score_step_sweep.sh [STEP_SIZE ...]

Default step sizes: 0.001 0.002 0.005
Every group edits the same four images (IDs 0, 1, 2, 3 in 0_random_140),
using seed 999, four fixed noise samples, and 50 updates.

Environment overrides:
  NF_REF_OUTPUT_ROOT   New output root (default: result/nf_reference_score_step_sweep)
  NF_REF_NUM_STEPS     Updates per image (default: 50)
  CUDA_VISIBLE_DEVICES GPU selection (default: 0)

Example:
  NF_REF_NUM_STEPS=200 NF_REF_OUTPUT_ROOT=result/nf_reference_score_step_sweep_k200 \
    bash scripts/run_nf_reference_score_step_sweep.sh 0.001 0.002 0.005 0.01
USAGE
  exit 0
fi

step_sizes=("$@")
if (( ${#step_sizes[@]} == 0 )); then
  step_sizes=(0.001 0.002 0.005)
fi

cd "$(dirname "$0")/.."
experiment_root="${NF_REF_OUTPUT_ROOT:-result/nf_reference_score_step_sweep}"
num_steps="${NF_REF_NUM_STEPS:-50}"
if [[ -e "$experiment_root" ]]; then
  printf 'Output root already exists; choose a new NF_REF_OUTPUT_ROOT: %s\n' "$experiment_root" >&2
  exit 1
fi

source /mnt/bn/jiangzhongtao/miniconda3/etc/profile.d/conda.sh
conda activate pvd

python - "$num_steps" "${step_sizes[@]}" <<'PY'
import math
import sys

try:
    if int(sys.argv[1]) < 1:
        raise ValueError('NF_REF_NUM_STEPS must be a positive integer')
    values = [float(value) for value in sys.argv[2:]]
    if any(not math.isfinite(value) or value <= 0 for value in values):
        raise ValueError('Step sizes must be finite and positive')
    if len(set(values)) != len(values):
        raise ValueError('Step sizes must be distinct')
except ValueError as error:
    sys.exit(str(error))
PY

export HF_HUB_CACHE="$PWD/ckpts/hf_cache"
export HF_HUB_OFFLINE=1
export TRANSFORMERS_OFFLINE=1
export CUDA_VISIBLE_DEVICES="${CUDA_VISIBLE_DEVICES:-0}"

mkdir -p "$experiment_root"
failed_steps=()
for step_size in "${step_sizes[@]}"; do
  group="step_${step_size}"
  printf '\nRunning step_size=%s, num_steps=%s, images=4\n' "$step_size" "$num_steps"
  if python -u scripts/nf_reference_score_editing.py \
    --category 0_random_140 \
    --image-id 0 --image-id 1 --image-id 2 --image-id 3 \
    --max-samples 4 \
    --seed 999 --vae-latent mean \
    --num-noise-samples 4 --noise-batch-size 1 \
    --num-steps "$num_steps" --step-size "$step_size" \
    --output-dir "$experiment_root/$group" \
    2>&1 | tee "$experiment_root/$group.log"; then
    printf 'Completed step_size=%s\n' "$step_size"
  else
    failed_steps+=("$step_size")
    printf 'Failed step_size=%s; see %s/%s.log\n' "$step_size" "$experiment_root" "$group" >&2
  fi
done

printf '\nSweep finished; output=%s\n' "$experiment_root"
sweep_status=0
if (( ${#failed_steps[@]} > 0 )); then
  printf 'Failed step sizes: %s\n' "${failed_steps[*]}" >&2
  sweep_status=1
fi

bash /mnt/bn/jiangzhongtao/lingmin/ml-starflow/scripts/zhanka.sh
exit "$sweep_status"