Download code/train_twin_diff.sh from fhyfhy/Implicit-Reasoning-checkpoints: direct link, hf CLI and curl.
- Browser
- Download file 4.54 kB
-
https://huggingface.co/fhyfhy/Implicit-Reasoning-checkpoints/resolve/main/code/train_twin_diff.sh
- Command line
-
hf download hf://fhyfhy/Implicit-Reasoning-checkpoints/code/train_twin_diff.sh
-
curl -L -o train_twin_diff.sh https://huggingface.co/fhyfhy/Implicit-Reasoning-checkpoints/resolve/main/code/train_twin_diff.sh
4.54 kB
| # Train on the twin two-hop dataset with selectable GPU, W&B logging, and scratch option. | |
| # | |
| # Usage: | |
| # ./train_twin.sh \\ | |
| # --gpu 0 \\ | |
| # --data data/twin_twohop.2000.200.20 \\ | |
| # --out outputs/twin_run \\ | |
| # --wandb-project myproj \\ | |
| # --from-scratch | |
| # | |
| # Arguments: | |
| # --gpu GPU id for CUDA_VISIBLE_DEVICES (default: 0) | |
| # --data Path to dataset directory (train.json, valid.json) [required] | |
| # --out Output directory for checkpoints [required] | |
| # --wandb-project Wandb project name (optional; if empty, wandb logging is off) | |
| # --model-name HF model name/path to start from (default: gpt2). Ignored if --from-scratch | |
| # --from-scratch Initialize fresh GPT-2 config instead of loading weights | |
| # --create-special-token Add dataset vocab to tokenizer so each entity/relation is a unique token | |
| # --evaluate-epoch Run test-set evaluation every N epochs (<=0 disables) | |
| # --train-eval-samples Number of train samples for periodic accuracy (default: 256) | |
| # --train-eval-seed Seed for selecting train-eval subset (default: 7) | |
| # --log-eval-samples Number of samples to log to W&B tables (default: 20) | |
| # --log-eval-seed Seed for sampling logged examples (default: 7) | |
| # --loss-compute-method Loss on full sequence or only answer tokens (full|answer) | |
| # --block-dropout-p Probability to drop each block during training | |
| # --block-dropout-block-size Number of layers per block | |
| # --block-dropout-seed Seed for block dropout | |
| # --epochs Training epochs (default: 3) | |
| # --batch-size Per-device batch size (default: 16) | |
| # --max-length Max sequence length (default: 64) | |
| # --lr Learning rate (default: 1e-4) | |
| # --warmup-steps Warmup steps (default: 2000) | |
| set -euo pipefail | |
| GPU=7 | |
| DATA_DIR="data/twin_twohop_trueood.50.10.5" | |
| WANDB_PROJECT="gpt2-twin-twohop-trueood-small-dropout" | |
| MODEL_NAME="gpt2" | |
| FROM_SCRATCH=1 | |
| CREATE_SPECIAL=1 | |
| EVALUATE_EPOCH=100 | |
| TRAIN_EVAL_SAMPLES=256 | |
| TRAIN_EVAL_SEED=7 | |
| LOG_EVAL_SAMPLES=256 | |
| LOG_EVAL_SEED=7 | |
| LOSS_COMPUTE_METHOD="full" | |
| BLOCK_DROPOUT_P=0.2 | |
| BLOCK_DROPOUT_BLOCK_SIZE=1 | |
| BLOCK_DROPOUT_SEED=7 | |
| EPOCHS=5000 | |
| BATCH_SIZE=256 | |
| MAX_LENGTH=8 | |
| LR=2e-4 | |
| WARMUP=200 | |
| OUT_DIR="outputs/twin_run-trueood-small-dropout-p${BLOCK_DROPOUT_P}-BS${BLOCK_DROPOUT_BLOCK_SIZE}-lr${LR}-bs${BATCH_SIZE}-epochs${EPOCHS}" | |
| while [[ $# -gt 0 ]]; do | |
| case "$1" in | |
| --gpu) GPU="$2"; shift 2;; | |
| --data) DATA_DIR="$2"; shift 2;; | |
| --out) OUT_DIR="$2"; shift 2;; | |
| --wandb-project) WANDB_PROJECT="$2"; shift 2;; | |
| --model-name) MODEL_NAME="$2"; shift 2;; | |
| --from-scratch) FROM_SCRATCH=1; shift 1;; | |
| --create-special-token) CREATE_SPECIAL=1; shift 1;; | |
| --evaluate-epoch) EVALUATE_EPOCH="$2"; shift 2;; | |
| --train-eval-samples) TRAIN_EVAL_SAMPLES="$2"; shift 2;; | |
| --train-eval-seed) TRAIN_EVAL_SEED="$2"; shift 2;; | |
| --log-eval-samples) LOG_EVAL_SAMPLES="$2"; shift 2;; | |
| --log-eval-seed) LOG_EVAL_SEED="$2"; shift 2;; | |
| --loss-compute-method) LOSS_COMPUTE_METHOD="$2"; shift 2;; | |
| --block-dropout-p) BLOCK_DROPOUT_P="$2"; shift 2;; | |
| --block-dropout-block-size) BLOCK_DROPOUT_BLOCK_SIZE="$2"; shift 2;; | |
| --block-dropout-seed) BLOCK_DROPOUT_SEED="$2"; shift 2;; | |
| --epochs) EPOCHS="$2"; shift 2;; | |
| --batch-size) BATCH_SIZE="$2"; shift 2;; | |
| --max-length) MAX_LENGTH="$2"; shift 2;; | |
| --lr) LR="$2"; shift 2;; | |
| --warmup-steps) WARMUP="$2"; shift 2;; | |
| *) echo "Unknown arg: $1" >&2; exit 1;; | |
| esac | |
| done | |
| if [[ -z "$DATA_DIR" || -z "$OUT_DIR" ]]; then | |
| echo "Required: --data <dir> and --out <dir>" >&2 | |
| exit 1 | |
| fi | |
| export CUDA_VISIBLE_DEVICES="$GPU" | |
| CMD=(python3 train_twin.py | |
| --data-dir "$DATA_DIR" | |
| --output-dir "$OUT_DIR" | |
| --model-name "$MODEL_NAME" | |
| --epochs "$EPOCHS" | |
| --batch-size "$BATCH_SIZE" | |
| --max-length "$MAX_LENGTH" | |
| --lr "$LR" | |
| --warmup-steps "$WARMUP" | |
| --evaluate-epoch "$EVALUATE_EPOCH" | |
| --train-eval-samples "$TRAIN_EVAL_SAMPLES" | |
| --train-eval-seed "$TRAIN_EVAL_SEED" | |
| --log-eval-samples "$LOG_EVAL_SAMPLES" | |
| --log-eval-seed "$LOG_EVAL_SEED" | |
| --loss-compute-method "$LOSS_COMPUTE_METHOD" | |
| --block-dropout-p "$BLOCK_DROPOUT_P" | |
| --block-dropout-block-size "$BLOCK_DROPOUT_BLOCK_SIZE" | |
| --block-dropout-seed "$BLOCK_DROPOUT_SEED" | |
| ) | |
| if [[ "$FROM_SCRATCH" -eq 1 ]]; then | |
| CMD+=(--from-scratch) | |
| fi | |
| if [[ "$CREATE_SPECIAL" -eq 1 ]]; then | |
| CMD+=(--create-special-token) | |
| fi | |
| if [[ -n "$WANDB_PROJECT" ]]; then | |
| CMD+=(--wandb-project "$WANDB_PROJECT") | |
| fi | |
| echo "Running: ${CMD[*]}" | |
| "${CMD[@]}" | |