update
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
- gainlora_OT_vMF/SETUP.md +0 -143
- gainlora_OT_vMF/requirements.txt +0 -3
- gainlora_OT_vMF/run_ot_sign_order1_t5large.sh +0 -175
- gainlora_OT_vMF/run_ot_sign_order2_t5large.sh +0 -168
- gainlora_OT_vMF/run_ot_sign_order3_t5large.sh +0 -169
- gainlora_OT_vMF/run_ot_sign_order4_t5large.sh +0 -169
- gainlora_OT_vMF/run_ot_sign_smoke_t5.sh +0 -70
- gainlora_OT_vMF/run_ot_sign_t4.sh +0 -488
- gainlora_OT_vMF/src/__pycache__/cl_collator.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_dataset.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_trainer_gainlora_inflora.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_trainer_gainlora_inflora_llama.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_trainer_gainlora_olora.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_trainer_gainlora_olora_llama.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_trainer_inflora.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_trainer_inflora_llama.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_trainer_olora.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/cl_trainer_olora_llama.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/compat_transformers.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/llama_gainlora_inflora.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/llama_inflora.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/ot_sign_utils.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/ot_sign_utils.cpython-313.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/run_llama.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/run_logger.cpython-313.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/run_t5.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/t5_gainlora_inflora.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/__pycache__/t5_inflora.cpython-312.pyc +0 -3
- gainlora_OT_vMF/src/compat_transformers.py +0 -206
- gainlora_OT_vMF/src/compute_ap_ft.py +0 -242
- gainlora_OT_vMF/src/ot_sign_utils.py +0 -289
- gainlora_OT_vMF/src/preflight_check.py +0 -199
- gainlora_OT_vMF/src/run_logger.py +0 -229
- gainlora_OT_vMF/src/test_ot_sign.py +0 -54
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/agnews/dev.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/agnews/labels.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/agnews/test.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/agnews/train.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/amazon/dev.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/amazon/labels.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/amazon/test.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/amazon/train.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/boolq/dev.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/boolq/labels.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/boolq/test.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/boolq/train.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/cb/dev.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/cb/labels.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/cb/test.json +0 -0
- {gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/cb/train.json +0 -0
gainlora_OT_vMF/SETUP.md
DELETED
|
@@ -1,143 +0,0 @@
|
|
| 1 |
-
# GainLoRA + OT-SIGN Setup Guide
|
| 2 |
-
|
| 3 |
-
## Quick Start
|
| 4 |
-
|
| 5 |
-
### Option 1: Using conda + pip (Recommended for GPU)
|
| 6 |
-
|
| 7 |
-
```bash
|
| 8 |
-
# 1. Create conda environment with CUDA support
|
| 9 |
-
conda create -n gainlora \
|
| 10 |
-
python=3.10 \
|
| 11 |
-
pytorch::pytorch \
|
| 12 |
-
pytorch::pytorch-cuda=12.1 \
|
| 13 |
-
pytorch::torchvision \
|
| 14 |
-
pytorch::torchaudio \
|
| 15 |
-
-c pytorch -c nvidia
|
| 16 |
-
|
| 17 |
-
# 2. Activate environment
|
| 18 |
-
conda activate gainlora
|
| 19 |
-
|
| 20 |
-
# 3. Install pip dependencies
|
| 21 |
-
cd gainlora
|
| 22 |
-
pip install -r requirements.txt
|
| 23 |
-
```
|
| 24 |
-
|
| 25 |
-
### Option 2: Using only pip (CPU or if CUDA already setup)
|
| 26 |
-
|
| 27 |
-
```bash
|
| 28 |
-
# Install all pip dependencies
|
| 29 |
-
pip install -r requirements.txt
|
| 30 |
-
```
|
| 31 |
-
|
| 32 |
-
### Option 3: From conda environment (existing setup)
|
| 33 |
-
|
| 34 |
-
```bash
|
| 35 |
-
# If you already have an environment, just update pip packages
|
| 36 |
-
conda activate <your_env>
|
| 37 |
-
pip install -r requirements.txt
|
| 38 |
-
```
|
| 39 |
-
|
| 40 |
-
---
|
| 41 |
-
|
| 42 |
-
## Key Dependencies
|
| 43 |
-
|
| 44 |
-
| Package | Purpose | Version |
|
| 45 |
-
|---------|---------|---------|
|
| 46 |
-
| transformers | HuggingFace models (T5, LLaMA, etc.) | 4.30.2 |
|
| 47 |
-
| torch/vision/audio | PyTorch + CUDA support | 2.1.0 |
|
| 48 |
-
| datasets | Dataset loading & processing | 2.14.6 |
|
| 49 |
-
| accelerate | Distributed training | 0.24.1 |
|
| 50 |
-
| deepspeed | ZeRO optimization | 0.11.2 |
|
| 51 |
-
| loralib | LoRA layers | 0.1.2 |
|
| 52 |
-
| cupy-cuda12x | GPU-accelerated arrays (for SVD) | 12.1.0 |
|
| 53 |
-
| safetensors | Fast model serialization | 0.4.4 |
|
| 54 |
-
|
| 55 |
-
---
|
| 56 |
-
|
| 57 |
-
## Troubleshooting
|
| 58 |
-
|
| 59 |
-
### CUDA Version Mismatch
|
| 60 |
-
If you have a different CUDA version:
|
| 61 |
-
```bash
|
| 62 |
-
# Change 12.1 to your CUDA version (11.8, 11.6, etc.)
|
| 63 |
-
conda create -n gainlora ... pytorch::pytorch-cuda=11.8 ...
|
| 64 |
-
```
|
| 65 |
-
|
| 66 |
-
### CuPy Installation Fails
|
| 67 |
-
CuPy requires CUDA dev toolkit. If it fails:
|
| 68 |
-
```bash
|
| 69 |
-
# Option 1: Install it separately
|
| 70 |
-
conda install -c conda-forge cupy cuda-version=12.1
|
| 71 |
-
|
| 72 |
-
# Option 2: Comment it out in requirements.txt if not using SVD GPM
|
| 73 |
-
```
|
| 74 |
-
|
| 75 |
-
### Out of Memory on 2ΓT4
|
| 76 |
-
Scripts are already optimized (batch_size=8, fp16). If still OOM:
|
| 77 |
-
1. Reduce `per_device_train_batch_size` in bash scripts
|
| 78 |
-
2. Increase `gradient_accumulation_steps`
|
| 79 |
-
|
| 80 |
-
### Kaggle/Colab Environment (Pre-built Wheels)
|
| 81 |
-
|
| 82 |
-
When running on Kaggle or Google Colab, use pre-built wheels to avoid compilation:
|
| 83 |
-
|
| 84 |
-
```bash
|
| 85 |
-
# Clone and install (Colab/Kaggle cell)
|
| 86 |
-
! git clone https://github.com/liangyanshuo/gainlora.git
|
| 87 |
-
! cd gainlora && pip install -r requirements.txt --no-build-isolation
|
| 88 |
-
|
| 89 |
-
# Or with uv proxy (faster) - already recommended in Colab/Kaggle
|
| 90 |
-
! pip install uv
|
| 91 |
-
! uv pip install -r requirements.txt
|
| 92 |
-
```
|
| 93 |
-
|
| 94 |
-
**Note:** `tokenizers>=0.14.1` has pre-built wheels for Python 3.12. If you still get build errors:
|
| 95 |
-
- Add GPU dependencies: `! pip install --upgrade setuptools wheel`
|
| 96 |
-
- Or downgrade Python: Colab uses 3.10-3.12; ensure compatibility
|
| 97 |
-
|
| 98 |
-
---
|
| 99 |
-
|
| 100 |
-
## Running OT-SIGN + GainLoRA
|
| 101 |
-
|
| 102 |
-
```bash
|
| 103 |
-
# Order 1 (SuperNI) - ~10 hours on 2ΓT4
|
| 104 |
-
bash run_ot_sign_order1_t5large.sh 0,1 google/flan-t5-large
|
| 105 |
-
|
| 106 |
-
# Order 2 (SuperNI) - ~10 hours
|
| 107 |
-
bash run_ot_sign_order2_t5large.sh 0,1 google/flan-t5-large
|
| 108 |
-
|
| 109 |
-
# Order 3 (Long) - ~4 hours [run this first to test]
|
| 110 |
-
bash run_ot_sign_order3_t5large.sh 0,1 google/flan-t5-large
|
| 111 |
-
|
| 112 |
-
# Order 4 (Long) - ~4 hours
|
| 113 |
-
bash run_ot_sign_order4_t5large.sh 0,1 google/flan-t5-large
|
| 114 |
-
```
|
| 115 |
-
|
| 116 |
-
Results and logs:
|
| 117 |
-
- Training outputs: `logs_and_outputs/ot_sign_order{1,2,3,4}_t5large/`
|
| 118 |
-
- AP/FT scores: Printed in terminal + `ap_ft_result.json`
|
| 119 |
-
- Compare with baseline: See `results/comparison_results.md`
|
| 120 |
-
|
| 121 |
-
---
|
| 122 |
-
|
| 123 |
-
## Environment Verification
|
| 124 |
-
|
| 125 |
-
```bash
|
| 126 |
-
# Check PyTorch + CUDA
|
| 127 |
-
python -c "import torch; print(f'PyTorch {torch.__version__}, CUDA {torch.cuda.is_available()}')"
|
| 128 |
-
|
| 129 |
-
# Check transformers
|
| 130 |
-
python -c "import transformers; print(f'Transformers {transformers.__version__}')"
|
| 131 |
-
|
| 132 |
-
# Check other deps
|
| 133 |
-
python -c "import cupy; import accelerate; import deepspeed; print('All deps OK')"
|
| 134 |
-
```
|
| 135 |
-
|
| 136 |
-
---
|
| 137 |
-
|
| 138 |
-
## Notes
|
| 139 |
-
|
| 140 |
-
- `requirements.yaml` = Full conda environment spec (includes system libs)
|
| 141 |
-
- `requirements.txt` = Python pip packages only (easier to share and modify)
|
| 142 |
-
- Both methods should give identical Python environment
|
| 143 |
-
- CUDA/cuDNN installation separate (via conda in setup)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/requirements.txt
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:22ba1705f034261bc2483bcabe3bbf5935a041e6972f2d17e487c54fb56b92c5
|
| 3 |
-
size 1136
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/run_ot_sign_order1_t5large.sh
DELETED
|
@@ -1,175 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
###############################################################################
|
| 3 |
-
# OT-SIGN + GainLoRA (T5-Large) β Order 1 (SuperNI)
|
| 4 |
-
# ===================================================
|
| 5 |
-
# Task order: samsum β sst2 β xsum β ... β emotion (15 tasks)
|
| 6 |
-
# Benchmark: SuperNI (RougeL metric)
|
| 7 |
-
# Hardware: 2Γ T4 16GB | Estimated time: ~9-10h
|
| 8 |
-
# Run: bash run_ot_sign_order1_t5large.sh [GPU_IDS] [MODEL_PATH]
|
| 9 |
-
###############################################################################
|
| 10 |
-
|
| 11 |
-
set -e # exit on first error
|
| 12 |
-
|
| 13 |
-
export CUDA_DEVICE_ORDER="PCI_BUS_ID"
|
| 14 |
-
GPU_IDS="${1:-0,1}"
|
| 15 |
-
MODEL_PATH="${2:-google/flan-t5-large}"
|
| 16 |
-
|
| 17 |
-
# ββ Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
-
RUN_NAME="ot_sign_order1_t5large"
|
| 19 |
-
OUTPUT_BASE="logs_and_outputs/${RUN_NAME}/outputs"
|
| 20 |
-
CONFIG_PREFIX="configs/gen_script_superni_order1_t5_configs"
|
| 21 |
-
GEN_DATA_DIR="generated_data/lora_gen_superni_t5"
|
| 22 |
-
METRIC_TYPE="rougeL" # RougeL for SuperNI
|
| 23 |
-
KL_RATIO=0.5
|
| 24 |
-
EPOCHS=50
|
| 25 |
-
|
| 26 |
-
# T4 settings
|
| 27 |
-
BATCH_SIZE=8
|
| 28 |
-
EVAL_BATCH=4
|
| 29 |
-
GRAD_ACCUM=4
|
| 30 |
-
LR=0.0003
|
| 31 |
-
|
| 32 |
-
# OT-SIGN
|
| 33 |
-
OT_EPSILON=0.05
|
| 34 |
-
OT_N_ITER=10
|
| 35 |
-
DEFAULT_KAPPA=10.0
|
| 36 |
-
LAMBDA_DRIFT=0.01
|
| 37 |
-
LAMBDA_INV=0.001
|
| 38 |
-
THRESHOLD=2.3
|
| 39 |
-
|
| 40 |
-
# ββ Task sequence ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 41 |
-
TASKS=(
|
| 42 |
-
"task1572_samsum_summary"
|
| 43 |
-
"task363_sst2_polarity_classification"
|
| 44 |
-
"task1290_xsum_summarization"
|
| 45 |
-
"task181_outcome_extraction"
|
| 46 |
-
"task002_quoref_answer_generation"
|
| 47 |
-
"task1510_evalution_relation_extraction"
|
| 48 |
-
"task639_multi_woz_user_utterance_generation"
|
| 49 |
-
"task1729_personachat_generate_next"
|
| 50 |
-
"task073_commonsenseqa_answer_generation"
|
| 51 |
-
"task1590_diplomacy_text_generation"
|
| 52 |
-
"task748_glucose_reverse_cause_event_detection"
|
| 53 |
-
"task511_reddit_tifu_long_text_summarization"
|
| 54 |
-
"task591_sciq_answer_generation"
|
| 55 |
-
"task1687_sentiment140_classification"
|
| 56 |
-
"task875_emotion_classification"
|
| 57 |
-
)
|
| 58 |
-
TASK_ORDER=$(IFS=,; echo "${TASKS[*]}")
|
| 59 |
-
T=${#TASKS[@]}
|
| 60 |
-
|
| 61 |
-
mkdir -p "${OUTPUT_BASE}"
|
| 62 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 63 |
-
echo " OT-SIGN+GainLoRA | Order 1 | T5-Large"
|
| 64 |
-
echo " GPUs: ${GPU_IDS} | Tasks: ${T} | Epochs: ${EPOCHS}"
|
| 65 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 66 |
-
|
| 67 |
-
# ββ Training loop ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 68 |
-
PREV_LORA_PATHS=""
|
| 69 |
-
|
| 70 |
-
for i in "${!TASKS[@]}"; do
|
| 71 |
-
TASK="${TASKS[$i]}"
|
| 72 |
-
TASKNUM=$((i + 1))
|
| 73 |
-
OUTDIR="${OUTPUT_BASE}/${TASKNUM}-${TASK}"
|
| 74 |
-
|
| 75 |
-
# Metric key (task 1 has no "for_task" suffix)
|
| 76 |
-
if [[ $i -eq 0 ]]; then
|
| 77 |
-
METRIC_KEY="eval_${METRIC_TYPE}"
|
| 78 |
-
else
|
| 79 |
-
METRIC_KEY="eval_${METRIC_TYPE}_for_${TASK}"
|
| 80 |
-
fi
|
| 81 |
-
|
| 82 |
-
echo ""
|
| 83 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 84 |
-
echo " Task ${TASKNUM}/${T}: ${TASK}"
|
| 85 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 86 |
-
|
| 87 |
-
# Build OT-SIGN flags
|
| 88 |
-
OT_FLAGS="--use_ot_routing True \
|
| 89 |
-
--ot_epsilon ${OT_EPSILON} \
|
| 90 |
-
--ot_n_iter ${OT_N_ITER} \
|
| 91 |
-
--default_kappa ${DEFAULT_KAPPA} \
|
| 92 |
-
--lambda_drift ${LAMBDA_DRIFT} \
|
| 93 |
-
--lambda_inv ${LAMBDA_INV} \
|
| 94 |
-
--invasion_threshold ${THRESHOLD}"
|
| 95 |
-
|
| 96 |
-
# Build previous-task flags (empty for task 1)
|
| 97 |
-
PREV_FLAGS=""
|
| 98 |
-
if [[ $i -gt 0 ]]; then
|
| 99 |
-
PREV_OUTDIR="${OUTPUT_BASE}/${i}-${TASKS[$((i-1))]}/saved_weights"
|
| 100 |
-
PREV_FLAGS="--load_checkpoint_from ${PREV_OUTDIR}/trans_input.pt \
|
| 101 |
-
--previous_lora_path ${PREV_LORA_PATHS} \
|
| 102 |
-
--previous_prompt_key_path ${PREV_OUTDIR}/prompts_keys_till_now.pt \
|
| 103 |
-
--previous_vmf_signatures_path ${PREV_OUTDIR}/vmf_signatures.pt \
|
| 104 |
-
--add_instruction_replay \
|
| 105 |
-
--gen_data_dir ${GEN_DATA_DIR} \
|
| 106 |
-
--kl_ratio ${KL_RATIO} \
|
| 107 |
-
--data_replay_freq -1 \
|
| 108 |
-
--replay_after_n_epoch 0"
|
| 109 |
-
fi
|
| 110 |
-
|
| 111 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 112 |
-
--do_train \
|
| 113 |
-
--do_predict \
|
| 114 |
-
--predict_with_generate \
|
| 115 |
-
--model_name_or_path "${MODEL_PATH}" \
|
| 116 |
-
--data_dir CL_Benchmark \
|
| 117 |
-
--task_order "${TASK_ORDER}" \
|
| 118 |
-
--task_config_dir "${CONFIG_PREFIX}/${TASK}" \
|
| 119 |
-
--output_dir "${OUTDIR}" \
|
| 120 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 121 |
-
--per_device_eval_batch_size ${EVAL_BATCH} \
|
| 122 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 123 |
-
--learning_rate ${LR} \
|
| 124 |
-
--num_train_epochs ${EPOCHS} \
|
| 125 |
-
--run_name "${RUN_NAME}" \
|
| 126 |
-
--max_source_length 512 \
|
| 127 |
-
--max_target_length 50 \
|
| 128 |
-
--generation_max_length 50 \
|
| 129 |
-
--add_task_name False \
|
| 130 |
-
--add_dataset_name False \
|
| 131 |
-
--lr_scheduler_type constant \
|
| 132 |
-
--warmup_steps 0 \
|
| 133 |
-
--logging_strategy steps \
|
| 134 |
-
--logging_steps 10 \
|
| 135 |
-
--eval_strategy steps \
|
| 136 |
-
--save_strategy steps \
|
| 137 |
-
--save_total_limit 1 \
|
| 138 |
-
--load_best_model_at_end \
|
| 139 |
-
--metric_for_best_model "${METRIC_KEY}" \
|
| 140 |
-
--lora_r 4 \
|
| 141 |
-
--lora_alpha 32 \
|
| 142 |
-
--lora_dropout 0.0 \
|
| 143 |
-
--attn_temperature 1 \
|
| 144 |
-
--mlp_hidden_dim 100 \
|
| 145 |
-
--model_name gainlora_inflora \
|
| 146 |
-
--threshold 0.995 \
|
| 147 |
-
--transthreshold 0.995 \
|
| 148 |
-
--fp16 \
|
| 149 |
-
${OT_FLAGS} \
|
| 150 |
-
${PREV_FLAGS}
|
| 151 |
-
|
| 152 |
-
# Accumulate previous lora paths
|
| 153 |
-
if [[ -z "${PREV_LORA_PATHS}" ]]; then
|
| 154 |
-
PREV_LORA_PATHS="${OUTDIR}/saved_weights"
|
| 155 |
-
else
|
| 156 |
-
PREV_LORA_PATHS="${PREV_LORA_PATHS},${OUTDIR}/saved_weights"
|
| 157 |
-
fi
|
| 158 |
-
|
| 159 |
-
echo " [DONE] Task ${TASKNUM}/${T}: ${TASK}"
|
| 160 |
-
done
|
| 161 |
-
|
| 162 |
-
# ββ Final AP/FT ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 163 |
-
echo ""
|
| 164 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 165 |
-
echo " Computing AP / FT ..."
|
| 166 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 167 |
-
python src/compute_ap_ft.py \
|
| 168 |
-
--output_base "${OUTPUT_BASE}" \
|
| 169 |
-
--task_order "${TASK_ORDER}" \
|
| 170 |
-
--method_name "${RUN_NAME}" \
|
| 171 |
-
--save
|
| 172 |
-
|
| 173 |
-
echo ""
|
| 174 |
-
echo "β All done. Results in: logs_and_outputs/${RUN_NAME}/"
|
| 175 |
-
echo " Compare with: results/comparison_results.md"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/run_ot_sign_order2_t5large.sh
DELETED
|
@@ -1,168 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
###############################################################################
|
| 3 |
-
# OT-SIGN + GainLoRA (T5-Large) β Order 2 (SuperNI)
|
| 4 |
-
# ===================================================
|
| 5 |
-
# Task order: glucose β commonsenseqa β diplomacy β ... β emotion (15 tasks)
|
| 6 |
-
# Benchmark: SuperNI (RougeL metric)
|
| 7 |
-
# Hardware: 2Γ T4 16GB | Estimated time: ~9-10h
|
| 8 |
-
# Run: bash run_ot_sign_order2_t5large.sh [GPU_IDS] [MODEL_PATH]
|
| 9 |
-
###############################################################################
|
| 10 |
-
|
| 11 |
-
set -e
|
| 12 |
-
|
| 13 |
-
export CUDA_DEVICE_ORDER="PCI_BUS_ID"
|
| 14 |
-
GPU_IDS="${1:-0,1}"
|
| 15 |
-
MODEL_PATH="${2:-google/flan-t5-large}"
|
| 16 |
-
|
| 17 |
-
# ββ Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
-
RUN_NAME="ot_sign_order2_t5large"
|
| 19 |
-
OUTPUT_BASE="logs_and_outputs/${RUN_NAME}/outputs"
|
| 20 |
-
CONFIG_PREFIX="configs/gen_script_superni_order2_t5_configs"
|
| 21 |
-
GEN_DATA_DIR="generated_data/lora_gen_superni_t5"
|
| 22 |
-
METRIC_TYPE="rougeL"
|
| 23 |
-
KL_RATIO=0.5
|
| 24 |
-
EPOCHS=50
|
| 25 |
-
|
| 26 |
-
BATCH_SIZE=8
|
| 27 |
-
EVAL_BATCH=4
|
| 28 |
-
GRAD_ACCUM=4
|
| 29 |
-
LR=0.0003
|
| 30 |
-
|
| 31 |
-
OT_EPSILON=0.05
|
| 32 |
-
OT_N_ITER=10
|
| 33 |
-
DEFAULT_KAPPA=10.0
|
| 34 |
-
LAMBDA_DRIFT=0.01
|
| 35 |
-
LAMBDA_INV=0.001
|
| 36 |
-
THRESHOLD=2.3
|
| 37 |
-
|
| 38 |
-
# ββ Task sequence ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 39 |
-
TASKS=(
|
| 40 |
-
"task748_glucose_reverse_cause_event_detection"
|
| 41 |
-
"task073_commonsenseqa_answer_generation"
|
| 42 |
-
"task1590_diplomacy_text_generation"
|
| 43 |
-
"task639_multi_woz_user_utterance_generation"
|
| 44 |
-
"task1572_samsum_summary"
|
| 45 |
-
"task1687_sentiment140_classification"
|
| 46 |
-
"task591_sciq_answer_generation"
|
| 47 |
-
"task363_sst2_polarity_classification"
|
| 48 |
-
"task1510_evalution_relation_extraction"
|
| 49 |
-
"task1729_personachat_generate_next"
|
| 50 |
-
"task181_outcome_extraction"
|
| 51 |
-
"task511_reddit_tifu_long_text_summarization"
|
| 52 |
-
"task002_quoref_answer_generation"
|
| 53 |
-
"task1290_xsum_summarization"
|
| 54 |
-
"task875_emotion_classification"
|
| 55 |
-
)
|
| 56 |
-
TASK_ORDER=$(IFS=,; echo "${TASKS[*]}")
|
| 57 |
-
T=${#TASKS[@]}
|
| 58 |
-
|
| 59 |
-
mkdir -p "${OUTPUT_BASE}"
|
| 60 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 61 |
-
echo " OT-SIGN+GainLoRA | Order 2 | T5-Large"
|
| 62 |
-
echo " GPUs: ${GPU_IDS} | Tasks: ${T} | Epochs: ${EPOCHS}"
|
| 63 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 64 |
-
|
| 65 |
-
# ββ Training loop ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 66 |
-
PREV_LORA_PATHS=""
|
| 67 |
-
|
| 68 |
-
for i in "${!TASKS[@]}"; do
|
| 69 |
-
TASK="${TASKS[$i]}"
|
| 70 |
-
TASKNUM=$((i + 1))
|
| 71 |
-
OUTDIR="${OUTPUT_BASE}/${TASKNUM}-${TASK}"
|
| 72 |
-
|
| 73 |
-
if [[ $i -eq 0 ]]; then
|
| 74 |
-
METRIC_KEY="eval_${METRIC_TYPE}"
|
| 75 |
-
else
|
| 76 |
-
METRIC_KEY="eval_${METRIC_TYPE}_for_${TASK}"
|
| 77 |
-
fi
|
| 78 |
-
|
| 79 |
-
echo ""
|
| 80 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 81 |
-
echo " Task ${TASKNUM}/${T}: ${TASK}"
|
| 82 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 83 |
-
|
| 84 |
-
OT_FLAGS="--use_ot_routing True \
|
| 85 |
-
--ot_epsilon ${OT_EPSILON} \
|
| 86 |
-
--ot_n_iter ${OT_N_ITER} \
|
| 87 |
-
--default_kappa ${DEFAULT_KAPPA} \
|
| 88 |
-
--lambda_drift ${LAMBDA_DRIFT} \
|
| 89 |
-
--lambda_inv ${LAMBDA_INV} \
|
| 90 |
-
--invasion_threshold ${THRESHOLD}"
|
| 91 |
-
|
| 92 |
-
PREV_FLAGS=""
|
| 93 |
-
if [[ $i -gt 0 ]]; then
|
| 94 |
-
PREV_OUTDIR="${OUTPUT_BASE}/${i}-${TASKS[$((i-1))]}/saved_weights"
|
| 95 |
-
PREV_FLAGS="--load_checkpoint_from ${PREV_OUTDIR}/trans_input.pt \
|
| 96 |
-
--previous_lora_path ${PREV_LORA_PATHS} \
|
| 97 |
-
--previous_prompt_key_path ${PREV_OUTDIR}/prompts_keys_till_now.pt \
|
| 98 |
-
--previous_vmf_signatures_path ${PREV_OUTDIR}/vmf_signatures.pt \
|
| 99 |
-
--add_instruction_replay \
|
| 100 |
-
--gen_data_dir ${GEN_DATA_DIR} \
|
| 101 |
-
--kl_ratio ${KL_RATIO} \
|
| 102 |
-
--data_replay_freq -1 \
|
| 103 |
-
--replay_after_n_epoch 0"
|
| 104 |
-
fi
|
| 105 |
-
|
| 106 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 107 |
-
--do_train \
|
| 108 |
-
--do_predict \
|
| 109 |
-
--predict_with_generate \
|
| 110 |
-
--model_name_or_path "${MODEL_PATH}" \
|
| 111 |
-
--data_dir CL_Benchmark \
|
| 112 |
-
--task_order "${TASK_ORDER}" \
|
| 113 |
-
--task_config_dir "${CONFIG_PREFIX}/${TASK}" \
|
| 114 |
-
--output_dir "${OUTDIR}" \
|
| 115 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 116 |
-
--per_device_eval_batch_size ${EVAL_BATCH} \
|
| 117 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 118 |
-
--learning_rate ${LR} \
|
| 119 |
-
--num_train_epochs ${EPOCHS} \
|
| 120 |
-
--run_name "${RUN_NAME}" \
|
| 121 |
-
--max_source_length 512 \
|
| 122 |
-
--max_target_length 50 \
|
| 123 |
-
--generation_max_length 50 \
|
| 124 |
-
--add_task_name False \
|
| 125 |
-
--add_dataset_name False \
|
| 126 |
-
--lr_scheduler_type constant \
|
| 127 |
-
--warmup_steps 0 \
|
| 128 |
-
--logging_strategy steps \
|
| 129 |
-
--logging_steps 10 \
|
| 130 |
-
--eval_strategy steps \
|
| 131 |
-
--save_strategy steps \
|
| 132 |
-
--save_total_limit 1 \
|
| 133 |
-
--load_best_model_at_end \
|
| 134 |
-
--metric_for_best_model "${METRIC_KEY}" \
|
| 135 |
-
--lora_r 4 \
|
| 136 |
-
--lora_alpha 32 \
|
| 137 |
-
--lora_dropout 0.0 \
|
| 138 |
-
--attn_temperature 1 \
|
| 139 |
-
--mlp_hidden_dim 100 \
|
| 140 |
-
--model_name gainlora_inflora \
|
| 141 |
-
--threshold 0.995 \
|
| 142 |
-
--transthreshold 0.995 \
|
| 143 |
-
--fp16 \
|
| 144 |
-
${OT_FLAGS} \
|
| 145 |
-
${PREV_FLAGS}
|
| 146 |
-
|
| 147 |
-
if [[ -z "${PREV_LORA_PATHS}" ]]; then
|
| 148 |
-
PREV_LORA_PATHS="${OUTDIR}/saved_weights"
|
| 149 |
-
else
|
| 150 |
-
PREV_LORA_PATHS="${PREV_LORA_PATHS},${OUTDIR}/saved_weights"
|
| 151 |
-
fi
|
| 152 |
-
|
| 153 |
-
echo " [DONE] Task ${TASKNUM}/${T}: ${TASK}"
|
| 154 |
-
done
|
| 155 |
-
|
| 156 |
-
# ββ Final AP/FT ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 157 |
-
echo ""
|
| 158 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 159 |
-
echo " Computing AP / FT ..."
|
| 160 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 161 |
-
python src/compute_ap_ft.py \
|
| 162 |
-
--output_base "${OUTPUT_BASE}" \
|
| 163 |
-
--task_order "${TASK_ORDER}" \
|
| 164 |
-
--method_name "${RUN_NAME}" \
|
| 165 |
-
--save
|
| 166 |
-
|
| 167 |
-
echo ""
|
| 168 |
-
echo "β All done. Results in: logs_and_outputs/${RUN_NAME}/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/run_ot_sign_order3_t5large.sh
DELETED
|
@@ -1,169 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
###############################################################################
|
| 3 |
-
# OT-SIGN + GainLoRA (T5-Large) β Order 3 (Long Benchmark)
|
| 4 |
-
# ==========================================================
|
| 5 |
-
# Task order: yelp β amazon β mnli β ... β wic (15 tasks)
|
| 6 |
-
# Benchmark: Long (Exact Match metric)
|
| 7 |
-
# Hardware: 2Γ T4 16GB | Estimated time: ~3-4h
|
| 8 |
-
# Run: bash run_ot_sign_order3_t5large.sh [GPU_IDS] [MODEL_PATH]
|
| 9 |
-
###############################################################################
|
| 10 |
-
|
| 11 |
-
set -e
|
| 12 |
-
|
| 13 |
-
export CUDA_DEVICE_ORDER="PCI_BUS_ID"
|
| 14 |
-
GPU_IDS="${1:-0,1}"
|
| 15 |
-
MODEL_PATH="${2:-google/flan-t5-large}"
|
| 16 |
-
|
| 17 |
-
# ββ Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
-
RUN_NAME="ot_sign_order3_t5large"
|
| 19 |
-
OUTPUT_BASE="logs_and_outputs/${RUN_NAME}/outputs"
|
| 20 |
-
CONFIG_PREFIX="configs/gen_script_long_order3_t5_configs"
|
| 21 |
-
GEN_DATA_DIR="generated_data/lora_gen_long_t5"
|
| 22 |
-
METRIC_TYPE="exact_match" # Exact Match for Long benchmark
|
| 23 |
-
KL_RATIO=0.1
|
| 24 |
-
EPOCHS=10 # Long benchmark uses fewer epochs
|
| 25 |
-
|
| 26 |
-
BATCH_SIZE=4
|
| 27 |
-
EVAL_BATCH=16 # Long benchmark uses larger eval batch
|
| 28 |
-
GRAD_ACCUM=8
|
| 29 |
-
LR=0.0003
|
| 30 |
-
|
| 31 |
-
OT_EPSILON=0.05
|
| 32 |
-
OT_N_ITER=10
|
| 33 |
-
DEFAULT_KAPPA=10.0
|
| 34 |
-
LAMBDA_DRIFT=0.01
|
| 35 |
-
LAMBDA_INV=0.001
|
| 36 |
-
THRESHOLD=2.3
|
| 37 |
-
|
| 38 |
-
# ββ Task sequence ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 39 |
-
TASKS=(
|
| 40 |
-
"yelp"
|
| 41 |
-
"amazon"
|
| 42 |
-
"mnli"
|
| 43 |
-
"cb"
|
| 44 |
-
"copa"
|
| 45 |
-
"qqp"
|
| 46 |
-
"rte"
|
| 47 |
-
"imdb"
|
| 48 |
-
"sst2"
|
| 49 |
-
"dbpedia"
|
| 50 |
-
"agnews"
|
| 51 |
-
"yahoo"
|
| 52 |
-
"multirc"
|
| 53 |
-
"boolq"
|
| 54 |
-
"wic"
|
| 55 |
-
)
|
| 56 |
-
TASK_ORDER=$(IFS=,; echo "${TASKS[*]}")
|
| 57 |
-
T=${#TASKS[@]}
|
| 58 |
-
|
| 59 |
-
mkdir -p "${OUTPUT_BASE}"
|
| 60 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 61 |
-
echo " OT-SIGN+GainLoRA | Order 3 | T5-Large"
|
| 62 |
-
echo " GPUs: ${GPU_IDS} | Tasks: ${T} | Epochs: ${EPOCHS}"
|
| 63 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 64 |
-
|
| 65 |
-
# ββ Training loop ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 66 |
-
PREV_LORA_PATHS=""
|
| 67 |
-
|
| 68 |
-
for i in "${!TASKS[@]}"; do
|
| 69 |
-
TASK="${TASKS[$i]}"
|
| 70 |
-
TASKNUM=$((i + 1))
|
| 71 |
-
OUTDIR="${OUTPUT_BASE}/${TASKNUM}-${TASK}"
|
| 72 |
-
|
| 73 |
-
if [[ $i -eq 0 ]]; then
|
| 74 |
-
METRIC_KEY="eval_${METRIC_TYPE}"
|
| 75 |
-
else
|
| 76 |
-
METRIC_KEY="eval_${METRIC_TYPE}_for_${TASK}"
|
| 77 |
-
fi
|
| 78 |
-
|
| 79 |
-
echo ""
|
| 80 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 81 |
-
echo " Task ${TASKNUM}/${T}: ${TASK}"
|
| 82 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 83 |
-
|
| 84 |
-
OT_FLAGS="--use_ot_routing True \
|
| 85 |
-
--ot_epsilon ${OT_EPSILON} \
|
| 86 |
-
--ot_n_iter ${OT_N_ITER} \
|
| 87 |
-
--default_kappa ${DEFAULT_KAPPA} \
|
| 88 |
-
--lambda_drift ${LAMBDA_DRIFT} \
|
| 89 |
-
--lambda_inv ${LAMBDA_INV} \
|
| 90 |
-
--invasion_threshold ${THRESHOLD}"
|
| 91 |
-
|
| 92 |
-
PREV_FLAGS=""
|
| 93 |
-
if [[ $i -gt 0 ]]; then
|
| 94 |
-
PREV_OUTDIR="${OUTPUT_BASE}/${i}-${TASKS[$((i-1))]}/saved_weights"
|
| 95 |
-
PREV_FLAGS="--load_checkpoint_from ${PREV_OUTDIR}/trans_input.pt \
|
| 96 |
-
--previous_lora_path ${PREV_LORA_PATHS} \
|
| 97 |
-
--previous_prompt_key_path ${PREV_OUTDIR}/prompts_keys_till_now.pt \
|
| 98 |
-
--previous_vmf_signatures_path ${PREV_OUTDIR}/vmf_signatures.pt \
|
| 99 |
-
--add_instruction_replay \
|
| 100 |
-
--gen_data_dir ${GEN_DATA_DIR} \
|
| 101 |
-
--kl_ratio ${KL_RATIO} \
|
| 102 |
-
--data_replay_freq -1 \
|
| 103 |
-
--replay_after_n_epoch 0"
|
| 104 |
-
fi
|
| 105 |
-
|
| 106 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} torchrun --nproc_per_node=2 src/run_t5.py \
|
| 107 |
-
--do_train \
|
| 108 |
-
--do_predict \
|
| 109 |
-
--predict_with_generate \
|
| 110 |
-
--model_name_or_path "${MODEL_PATH}" \
|
| 111 |
-
--data_dir CL_Benchmark \
|
| 112 |
-
--task_order "${TASK_ORDER}" \
|
| 113 |
-
--task_config_dir "${CONFIG_PREFIX}/${TASK}" \
|
| 114 |
-
--output_dir "${OUTDIR}" \
|
| 115 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 116 |
-
--per_device_eval_batch_size ${EVAL_BATCH} \
|
| 117 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 118 |
-
--learning_rate ${LR} \
|
| 119 |
-
--num_train_epochs ${EPOCHS} \
|
| 120 |
-
--run_name "${RUN_NAME}" \
|
| 121 |
-
--max_source_length 512 \
|
| 122 |
-
--max_target_length 50 \
|
| 123 |
-
--generation_max_length 50 \
|
| 124 |
-
--add_task_name False \
|
| 125 |
-
--add_dataset_name False \
|
| 126 |
-
--lr_scheduler_type constant \
|
| 127 |
-
--warmup_steps 0 \
|
| 128 |
-
--logging_strategy steps \
|
| 129 |
-
--logging_steps 10 \
|
| 130 |
-
--eval_strategy steps \
|
| 131 |
-
--save_strategy steps \
|
| 132 |
-
--save_total_limit 1 \
|
| 133 |
-
--load_best_model_at_end \
|
| 134 |
-
--metric_for_best_model "${METRIC_KEY}" \
|
| 135 |
-
--lora_r 4 \
|
| 136 |
-
--lora_alpha 32 \
|
| 137 |
-
--lora_dropout 0.0 \
|
| 138 |
-
--attn_temperature 1 \
|
| 139 |
-
--mlp_hidden_dim 100 \
|
| 140 |
-
--model_name gainlora_inflora \
|
| 141 |
-
--threshold 0.995 \
|
| 142 |
-
--transthreshold 0.995 \
|
| 143 |
-
--fp16 \
|
| 144 |
-
--gradient_checkpointing True \
|
| 145 |
-
${OT_FLAGS} \
|
| 146 |
-
${PREV_FLAGS}
|
| 147 |
-
|
| 148 |
-
if [[ -z "${PREV_LORA_PATHS}" ]]; then
|
| 149 |
-
PREV_LORA_PATHS="${OUTDIR}/saved_weights"
|
| 150 |
-
else
|
| 151 |
-
PREV_LORA_PATHS="${PREV_LORA_PATHS},${OUTDIR}/saved_weights"
|
| 152 |
-
fi
|
| 153 |
-
|
| 154 |
-
echo " [DONE] Task ${TASKNUM}/${T}: ${TASK}"
|
| 155 |
-
done
|
| 156 |
-
|
| 157 |
-
# ββ Final AP/FT ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 158 |
-
echo ""
|
| 159 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 160 |
-
echo " Computing AP / FT ..."
|
| 161 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 162 |
-
python src/compute_ap_ft.py \
|
| 163 |
-
--output_base "${OUTPUT_BASE}" \
|
| 164 |
-
--task_order "${TASK_ORDER}" \
|
| 165 |
-
--method_name "${RUN_NAME}" \
|
| 166 |
-
--save
|
| 167 |
-
|
| 168 |
-
echo ""
|
| 169 |
-
echo "β All done. Results in: logs_and_outputs/${RUN_NAME}/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/run_ot_sign_order4_t5large.sh
DELETED
|
@@ -1,169 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
###############################################################################
|
| 3 |
-
# OT-SIGN + GainLoRA (T5-Large) β Order 4 (Long Benchmark)
|
| 4 |
-
# ==========================================================
|
| 5 |
-
# Task order: mnli β cb β wic β ... β yahoo (15 tasks)
|
| 6 |
-
# Benchmark: Long (Exact Match metric)
|
| 7 |
-
# Hardware: 2Γ T4 16GB | Estimated time: ~3-4h
|
| 8 |
-
# Run: bash run_ot_sign_order4_t5large.sh [GPU_IDS] [MODEL_PATH]
|
| 9 |
-
###############################################################################
|
| 10 |
-
|
| 11 |
-
set -e
|
| 12 |
-
|
| 13 |
-
export CUDA_DEVICE_ORDER="PCI_BUS_ID"
|
| 14 |
-
GPU_IDS="${1:-0,1}"
|
| 15 |
-
MODEL_PATH="${2:-google/flan-t5-large}"
|
| 16 |
-
|
| 17 |
-
# ββ Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
-
RUN_NAME="ot_sign_order4_t5large"
|
| 19 |
-
OUTPUT_BASE="logs_and_outputs/${RUN_NAME}/outputs"
|
| 20 |
-
CONFIG_PREFIX="configs/gen_script_long_order4_t5_configs"
|
| 21 |
-
GEN_DATA_DIR="generated_data/lora_gen_long_t5"
|
| 22 |
-
METRIC_TYPE="exact_match"
|
| 23 |
-
KL_RATIO=0.1
|
| 24 |
-
EPOCHS=10
|
| 25 |
-
|
| 26 |
-
BATCH_SIZE=4
|
| 27 |
-
EVAL_BATCH=16
|
| 28 |
-
GRAD_ACCUM=8
|
| 29 |
-
LR=0.0003
|
| 30 |
-
|
| 31 |
-
OT_EPSILON=0.05
|
| 32 |
-
OT_N_ITER=10
|
| 33 |
-
DEFAULT_KAPPA=10.0
|
| 34 |
-
LAMBDA_DRIFT=0.01
|
| 35 |
-
LAMBDA_INV=0.001
|
| 36 |
-
THRESHOLD=2.3
|
| 37 |
-
|
| 38 |
-
# ββ Task sequence ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 39 |
-
TASKS=(
|
| 40 |
-
"mnli"
|
| 41 |
-
"cb"
|
| 42 |
-
"wic"
|
| 43 |
-
"copa"
|
| 44 |
-
"qqp"
|
| 45 |
-
"boolq"
|
| 46 |
-
"rte"
|
| 47 |
-
"imdb"
|
| 48 |
-
"yelp"
|
| 49 |
-
"amazon"
|
| 50 |
-
"sst2"
|
| 51 |
-
"dbpedia"
|
| 52 |
-
"agnews"
|
| 53 |
-
"multirc"
|
| 54 |
-
"yahoo"
|
| 55 |
-
)
|
| 56 |
-
TASK_ORDER=$(IFS=,; echo "${TASKS[*]}")
|
| 57 |
-
T=${#TASKS[@]}
|
| 58 |
-
|
| 59 |
-
mkdir -p "${OUTPUT_BASE}"
|
| 60 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 61 |
-
echo " OT-SIGN+GainLoRA | Order 4 | T5-Large"
|
| 62 |
-
echo " GPUs: ${GPU_IDS} | Tasks: ${T} | Epochs: ${EPOCHS}"
|
| 63 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 64 |
-
|
| 65 |
-
# ββ Training loop ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 66 |
-
PREV_LORA_PATHS=""
|
| 67 |
-
|
| 68 |
-
for i in "${!TASKS[@]}"; do
|
| 69 |
-
TASK="${TASKS[$i]}"
|
| 70 |
-
TASKNUM=$((i + 1))
|
| 71 |
-
OUTDIR="${OUTPUT_BASE}/${TASKNUM}-${TASK}"
|
| 72 |
-
|
| 73 |
-
if [[ $i -eq 0 ]]; then
|
| 74 |
-
METRIC_KEY="eval_${METRIC_TYPE}"
|
| 75 |
-
else
|
| 76 |
-
METRIC_KEY="eval_${METRIC_TYPE}_for_${TASK}"
|
| 77 |
-
fi
|
| 78 |
-
|
| 79 |
-
echo ""
|
| 80 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 81 |
-
echo " Task ${TASKNUM}/${T}: ${TASK}"
|
| 82 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 83 |
-
|
| 84 |
-
OT_FLAGS="--use_ot_routing True \
|
| 85 |
-
--ot_epsilon ${OT_EPSILON} \
|
| 86 |
-
--ot_n_iter ${OT_N_ITER} \
|
| 87 |
-
--default_kappa ${DEFAULT_KAPPA} \
|
| 88 |
-
--lambda_drift ${LAMBDA_DRIFT} \
|
| 89 |
-
--lambda_inv ${LAMBDA_INV} \
|
| 90 |
-
--invasion_threshold ${THRESHOLD}"
|
| 91 |
-
|
| 92 |
-
PREV_FLAGS=""
|
| 93 |
-
if [[ $i -gt 0 ]]; then
|
| 94 |
-
PREV_OUTDIR="${OUTPUT_BASE}/${i}-${TASKS[$((i-1))]}/saved_weights"
|
| 95 |
-
PREV_FLAGS="--load_checkpoint_from ${PREV_OUTDIR}/trans_input.pt \
|
| 96 |
-
--previous_lora_path ${PREV_LORA_PATHS} \
|
| 97 |
-
--previous_prompt_key_path ${PREV_OUTDIR}/prompts_keys_till_now.pt \
|
| 98 |
-
--previous_vmf_signatures_path ${PREV_OUTDIR}/vmf_signatures.pt \
|
| 99 |
-
--add_instruction_replay \
|
| 100 |
-
--gen_data_dir ${GEN_DATA_DIR} \
|
| 101 |
-
--kl_ratio ${KL_RATIO} \
|
| 102 |
-
--data_replay_freq -1 \
|
| 103 |
-
--replay_after_n_epoch 0"
|
| 104 |
-
fi
|
| 105 |
-
|
| 106 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} torchrun --nproc_per_node=2 src/run_t5.py \
|
| 107 |
-
--do_train \
|
| 108 |
-
--do_predict \
|
| 109 |
-
--predict_with_generate \
|
| 110 |
-
--model_name_or_path "${MODEL_PATH}" \
|
| 111 |
-
--data_dir CL_Benchmark \
|
| 112 |
-
--task_order "${TASK_ORDER}" \
|
| 113 |
-
--task_config_dir "${CONFIG_PREFIX}/${TASK}" \
|
| 114 |
-
--output_dir "${OUTDIR}" \
|
| 115 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 116 |
-
--per_device_eval_batch_size ${EVAL_BATCH} \
|
| 117 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 118 |
-
--learning_rate ${LR} \
|
| 119 |
-
--num_train_epochs ${EPOCHS} \
|
| 120 |
-
--run_name "${RUN_NAME}" \
|
| 121 |
-
--max_source_length 512 \
|
| 122 |
-
--max_target_length 50 \
|
| 123 |
-
--generation_max_length 50 \
|
| 124 |
-
--add_task_name False \
|
| 125 |
-
--add_dataset_name False \
|
| 126 |
-
--lr_scheduler_type constant \
|
| 127 |
-
--warmup_steps 0 \
|
| 128 |
-
--logging_strategy steps \
|
| 129 |
-
--logging_steps 10 \
|
| 130 |
-
--eval_strategy steps \
|
| 131 |
-
--save_strategy steps \
|
| 132 |
-
--save_total_limit 1 \
|
| 133 |
-
--load_best_model_at_end \
|
| 134 |
-
--metric_for_best_model "${METRIC_KEY}" \
|
| 135 |
-
--lora_r 4 \
|
| 136 |
-
--lora_alpha 32 \
|
| 137 |
-
--lora_dropout 0.0 \
|
| 138 |
-
--attn_temperature 1 \
|
| 139 |
-
--mlp_hidden_dim 100 \
|
| 140 |
-
--model_name gainlora_inflora \
|
| 141 |
-
--threshold 0.995 \
|
| 142 |
-
--transthreshold 0.995 \
|
| 143 |
-
--fp16 \
|
| 144 |
-
--gradient_checkpointing True \
|
| 145 |
-
${OT_FLAGS} \
|
| 146 |
-
${PREV_FLAGS}
|
| 147 |
-
|
| 148 |
-
if [[ -z "${PREV_LORA_PATHS}" ]]; then
|
| 149 |
-
PREV_LORA_PATHS="${OUTDIR}/saved_weights"
|
| 150 |
-
else
|
| 151 |
-
PREV_LORA_PATHS="${PREV_LORA_PATHS},${OUTDIR}/saved_weights"
|
| 152 |
-
fi
|
| 153 |
-
|
| 154 |
-
echo " [DONE] Task ${TASKNUM}/${T}: ${TASK}"
|
| 155 |
-
done
|
| 156 |
-
|
| 157 |
-
# ββ Final AP/FT ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 158 |
-
echo ""
|
| 159 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 160 |
-
echo " Computing AP / FT ..."
|
| 161 |
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
|
| 162 |
-
python src/compute_ap_ft.py \
|
| 163 |
-
--output_base "${OUTPUT_BASE}" \
|
| 164 |
-
--task_order "${TASK_ORDER}" \
|
| 165 |
-
--method_name "${RUN_NAME}" \
|
| 166 |
-
--save
|
| 167 |
-
|
| 168 |
-
echo ""
|
| 169 |
-
echo "β All done. Results in: logs_and_outputs/${RUN_NAME}/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/run_ot_sign_smoke_t5.sh
DELETED
|
@@ -1,70 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
# Fast smoke run for early bug detection (2-5 minutes, not 30+ minutes).
|
| 3 |
-
|
| 4 |
-
set -euo pipefail
|
| 5 |
-
|
| 6 |
-
GPU_IDS="${1:-0}"
|
| 7 |
-
MODEL_PATH="${2:-google/flan-t5-small}"
|
| 8 |
-
|
| 9 |
-
RUN_NAME="ot_sign_smoke_t5"
|
| 10 |
-
OUTDIR="logs_and_outputs/${RUN_NAME}/outputs"
|
| 11 |
-
TASK="yelp"
|
| 12 |
-
TASK_ORDER="yelp"
|
| 13 |
-
CONFIG_DIR="configs/gen_script_long_order3_t5_configs/${TASK}"
|
| 14 |
-
|
| 15 |
-
echo "[1/2] Running preflight checks..."
|
| 16 |
-
python src/preflight_check.py
|
| 17 |
-
|
| 18 |
-
echo "[2/2] Running smoke training (tiny data, tiny steps)..."
|
| 19 |
-
CUDA_VISIBLE_DEVICES="${GPU_IDS}" torchrun --nproc_per_node=1 src/run_t5.py \
|
| 20 |
-
--do_train \
|
| 21 |
-
--do_eval \
|
| 22 |
-
--model_name_or_path "${MODEL_PATH}" \
|
| 23 |
-
--data_dir CL_Benchmark \
|
| 24 |
-
--task_order "${TASK_ORDER}" \
|
| 25 |
-
--task_config_dir "${CONFIG_DIR}" \
|
| 26 |
-
--output_dir "${OUTDIR}" \
|
| 27 |
-
--overwrite_output_dir True \
|
| 28 |
-
--per_device_train_batch_size 1 \
|
| 29 |
-
--per_device_eval_batch_size 1 \
|
| 30 |
-
--gradient_accumulation_steps 1 \
|
| 31 |
-
--learning_rate 3e-4 \
|
| 32 |
-
--num_train_epochs 1 \
|
| 33 |
-
--max_steps 3 \
|
| 34 |
-
--max_num_instances_per_task 8 \
|
| 35 |
-
--max_num_instances_per_eval_task 8 \
|
| 36 |
-
--max_train_samples 8 \
|
| 37 |
-
--max_eval_samples 8 \
|
| 38 |
-
--max_predict_samples 8 \
|
| 39 |
-
--run_name "${RUN_NAME}" \
|
| 40 |
-
--max_source_length 128 \
|
| 41 |
-
--max_target_length 32 \
|
| 42 |
-
--generation_max_length 32 \
|
| 43 |
-
--add_task_name False \
|
| 44 |
-
--add_dataset_name False \
|
| 45 |
-
--lr_scheduler_type constant \
|
| 46 |
-
--warmup_steps 0 \
|
| 47 |
-
--logging_strategy steps \
|
| 48 |
-
--logging_steps 1 \
|
| 49 |
-
--eval_strategy steps \
|
| 50 |
-
--eval_steps 1 \
|
| 51 |
-
--save_strategy no \
|
| 52 |
-
--lora_r 4 \
|
| 53 |
-
--lora_alpha 32 \
|
| 54 |
-
--lora_dropout 0.0 \
|
| 55 |
-
--attn_temperature 1 \
|
| 56 |
-
--mlp_hidden_dim 32 \
|
| 57 |
-
--model_name gainlora_inflora \
|
| 58 |
-
--threshold 0.995 \
|
| 59 |
-
--transthreshold 0.995 \
|
| 60 |
-
--fp16 \
|
| 61 |
-
--gradient_checkpointing True \
|
| 62 |
-
--use_ot_routing True \
|
| 63 |
-
--ot_epsilon 0.05 \
|
| 64 |
-
--ot_n_iter 5 \
|
| 65 |
-
--default_kappa 10.0 \
|
| 66 |
-
--lambda_drift 0.01 \
|
| 67 |
-
--lambda_inv 0.001 \
|
| 68 |
-
--invasion_threshold 2.3
|
| 69 |
-
|
| 70 |
-
echo "Smoke run done."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/run_ot_sign_t4.sh
DELETED
|
@@ -1,488 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
###############################################################################
|
| 3 |
-
# OT-SIGN + GainLoRA (T5-Large) β Optimized for 2ΓT4 (16GB each)
|
| 4 |
-
# ================================================================
|
| 5 |
-
# Changes from original:
|
| 6 |
-
# - batch_size: 16 β 8 (T4 memory constraint)
|
| 7 |
-
# - fp16: enabled (T4 has good FP16 throughput)
|
| 8 |
-
# - gradient_accumulation: 4 (compensate for smaller batch)
|
| 9 |
-
# - OT-SIGN: use_ot_routing enabled from task 2 onward
|
| 10 |
-
# - OT-SIGN: vMF signatures saved/loaded between tasks
|
| 11 |
-
# - OT-SIGN: anti-drift + anti-invasion losses activated
|
| 12 |
-
# - num_train_epochs: 50 (reduced for faster iteration on T4)
|
| 13 |
-
# - ipdb/cupy guards already handled in code
|
| 14 |
-
###############################################################################
|
| 15 |
-
|
| 16 |
-
export CUDA_DEVICE_ORDER="PCI_BUS_ID"
|
| 17 |
-
|
| 18 |
-
# === Configuration ===
|
| 19 |
-
GPU_IDS="${1:-0,1}" # Default: use GPU 0,1
|
| 20 |
-
MODEL_PATH="${2:-google/flan-t5-large}" # T5-Large
|
| 21 |
-
RUN_NAME="ot_sign_t5_gainlora_t4"
|
| 22 |
-
TASK_ORDER="task1572_samsum_summary,task363_sst2_polarity_classification,task1290_xsum_summarization,task181_outcome_extraction,task002_quoref_answer_generation,task1510_evalution_relation_extraction,task639_multi_woz_user_utterance_generation,task1729_personachat_generate_next,task073_commonsenseqa_answer_generation,task1590_diplomacy_text_generation,task748_glucose_reverse_cause_event_detection,task511_reddit_tifu_long_text_summarization,task591_sciq_answer_generation,task1687_sentiment140_classification,task875_emotion_classification"
|
| 23 |
-
OUTPUT_BASE="logs_and_outputs/${RUN_NAME}/outputs"
|
| 24 |
-
|
| 25 |
-
# T4-optimized hyperparameters
|
| 26 |
-
BATCH_SIZE=8
|
| 27 |
-
EVAL_BATCH_SIZE=4
|
| 28 |
-
GRAD_ACCUM=4
|
| 29 |
-
LR=0.0003
|
| 30 |
-
EPOCHS=50
|
| 31 |
-
MAX_SRC=512
|
| 32 |
-
MAX_TGT=50
|
| 33 |
-
LORA_R=4
|
| 34 |
-
LORA_ALPHA=32
|
| 35 |
-
|
| 36 |
-
# OT-SIGN hyperparameters
|
| 37 |
-
OT_EPSILON=0.05
|
| 38 |
-
OT_N_ITER=10
|
| 39 |
-
DEFAULT_KAPPA=10.0
|
| 40 |
-
LAMBDA_DRIFT=0.01
|
| 41 |
-
LAMBDA_INV=0.001
|
| 42 |
-
INVASION_THRESHOLD=2.3
|
| 43 |
-
|
| 44 |
-
# Common flags
|
| 45 |
-
COMMON_FLAGS="--predict_with_generate \
|
| 46 |
-
--model_name_or_path ${MODEL_PATH} \
|
| 47 |
-
--data_dir CL_Benchmark \
|
| 48 |
-
--task_order ${TASK_ORDER} \
|
| 49 |
-
--per_device_eval_batch_size ${EVAL_BATCH_SIZE} \
|
| 50 |
-
--learning_rate ${LR} \
|
| 51 |
-
--num_train_epochs ${EPOCHS} \
|
| 52 |
-
--run_name ${RUN_NAME} \
|
| 53 |
-
--max_source_length ${MAX_SRC} \
|
| 54 |
-
--max_target_length ${MAX_TGT} \
|
| 55 |
-
--generation_max_length ${MAX_TGT} \
|
| 56 |
-
--add_task_name False \
|
| 57 |
-
--add_dataset_name False \
|
| 58 |
-
--lr_scheduler_type constant \
|
| 59 |
-
--warmup_steps 0 \
|
| 60 |
-
--logging_strategy steps \
|
| 61 |
-
--logging_steps 10 \
|
| 62 |
-
--eval_strategy steps \
|
| 63 |
-
--save_strategy steps \
|
| 64 |
-
--save_total_limit 1 \
|
| 65 |
-
--load_best_model_at_end \
|
| 66 |
-
--lora_r ${LORA_R} \
|
| 67 |
-
--lora_alpha ${LORA_ALPHA} \
|
| 68 |
-
--lora_dropout 0.0 \
|
| 69 |
-
--attn_temperature 1 \
|
| 70 |
-
--mlp_hidden_dim 100 \
|
| 71 |
-
--model_name gainlora_inflora \
|
| 72 |
-
--threshold 0.995 \
|
| 73 |
-
--transthreshold 0.995 \
|
| 74 |
-
--fp16"
|
| 75 |
-
|
| 76 |
-
# OT-SIGN flags (used from task 2 onward)
|
| 77 |
-
OT_SIGN_FLAGS="--use_ot_routing True \
|
| 78 |
-
--ot_epsilon ${OT_EPSILON} \
|
| 79 |
-
--ot_n_iter ${OT_N_ITER} \
|
| 80 |
-
--default_kappa ${DEFAULT_KAPPA} \
|
| 81 |
-
--lambda_drift ${LAMBDA_DRIFT} \
|
| 82 |
-
--lambda_inv ${LAMBDA_INV} \
|
| 83 |
-
--invasion_threshold ${INVASION_THRESHOLD}"
|
| 84 |
-
|
| 85 |
-
echo "============================================="
|
| 86 |
-
echo "OT-SIGN + GainLoRA T5-Large on 2ΓT4"
|
| 87 |
-
echo "Run: ${RUN_NAME}"
|
| 88 |
-
echo "Model: ${MODEL_PATH}"
|
| 89 |
-
echo "Batch: ${BATCH_SIZE} Γ ${GRAD_ACCUM} grad_accum"
|
| 90 |
-
echo "FP16: enabled"
|
| 91 |
-
echo "OT-SIGN: epsilon=${OT_EPSILON}, kappa_def=${DEFAULT_KAPPA}"
|
| 92 |
-
echo "============================================="
|
| 93 |
-
|
| 94 |
-
# Create output directories
|
| 95 |
-
mkdir -p ${OUTPUT_BASE}
|
| 96 |
-
mkdir -p logs_and_outputs/${RUN_NAME}/ot_sign_logs
|
| 97 |
-
|
| 98 |
-
###############################################################################
|
| 99 |
-
# Task 1: task1572_samsum_summary (NO OT routing β first task, no signatures)
|
| 100 |
-
###############################################################################
|
| 101 |
-
echo ""
|
| 102 |
-
echo "===== Task 1/15: task1572_samsum_summary (baseline, no OT) ====="
|
| 103 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 104 |
-
--do_train \
|
| 105 |
-
--do_predict \
|
| 106 |
-
${COMMON_FLAGS} \
|
| 107 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task1572_samsum_summary \
|
| 108 |
-
--output_dir ${OUTPUT_BASE}/1-task1572_samsum_summary \
|
| 109 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 110 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 111 |
-
--metric_for_best_model eval_rougeL \
|
| 112 |
-
--data_replay_freq -1 \
|
| 113 |
-
--replay_after_n_epoch 0 \
|
| 114 |
-
--kl_ratio 0.5 \
|
| 115 |
-
--use_ot_routing True \
|
| 116 |
-
--ot_epsilon ${OT_EPSILON} \
|
| 117 |
-
--ot_n_iter ${OT_N_ITER} \
|
| 118 |
-
--default_kappa ${DEFAULT_KAPPA}
|
| 119 |
-
|
| 120 |
-
###############################################################################
|
| 121 |
-
# Task 2: task363_sst2 (OT routing with 1 signature from task 1)
|
| 122 |
-
###############################################################################
|
| 123 |
-
echo ""
|
| 124 |
-
echo "===== Task 2/15: task363_sst2_polarity_classification (OT-SIGN active) ====="
|
| 125 |
-
PREV_1="${OUTPUT_BASE}/1-task1572_samsum_summary/saved_weights"
|
| 126 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 127 |
-
--do_train \
|
| 128 |
-
--do_predict \
|
| 129 |
-
${COMMON_FLAGS} \
|
| 130 |
-
--load_checkpoint_from ${PREV_1}/trans_input.pt \
|
| 131 |
-
--previous_lora_path ${PREV_1} \
|
| 132 |
-
--previous_prompt_key_path ${PREV_1}/prompts_keys_till_now.pt \
|
| 133 |
-
--previous_vmf_signatures_path ${PREV_1}/vmf_signatures.pt \
|
| 134 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 135 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task363_sst2_polarity_classification \
|
| 136 |
-
--output_dir ${OUTPUT_BASE}/2-task363_sst2_polarity_classification \
|
| 137 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 138 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 139 |
-
--metric_for_best_model eval_rougeL_for_task363_sst2_polarity_classification \
|
| 140 |
-
--add_instruction_replay \
|
| 141 |
-
--data_replay_freq -1 \
|
| 142 |
-
--replay_after_n_epoch 0 \
|
| 143 |
-
--kl_ratio 0.5 \
|
| 144 |
-
${OT_SIGN_FLAGS}
|
| 145 |
-
|
| 146 |
-
###############################################################################
|
| 147 |
-
# Task 3: task1290_xsum_summarization
|
| 148 |
-
###############################################################################
|
| 149 |
-
echo ""
|
| 150 |
-
echo "===== Task 3/15: task1290_xsum_summarization (OT-SIGN active) ====="
|
| 151 |
-
PREV_2="${OUTPUT_BASE}/2-task363_sst2_polarity_classification/saved_weights"
|
| 152 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 153 |
-
--do_train \
|
| 154 |
-
--do_predict \
|
| 155 |
-
${COMMON_FLAGS} \
|
| 156 |
-
--load_checkpoint_from ${PREV_2}/trans_input.pt \
|
| 157 |
-
--previous_lora_path ${PREV_1},${PREV_2} \
|
| 158 |
-
--previous_prompt_key_path ${PREV_2}/prompts_keys_till_now.pt \
|
| 159 |
-
--previous_vmf_signatures_path ${PREV_2}/vmf_signatures.pt \
|
| 160 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 161 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task1290_xsum_summarization \
|
| 162 |
-
--output_dir ${OUTPUT_BASE}/3-task1290_xsum_summarization \
|
| 163 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 164 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 165 |
-
--metric_for_best_model eval_rougeL_for_task1290_xsum_summarization \
|
| 166 |
-
--add_instruction_replay \
|
| 167 |
-
--data_replay_freq -1 \
|
| 168 |
-
--replay_after_n_epoch 0 \
|
| 169 |
-
--kl_ratio 0.5 \
|
| 170 |
-
${OT_SIGN_FLAGS}
|
| 171 |
-
|
| 172 |
-
###############################################################################
|
| 173 |
-
# Task 4: task181_outcome_extraction
|
| 174 |
-
###############################################################################
|
| 175 |
-
echo ""
|
| 176 |
-
echo "===== Task 4/15: task181_outcome_extraction (OT-SIGN active) ====="
|
| 177 |
-
PREV_3="${OUTPUT_BASE}/3-task1290_xsum_summarization/saved_weights"
|
| 178 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 179 |
-
--do_train \
|
| 180 |
-
--do_predict \
|
| 181 |
-
${COMMON_FLAGS} \
|
| 182 |
-
--load_checkpoint_from ${PREV_3}/trans_input.pt \
|
| 183 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3} \
|
| 184 |
-
--previous_prompt_key_path ${PREV_3}/prompts_keys_till_now.pt \
|
| 185 |
-
--previous_vmf_signatures_path ${PREV_3}/vmf_signatures.pt \
|
| 186 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 187 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task181_outcome_extraction \
|
| 188 |
-
--output_dir ${OUTPUT_BASE}/4-task181_outcome_extraction \
|
| 189 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 190 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 191 |
-
--metric_for_best_model eval_rougeL_for_task181_outcome_extraction \
|
| 192 |
-
--add_instruction_replay \
|
| 193 |
-
--data_replay_freq -1 \
|
| 194 |
-
--replay_after_n_epoch 0 \
|
| 195 |
-
--kl_ratio 0.5 \
|
| 196 |
-
${OT_SIGN_FLAGS}
|
| 197 |
-
|
| 198 |
-
###############################################################################
|
| 199 |
-
# Task 5: task002_quoref_answer_generation
|
| 200 |
-
###############################################################################
|
| 201 |
-
echo ""
|
| 202 |
-
echo "===== Task 5/15: task002_quoref_answer_generation (OT-SIGN active) ====="
|
| 203 |
-
PREV_4="${OUTPUT_BASE}/4-task181_outcome_extraction/saved_weights"
|
| 204 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 205 |
-
--do_train \
|
| 206 |
-
--do_predict \
|
| 207 |
-
${COMMON_FLAGS} \
|
| 208 |
-
--load_checkpoint_from ${PREV_4}/trans_input.pt \
|
| 209 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4} \
|
| 210 |
-
--previous_prompt_key_path ${PREV_4}/prompts_keys_till_now.pt \
|
| 211 |
-
--previous_vmf_signatures_path ${PREV_4}/vmf_signatures.pt \
|
| 212 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 213 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task002_quoref_answer_generation \
|
| 214 |
-
--output_dir ${OUTPUT_BASE}/5-task002_quoref_answer_generation \
|
| 215 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 216 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 217 |
-
--metric_for_best_model eval_rougeL_for_task002_quoref_answer_generation \
|
| 218 |
-
--add_instruction_replay \
|
| 219 |
-
--data_replay_freq -1 \
|
| 220 |
-
--replay_after_n_epoch 0 \
|
| 221 |
-
--kl_ratio 0.5 \
|
| 222 |
-
${OT_SIGN_FLAGS}
|
| 223 |
-
|
| 224 |
-
###############################################################################
|
| 225 |
-
# Task 6: task1510_evalution_relation_extraction
|
| 226 |
-
###############################################################################
|
| 227 |
-
echo ""
|
| 228 |
-
echo "===== Task 6/15: task1510_evalution_relation_extraction (OT-SIGN active) ====="
|
| 229 |
-
PREV_5="${OUTPUT_BASE}/5-task002_quoref_answer_generation/saved_weights"
|
| 230 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 231 |
-
--do_train \
|
| 232 |
-
--do_predict \
|
| 233 |
-
${COMMON_FLAGS} \
|
| 234 |
-
--load_checkpoint_from ${PREV_5}/trans_input.pt \
|
| 235 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5} \
|
| 236 |
-
--previous_prompt_key_path ${PREV_5}/prompts_keys_till_now.pt \
|
| 237 |
-
--previous_vmf_signatures_path ${PREV_5}/vmf_signatures.pt \
|
| 238 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 239 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task1510_evalution_relation_extraction \
|
| 240 |
-
--output_dir ${OUTPUT_BASE}/6-task1510_evalution_relation_extraction \
|
| 241 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 242 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 243 |
-
--metric_for_best_model eval_rougeL_for_task1510_evalution_relation_extraction \
|
| 244 |
-
--add_instruction_replay \
|
| 245 |
-
--data_replay_freq -1 \
|
| 246 |
-
--replay_after_n_epoch 0 \
|
| 247 |
-
--kl_ratio 0.5 \
|
| 248 |
-
${OT_SIGN_FLAGS}
|
| 249 |
-
|
| 250 |
-
###############################################################################
|
| 251 |
-
# Task 7: task639_multi_woz_user_utterance_generation
|
| 252 |
-
###############################################################################
|
| 253 |
-
echo ""
|
| 254 |
-
echo "===== Task 7/15: task639_multi_woz_user_utterance_generation (OT-SIGN active) ====="
|
| 255 |
-
PREV_6="${OUTPUT_BASE}/6-task1510_evalution_relation_extraction/saved_weights"
|
| 256 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 257 |
-
--do_train \
|
| 258 |
-
--do_predict \
|
| 259 |
-
${COMMON_FLAGS} \
|
| 260 |
-
--load_checkpoint_from ${PREV_6}/trans_input.pt \
|
| 261 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6} \
|
| 262 |
-
--previous_prompt_key_path ${PREV_6}/prompts_keys_till_now.pt \
|
| 263 |
-
--previous_vmf_signatures_path ${PREV_6}/vmf_signatures.pt \
|
| 264 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 265 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task639_multi_woz_user_utterance_generation \
|
| 266 |
-
--output_dir ${OUTPUT_BASE}/7-task639_multi_woz_user_utterance_generation \
|
| 267 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 268 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 269 |
-
--metric_for_best_model eval_rougeL_for_task639_multi_woz_user_utterance_generation \
|
| 270 |
-
--add_instruction_replay \
|
| 271 |
-
--data_replay_freq -1 \
|
| 272 |
-
--replay_after_n_epoch 0 \
|
| 273 |
-
--kl_ratio 0.5 \
|
| 274 |
-
${OT_SIGN_FLAGS}
|
| 275 |
-
|
| 276 |
-
###############################################################################
|
| 277 |
-
# Task 8: task1729_personachat_generate_next
|
| 278 |
-
###############################################################################
|
| 279 |
-
echo ""
|
| 280 |
-
echo "===== Task 8/15: task1729_personachat_generate_next (OT-SIGN active) ====="
|
| 281 |
-
PREV_7="${OUTPUT_BASE}/7-task639_multi_woz_user_utterance_generation/saved_weights"
|
| 282 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 283 |
-
--do_train \
|
| 284 |
-
--do_predict \
|
| 285 |
-
${COMMON_FLAGS} \
|
| 286 |
-
--load_checkpoint_from ${PREV_7}/trans_input.pt \
|
| 287 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6},${PREV_7} \
|
| 288 |
-
--previous_prompt_key_path ${PREV_7}/prompts_keys_till_now.pt \
|
| 289 |
-
--previous_vmf_signatures_path ${PREV_7}/vmf_signatures.pt \
|
| 290 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 291 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task1729_personachat_generate_next \
|
| 292 |
-
--output_dir ${OUTPUT_BASE}/8-task1729_personachat_generate_next \
|
| 293 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 294 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 295 |
-
--metric_for_best_model eval_rougeL_for_task1729_personachat_generate_next \
|
| 296 |
-
--add_instruction_replay \
|
| 297 |
-
--data_replay_freq -1 \
|
| 298 |
-
--replay_after_n_epoch 0 \
|
| 299 |
-
--kl_ratio 0.5 \
|
| 300 |
-
${OT_SIGN_FLAGS}
|
| 301 |
-
|
| 302 |
-
###############################################################################
|
| 303 |
-
# Task 9: task073_commonsenseqa_answer_generation
|
| 304 |
-
###############################################################################
|
| 305 |
-
echo ""
|
| 306 |
-
echo "===== Task 9/15: task073_commonsenseqa_answer_generation (OT-SIGN active) ====="
|
| 307 |
-
PREV_8="${OUTPUT_BASE}/8-task1729_personachat_generate_next/saved_weights"
|
| 308 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 309 |
-
--do_train \
|
| 310 |
-
--do_predict \
|
| 311 |
-
${COMMON_FLAGS} \
|
| 312 |
-
--load_checkpoint_from ${PREV_8}/trans_input.pt \
|
| 313 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6},${PREV_7},${PREV_8} \
|
| 314 |
-
--previous_prompt_key_path ${PREV_8}/prompts_keys_till_now.pt \
|
| 315 |
-
--previous_vmf_signatures_path ${PREV_8}/vmf_signatures.pt \
|
| 316 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 317 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task073_commonsenseqa_answer_generation \
|
| 318 |
-
--output_dir ${OUTPUT_BASE}/9-task073_commonsenseqa_answer_generation \
|
| 319 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 320 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 321 |
-
--metric_for_best_model eval_rougeL_for_task073_commonsenseqa_answer_generation \
|
| 322 |
-
--add_instruction_replay \
|
| 323 |
-
--data_replay_freq -1 \
|
| 324 |
-
--replay_after_n_epoch 0 \
|
| 325 |
-
--kl_ratio 0.5 \
|
| 326 |
-
${OT_SIGN_FLAGS}
|
| 327 |
-
|
| 328 |
-
###############################################################################
|
| 329 |
-
# Task 10: task1590_diplomacy_text_generation
|
| 330 |
-
###############################################################################
|
| 331 |
-
echo ""
|
| 332 |
-
echo "===== Task 10/15: task1590_diplomacy_text_generation (OT-SIGN active) ====="
|
| 333 |
-
PREV_9="${OUTPUT_BASE}/9-task073_commonsenseqa_answer_generation/saved_weights"
|
| 334 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 335 |
-
--do_train \
|
| 336 |
-
--do_predict \
|
| 337 |
-
${COMMON_FLAGS} \
|
| 338 |
-
--load_checkpoint_from ${PREV_9}/trans_input.pt \
|
| 339 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6},${PREV_7},${PREV_8},${PREV_9} \
|
| 340 |
-
--previous_prompt_key_path ${PREV_9}/prompts_keys_till_now.pt \
|
| 341 |
-
--previous_vmf_signatures_path ${PREV_9}/vmf_signatures.pt \
|
| 342 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 343 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task1590_diplomacy_text_generation \
|
| 344 |
-
--output_dir ${OUTPUT_BASE}/10-task1590_diplomacy_text_generation \
|
| 345 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 346 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 347 |
-
--metric_for_best_model eval_rougeL_for_task1590_diplomacy_text_generation \
|
| 348 |
-
--add_instruction_replay \
|
| 349 |
-
--data_replay_freq -1 \
|
| 350 |
-
--replay_after_n_epoch 0 \
|
| 351 |
-
--kl_ratio 0.5 \
|
| 352 |
-
${OT_SIGN_FLAGS}
|
| 353 |
-
|
| 354 |
-
###############################################################################
|
| 355 |
-
# Task 11: task748_glucose_reverse_cause_event_detection
|
| 356 |
-
###############################################################################
|
| 357 |
-
echo ""
|
| 358 |
-
echo "===== Task 11/15: task748_glucose_reverse_cause_event_detection (OT-SIGN active) ====="
|
| 359 |
-
PREV_10="${OUTPUT_BASE}/10-task1590_diplomacy_text_generation/saved_weights"
|
| 360 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 361 |
-
--do_train \
|
| 362 |
-
--do_predict \
|
| 363 |
-
${COMMON_FLAGS} \
|
| 364 |
-
--load_checkpoint_from ${PREV_10}/trans_input.pt \
|
| 365 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6},${PREV_7},${PREV_8},${PREV_9},${PREV_10} \
|
| 366 |
-
--previous_prompt_key_path ${PREV_10}/prompts_keys_till_now.pt \
|
| 367 |
-
--previous_vmf_signatures_path ${PREV_10}/vmf_signatures.pt \
|
| 368 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 369 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task748_glucose_reverse_cause_event_detection \
|
| 370 |
-
--output_dir ${OUTPUT_BASE}/11-task748_glucose_reverse_cause_event_detection \
|
| 371 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 372 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 373 |
-
--metric_for_best_model eval_rougeL_for_task748_glucose_reverse_cause_event_detection \
|
| 374 |
-
--add_instruction_replay \
|
| 375 |
-
--data_replay_freq -1 \
|
| 376 |
-
--replay_after_n_epoch 0 \
|
| 377 |
-
--kl_ratio 0.5 \
|
| 378 |
-
${OT_SIGN_FLAGS}
|
| 379 |
-
|
| 380 |
-
###############################################################################
|
| 381 |
-
# Task 12: task511_reddit_tifu_long_text_summarization
|
| 382 |
-
###############################################################################
|
| 383 |
-
echo ""
|
| 384 |
-
echo "===== Task 12/15: task511_reddit_tifu_long_text_summarization (OT-SIGN active) ====="
|
| 385 |
-
PREV_11="${OUTPUT_BASE}/11-task748_glucose_reverse_cause_event_detection/saved_weights"
|
| 386 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 387 |
-
--do_train \
|
| 388 |
-
--do_predict \
|
| 389 |
-
${COMMON_FLAGS} \
|
| 390 |
-
--load_checkpoint_from ${PREV_11}/trans_input.pt \
|
| 391 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6},${PREV_7},${PREV_8},${PREV_9},${PREV_10},${PREV_11} \
|
| 392 |
-
--previous_prompt_key_path ${PREV_11}/prompts_keys_till_now.pt \
|
| 393 |
-
--previous_vmf_signatures_path ${PREV_11}/vmf_signatures.pt \
|
| 394 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 395 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task511_reddit_tifu_long_text_summarization \
|
| 396 |
-
--output_dir ${OUTPUT_BASE}/12-task511_reddit_tifu_long_text_summarization \
|
| 397 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 398 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 399 |
-
--metric_for_best_model eval_rougeL_for_task511_reddit_tifu_long_text_summarization \
|
| 400 |
-
--add_instruction_replay \
|
| 401 |
-
--data_replay_freq -1 \
|
| 402 |
-
--replay_after_n_epoch 0 \
|
| 403 |
-
--kl_ratio 0.5 \
|
| 404 |
-
${OT_SIGN_FLAGS}
|
| 405 |
-
|
| 406 |
-
###############################################################################
|
| 407 |
-
# Task 13: task591_sciq_answer_generation
|
| 408 |
-
###############################################################################
|
| 409 |
-
echo ""
|
| 410 |
-
echo "===== Task 13/15: task591_sciq_answer_generation (OT-SIGN active) ====="
|
| 411 |
-
PREV_12="${OUTPUT_BASE}/12-task511_reddit_tifu_long_text_summarization/saved_weights"
|
| 412 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 413 |
-
--do_train \
|
| 414 |
-
--do_predict \
|
| 415 |
-
${COMMON_FLAGS} \
|
| 416 |
-
--load_checkpoint_from ${PREV_12}/trans_input.pt \
|
| 417 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6},${PREV_7},${PREV_8},${PREV_9},${PREV_10},${PREV_11},${PREV_12} \
|
| 418 |
-
--previous_prompt_key_path ${PREV_12}/prompts_keys_till_now.pt \
|
| 419 |
-
--previous_vmf_signatures_path ${PREV_12}/vmf_signatures.pt \
|
| 420 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 421 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task591_sciq_answer_generation \
|
| 422 |
-
--output_dir ${OUTPUT_BASE}/13-task591_sciq_answer_generation \
|
| 423 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 424 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 425 |
-
--metric_for_best_model eval_rougeL_for_task591_sciq_answer_generation \
|
| 426 |
-
--add_instruction_replay \
|
| 427 |
-
--data_replay_freq -1 \
|
| 428 |
-
--replay_after_n_epoch 0 \
|
| 429 |
-
--kl_ratio 0.5 \
|
| 430 |
-
${OT_SIGN_FLAGS}
|
| 431 |
-
|
| 432 |
-
###############################################################################
|
| 433 |
-
# Task 14: task1687_sentiment140_classification
|
| 434 |
-
###############################################################################
|
| 435 |
-
echo ""
|
| 436 |
-
echo "===== Task 14/15: task1687_sentiment140_classification (OT-SIGN active) ====="
|
| 437 |
-
PREV_13="${OUTPUT_BASE}/13-task591_sciq_answer_generation/saved_weights"
|
| 438 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 439 |
-
--do_train \
|
| 440 |
-
--do_predict \
|
| 441 |
-
${COMMON_FLAGS} \
|
| 442 |
-
--load_checkpoint_from ${PREV_13}/trans_input.pt \
|
| 443 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6},${PREV_7},${PREV_8},${PREV_9},${PREV_10},${PREV_11},${PREV_12},${PREV_13} \
|
| 444 |
-
--previous_prompt_key_path ${PREV_13}/prompts_keys_till_now.pt \
|
| 445 |
-
--previous_vmf_signatures_path ${PREV_13}/vmf_signatures.pt \
|
| 446 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 447 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task1687_sentiment140_classification \
|
| 448 |
-
--output_dir ${OUTPUT_BASE}/14-task1687_sentiment140_classification \
|
| 449 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 450 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 451 |
-
--metric_for_best_model eval_rougeL_for_task1687_sentiment140_classification \
|
| 452 |
-
--add_instruction_replay \
|
| 453 |
-
--data_replay_freq -1 \
|
| 454 |
-
--replay_after_n_epoch 0 \
|
| 455 |
-
--kl_ratio 0.5 \
|
| 456 |
-
${OT_SIGN_FLAGS}
|
| 457 |
-
|
| 458 |
-
###############################################################################
|
| 459 |
-
# Task 15: task875_emotion_classification
|
| 460 |
-
###############################################################################
|
| 461 |
-
echo ""
|
| 462 |
-
echo "===== Task 15/15: task875_emotion_classification (OT-SIGN active) ====="
|
| 463 |
-
PREV_14="${OUTPUT_BASE}/14-task1687_sentiment140_classification/saved_weights"
|
| 464 |
-
CUDA_VISIBLE_DEVICES=${GPU_IDS} python src/run_t5.py \
|
| 465 |
-
--do_train \
|
| 466 |
-
--do_predict \
|
| 467 |
-
${COMMON_FLAGS} \
|
| 468 |
-
--load_checkpoint_from ${PREV_14}/trans_input.pt \
|
| 469 |
-
--previous_lora_path ${PREV_1},${PREV_2},${PREV_3},${PREV_4},${PREV_5},${PREV_6},${PREV_7},${PREV_8},${PREV_9},${PREV_10},${PREV_11},${PREV_12},${PREV_13},${PREV_14} \
|
| 470 |
-
--previous_prompt_key_path ${PREV_14}/prompts_keys_till_now.pt \
|
| 471 |
-
--previous_vmf_signatures_path ${PREV_14}/vmf_signatures.pt \
|
| 472 |
-
--gen_data_dir generated_data/lora_gen_superni_t5 \
|
| 473 |
-
--task_config_dir configs/gen_script_superni_order1_t5_configs/task875_emotion_classification \
|
| 474 |
-
--output_dir ${OUTPUT_BASE}/15-task875_emotion_classification \
|
| 475 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
| 476 |
-
--gradient_accumulation_steps ${GRAD_ACCUM} \
|
| 477 |
-
--metric_for_best_model eval_rougeL_for_task875_emotion_classification \
|
| 478 |
-
--add_instruction_replay \
|
| 479 |
-
--data_replay_freq -1 \
|
| 480 |
-
--replay_after_n_epoch 0 \
|
| 481 |
-
--kl_ratio 0.5 \
|
| 482 |
-
${OT_SIGN_FLAGS}
|
| 483 |
-
|
| 484 |
-
echo ""
|
| 485 |
-
echo "============================================="
|
| 486 |
-
echo "OT-SIGN Training Complete!"
|
| 487 |
-
echo "Logs: logs_and_outputs/${RUN_NAME}/ot_sign_logs/"
|
| 488 |
-
echo "============================================="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_collator.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:7ac24a521ab05c5f986666baca176d46a7b716692db92c57ce86c0b150597b6e
|
| 3 |
-
size 10116
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_dataset.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:f2e7871bd4488d77a1beca52f07be680fe96e2580847792047caf3d76364750d
|
| 3 |
-
size 13159
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_trainer_gainlora_inflora.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:9751f103b0e86c9b3b8f269dae372351263cb0824656c821c90a8254847ee1e4
|
| 3 |
-
size 90854
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_trainer_gainlora_inflora_llama.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:d36384d520c11413ee49678a86ebc5bdc3671c64ea4b8ea49631c4ef5037d9d0
|
| 3 |
-
size 85068
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_trainer_gainlora_olora.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:370b7649906c9cf60e7fb0fd8839938433c42dbfcae79c7ff3e635313b62dcdf
|
| 3 |
-
size 76727
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_trainer_gainlora_olora_llama.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:f1680b3b17975f4de053e9be0f7eab2ef7902865cbe78059677cd3e02a1b63c2
|
| 3 |
-
size 76991
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_trainer_inflora.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:77eefddbbd5e041b41abe092f7004787fd48805b2c8608eaef3278fdab1812bd
|
| 3 |
-
size 39965
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_trainer_inflora_llama.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:4fa7568e94200b9196177ed47ea2c4d203ced2796d4f68df9d737b3f8c74fbd4
|
| 3 |
-
size 41975
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_trainer_olora.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:5d0394c51dfd84ef4fde8f259a4bd2a5bfba5fc5ded9874c7e48ec016335154e
|
| 3 |
-
size 29030
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/cl_trainer_olora_llama.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:3e7defc47276232e838f31b4b8dce26c968c00b772590be8a2105a77190ffaa6
|
| 3 |
-
size 29042
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/compat_transformers.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:e1dfbaa2911f50bbc0919979a7abaebff3700e1c54651e42f2c19bf2c4f8e1b5
|
| 3 |
-
size 6959
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/llama_gainlora_inflora.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:4bd9b3d05288494ad72b0151d68a39e9381752a5ef49819c9f7576d87a27ac4b
|
| 3 |
-
size 83793
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/llama_inflora.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:df016d6843864aa718d9b408bef534b204cdfd89b6ab8a3a65666f8dc0159245
|
| 3 |
-
size 74109
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/ot_sign_utils.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:55761c6d084de04d7ee473dccb92cdffe94d819ce33435580a56fc28297df409
|
| 3 |
-
size 13082
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/ot_sign_utils.cpython-313.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:64711cfa682645e7d2df1e923d09f0dc35d4ffb8c45807972df75a4c1c1755a1
|
| 3 |
-
size 12377
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/run_llama.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:ff4021939dae2e3c66abfccb78c774324ec19de43dee71d5c8838fd7e37167c2
|
| 3 |
-
size 44561
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/run_logger.cpython-313.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:96c719d7c1cf1f2bd4dddc4808b5f512a221ec5a4f8ebd1a0c60d4069216339f
|
| 3 |
-
size 5510
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/run_t5.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:b490149aa88456c921dbecd66d0b6119a7a6be4cdb8634f4d5efcb2d0dad43e7
|
| 3 |
-
size 48700
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/t5_gainlora_inflora.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:413a2c9a942c77bbc879103ca0c963de3a66d92b841aa6216a3239b44cf43665
|
| 3 |
-
size 125803
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/__pycache__/t5_inflora.cpython-312.pyc
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:8279a00efc964668a6729e13dcd430f08b4eaf1c1ee5ae31fffe31da9922bb9a
|
| 3 |
-
size 111402
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/compat_transformers.py
DELETED
|
@@ -1,206 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Compatibility shims for transformers 4.x APIs removed in transformers 5.0.
|
| 3 |
-
|
| 4 |
-
This module provides fallback definitions for all symbols and attributes
|
| 5 |
-
that were removed from the transformers library in version 5.0, allowing
|
| 6 |
-
the trainer code (originally written for transformers ~4.28) to run
|
| 7 |
-
without modification on transformers 5.0+.
|
| 8 |
-
|
| 9 |
-
Usage:
|
| 10 |
-
from compat_transformers import (
|
| 11 |
-
ShardedDDPOption, is_sagemaker_mp_enabled, smp_forward_backward,
|
| 12 |
-
deepspeed_init, deepspeed_load_checkpoint, HPSearchBackend,
|
| 13 |
-
patch_trainer_compat,
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
# In your Trainer subclass __init__:
|
| 17 |
-
class MyTrainer(Seq2SeqTrainer):
|
| 18 |
-
def __init__(self, *args, **kwargs):
|
| 19 |
-
super().__init__(*args, **kwargs)
|
| 20 |
-
patch_trainer_compat(self)
|
| 21 |
-
"""
|
| 22 |
-
|
| 23 |
-
from enum import Enum
|
| 24 |
-
|
| 25 |
-
# ============================================================================
|
| 26 |
-
# ShardedDDPOption (removed in transformers 5.0, replaced by FSDP)
|
| 27 |
-
# ============================================================================
|
| 28 |
-
try:
|
| 29 |
-
from transformers.trainer import ShardedDDPOption
|
| 30 |
-
except ImportError:
|
| 31 |
-
class ShardedDDPOption(str, Enum):
|
| 32 |
-
SIMPLE = "simple"
|
| 33 |
-
ZERO_DP_2 = "zero_dp_2"
|
| 34 |
-
ZERO_DP_3 = "zero_dp_3"
|
| 35 |
-
OFFLOAD = "offload"
|
| 36 |
-
|
| 37 |
-
# ============================================================================
|
| 38 |
-
# is_sagemaker_mp_enabled (removed in transformers 5.0)
|
| 39 |
-
# ============================================================================
|
| 40 |
-
try:
|
| 41 |
-
from transformers.trainer import is_sagemaker_mp_enabled
|
| 42 |
-
except ImportError:
|
| 43 |
-
def is_sagemaker_mp_enabled():
|
| 44 |
-
return False
|
| 45 |
-
|
| 46 |
-
# ============================================================================
|
| 47 |
-
# smp_forward_backward / smp_forward_only / smp_nested_tensor_size
|
| 48 |
-
# (SageMaker Model Parallel β removed in transformers 5.0)
|
| 49 |
-
# ============================================================================
|
| 50 |
-
try:
|
| 51 |
-
from transformers.trainer import smp_forward_backward
|
| 52 |
-
except ImportError:
|
| 53 |
-
def smp_forward_backward(model, inputs, gradient_accumulation_steps=1):
|
| 54 |
-
raise RuntimeError("SageMaker Model Parallel is not available")
|
| 55 |
-
|
| 56 |
-
try:
|
| 57 |
-
from transformers.trainer import smp_forward_only
|
| 58 |
-
except ImportError:
|
| 59 |
-
def smp_forward_only(model, inputs):
|
| 60 |
-
raise RuntimeError("SageMaker Model Parallel is not available")
|
| 61 |
-
|
| 62 |
-
try:
|
| 63 |
-
from transformers.trainer import smp_nested_tensor_size
|
| 64 |
-
except ImportError:
|
| 65 |
-
def smp_nested_tensor_size(tensor):
|
| 66 |
-
return tensor.size()
|
| 67 |
-
|
| 68 |
-
# ============================================================================
|
| 69 |
-
# deepspeed_init (moved/changed in transformers 5.0)
|
| 70 |
-
# ============================================================================
|
| 71 |
-
try:
|
| 72 |
-
from transformers.integrations import deepspeed_init
|
| 73 |
-
except ImportError:
|
| 74 |
-
try:
|
| 75 |
-
from transformers.deepspeed import deepspeed_init
|
| 76 |
-
except ImportError:
|
| 77 |
-
def deepspeed_init(trainer, num_training_steps, resume_from_checkpoint=None, inference=False):
|
| 78 |
-
raise RuntimeError("DeepSpeed is not available in this transformers version")
|
| 79 |
-
|
| 80 |
-
# ============================================================================
|
| 81 |
-
# deepspeed_load_checkpoint (moved/changed in transformers 5.0)
|
| 82 |
-
# ============================================================================
|
| 83 |
-
try:
|
| 84 |
-
from transformers.integrations import deepspeed_load_checkpoint
|
| 85 |
-
except ImportError:
|
| 86 |
-
try:
|
| 87 |
-
from transformers.deepspeed import deepspeed_load_checkpoint
|
| 88 |
-
except ImportError:
|
| 89 |
-
def deepspeed_load_checkpoint(deepspeed_engine, checkpoint_path):
|
| 90 |
-
raise RuntimeError("DeepSpeed is not available in this transformers version")
|
| 91 |
-
|
| 92 |
-
# ============================================================================
|
| 93 |
-
# HPSearchBackend (removed in transformers 5.0)
|
| 94 |
-
# ============================================================================
|
| 95 |
-
try:
|
| 96 |
-
from transformers.trainer import HPSearchBackend
|
| 97 |
-
except ImportError:
|
| 98 |
-
try:
|
| 99 |
-
from transformers.trainer_utils import HPSearchBackend
|
| 100 |
-
except ImportError:
|
| 101 |
-
class HPSearchBackend(str, Enum):
|
| 102 |
-
OPTUNA = "optuna"
|
| 103 |
-
RAY = "ray"
|
| 104 |
-
SIGOPT = "sigopt"
|
| 105 |
-
WANDB = "wandb"
|
| 106 |
-
|
| 107 |
-
# ============================================================================
|
| 108 |
-
# is_apex_available (removed in transformers 5.0)
|
| 109 |
-
# ============================================================================
|
| 110 |
-
try:
|
| 111 |
-
from transformers.utils import is_apex_available
|
| 112 |
-
except ImportError:
|
| 113 |
-
def is_apex_available():
|
| 114 |
-
return False
|
| 115 |
-
|
| 116 |
-
# ============================================================================
|
| 117 |
-
# ALL_LAYERNORM_LAYERS (removed from transformers.trainer in 5.0)
|
| 118 |
-
# ============================================================================
|
| 119 |
-
try:
|
| 120 |
-
from transformers.trainer import ALL_LAYERNORM_LAYERS
|
| 121 |
-
except ImportError:
|
| 122 |
-
try:
|
| 123 |
-
from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS
|
| 124 |
-
except ImportError:
|
| 125 |
-
import torch.nn as _nn
|
| 126 |
-
ALL_LAYERNORM_LAYERS = [_nn.LayerNorm]
|
| 127 |
-
|
| 128 |
-
# ============================================================================
|
| 129 |
-
# IS_SAGEMAKER_MP_POST_1_10 (SageMaker detection constant β removed in transformers 5.0)
|
| 130 |
-
# ============================================================================
|
| 131 |
-
try:
|
| 132 |
-
from transformers.trainer import IS_SAGEMAKER_MP_POST_1_10
|
| 133 |
-
except ImportError:
|
| 134 |
-
IS_SAGEMAKER_MP_POST_1_10 = False
|
| 135 |
-
|
| 136 |
-
# ============================================================================
|
| 137 |
-
# is_torch_tpu_available (removed in transformers 5.0, replaced by is_torch_xla_available)
|
| 138 |
-
# ============================================================================
|
| 139 |
-
try:
|
| 140 |
-
from transformers.utils import is_torch_tpu_available
|
| 141 |
-
except ImportError:
|
| 142 |
-
try:
|
| 143 |
-
from transformers.utils import is_torch_xla_available as is_torch_tpu_available
|
| 144 |
-
except ImportError:
|
| 145 |
-
def is_torch_tpu_available(check_device=True):
|
| 146 |
-
return False
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
def patch_trainer_compat(trainer):
|
| 150 |
-
"""
|
| 151 |
-
Patch a Trainer instance with deprecated attributes that were removed
|
| 152 |
-
in transformers 5.0. Call this in __init__ after super().__init__().
|
| 153 |
-
|
| 154 |
-
Sets safe defaults for all deprecated attributes:
|
| 155 |
-
- sharded_ddp = None (FSDP replaces this)
|
| 156 |
-
- use_apex = False
|
| 157 |
-
- do_grad_scaling = False
|
| 158 |
-
- scaler = None
|
| 159 |
-
- deepspeed = None (the engine reference)
|
| 160 |
-
- current_flos = 0
|
| 161 |
-
- hp_name = None
|
| 162 |
-
- hp_search_backend = None
|
| 163 |
-
- is_in_train = False
|
| 164 |
-
"""
|
| 165 |
-
if not hasattr(trainer, 'sharded_ddp'):
|
| 166 |
-
trainer.sharded_ddp = None
|
| 167 |
-
if not hasattr(trainer, 'fsdp'):
|
| 168 |
-
trainer.fsdp = None
|
| 169 |
-
if not hasattr(trainer, 'use_apex'):
|
| 170 |
-
trainer.use_apex = False
|
| 171 |
-
if not hasattr(trainer, 'do_grad_scaling'):
|
| 172 |
-
trainer.do_grad_scaling = False
|
| 173 |
-
if not hasattr(trainer, 'scaler'):
|
| 174 |
-
trainer.scaler = None
|
| 175 |
-
if not hasattr(trainer, 'deepspeed'):
|
| 176 |
-
trainer.deepspeed = None
|
| 177 |
-
if not hasattr(trainer, 'current_flos'):
|
| 178 |
-
trainer.current_flos = 0
|
| 179 |
-
if not hasattr(trainer, 'hp_name'):
|
| 180 |
-
trainer.hp_name = None
|
| 181 |
-
if not hasattr(trainer, 'hp_search_backend'):
|
| 182 |
-
trainer.hp_search_backend = None
|
| 183 |
-
if not hasattr(trainer, 'is_in_train'):
|
| 184 |
-
trainer.is_in_train = False
|
| 185 |
-
if not hasattr(trainer, 'is_deepspeed_enabled'):
|
| 186 |
-
trainer.is_deepspeed_enabled = False
|
| 187 |
-
if not hasattr(trainer, '_trial'):
|
| 188 |
-
trainer._trial = None
|
| 189 |
-
if not hasattr(trainer, 'model_wrapped'):
|
| 190 |
-
trainer.model_wrapped = getattr(trainer, 'model', None)
|
| 191 |
-
|
| 192 |
-
def patch_args_compat(args):
|
| 193 |
-
"""
|
| 194 |
-
Patch a TrainingArguments instance with deprecated attributes that were removed
|
| 195 |
-
in transformers 5.0. Call this in Trainer.__init__ to ensure args has all needed fields.
|
| 196 |
-
|
| 197 |
-
- past_index: -1 (default, no cached predictions)
|
| 198 |
-
"""
|
| 199 |
-
if not hasattr(args, 'past_index'):
|
| 200 |
-
args.past_index = -1
|
| 201 |
-
|
| 202 |
-
# GainLoRA has parameters (prompt_key, previous_prompts_keys, vmf_signatures)
|
| 203 |
-
# not used in every forward pass. Transformers 5.0 sets find_unused_parameters=False
|
| 204 |
-
# when gradient_checkpointing=True, which causes DDP reduction errors.
|
| 205 |
-
if getattr(args, 'ddp_find_unused_parameters', None) is None:
|
| 206 |
-
args.ddp_find_unused_parameters = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/compute_ap_ft.py
DELETED
|
@@ -1,242 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
compute_ap_ft.py β Compute AP and FT from training output directories
|
| 4 |
-
======================================================================
|
| 5 |
-
Usage:
|
| 6 |
-
python compute_ap_ft.py \\
|
| 7 |
-
--output_base logs_and_outputs/ot_sign_order1/outputs \\
|
| 8 |
-
--task_order "task1572_samsum_summary,task363_sst2_polarity_classification,..." \\
|
| 9 |
-
--method_name "OT-SIGN+GainLoRA(InfLoRA)"
|
| 10 |
-
|
| 11 |
-
AP = (1/T) * Ξ£_j R[T-1][j] β avg score on ALL tasks after training last task
|
| 12 |
-
FT = (1/(T-1)) * Ξ£_j (R[j][j] - R[T-1][j]) β avg performance DROP from peak
|
| 13 |
-
|
| 14 |
-
Result matrix R[i][j]:
|
| 15 |
-
R[i][j] = score on task j right after model was trained on task i
|
| 16 |
-
Diagonal R[i][i] = peak performance on task i
|
| 17 |
-
Last row R[T-1][j] = final performance (what we report as AP)
|
| 18 |
-
|
| 19 |
-
Score file locations (HuggingFace Trainer):
|
| 20 |
-
{output_base}/{i+1}-{task_name}/predict_results.json β has all task scores
|
| 21 |
-
{output_base}/{i+1}-{task_name}/eval_results.json β used as fallback peak
|
| 22 |
-
"""
|
| 23 |
-
|
| 24 |
-
import argparse
|
| 25 |
-
import json
|
| 26 |
-
import os
|
| 27 |
-
import re
|
| 28 |
-
import sys
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# ββ Metric key detection ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 32 |
-
|
| 33 |
-
def _is_long_benchmark(task_list):
|
| 34 |
-
long_tasks = {'yelp', 'amazon', 'mnli', 'imdb', 'sst2', 'dbpedia', 'agnews',
|
| 35 |
-
'yahoo', 'multirc', 'boolq', 'wic', 'copa', 'qqp', 'rte', 'cb'}
|
| 36 |
-
return any(t.lower() in long_tasks for t in task_list)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def _get_score(metrics, task_name, is_long):
|
| 40 |
-
"""Extract score for `task_name` from a metrics dict."""
|
| 41 |
-
prefix = "exact_match" if is_long else "rougeL"
|
| 42 |
-
candidates = [
|
| 43 |
-
f"predict_{prefix}_for_{task_name}",
|
| 44 |
-
f"eval_{prefix}_for_{task_name}",
|
| 45 |
-
f"predict_{prefix}",
|
| 46 |
-
f"eval_{prefix}",
|
| 47 |
-
]
|
| 48 |
-
for key in candidates:
|
| 49 |
-
if key in metrics:
|
| 50 |
-
v = float(metrics[key])
|
| 51 |
-
# rougeL from compute_metrics is 0-1 scale β convert to %
|
| 52 |
-
if v <= 1.0 and "rouge" in key.lower():
|
| 53 |
-
v = v * 100.0
|
| 54 |
-
return round(v, 2)
|
| 55 |
-
|
| 56 |
-
# broad fallback: any key mentioning the task name
|
| 57 |
-
for k, v in metrics.items():
|
| 58 |
-
if task_name in k and isinstance(v, (int, float)):
|
| 59 |
-
v = float(v)
|
| 60 |
-
if v <= 1.0 and "rouge" in k.lower():
|
| 61 |
-
v = v * 100.0
|
| 62 |
-
return round(v, 2)
|
| 63 |
-
return None
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
def _load_json_file(path):
|
| 67 |
-
if not os.path.exists(path):
|
| 68 |
-
return {}
|
| 69 |
-
with open(path) as f:
|
| 70 |
-
return json.load(f)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
# ββ Result matrix builder ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 74 |
-
|
| 75 |
-
def build_result_matrix(output_base, task_order, is_long):
|
| 76 |
-
"""
|
| 77 |
-
R[i][j] = score on task j after training on task i.
|
| 78 |
-
R[i][i] = peak performance on task i (from predict_results when trained on i).
|
| 79 |
-
"""
|
| 80 |
-
T = len(task_order)
|
| 81 |
-
R = {}
|
| 82 |
-
|
| 83 |
-
for i, task_i in enumerate(task_order):
|
| 84 |
-
# Find output directory for this task (numbered 1-based)
|
| 85 |
-
task_dir = _find_task_dir(output_base, i + 1, task_i)
|
| 86 |
-
if task_dir is None:
|
| 87 |
-
print(f" [WARN] Directory for task {i+1} ({task_i}) not found β skipping", file=sys.stderr)
|
| 88 |
-
continue
|
| 89 |
-
|
| 90 |
-
predict_file = os.path.join(task_dir, "predict_results.json")
|
| 91 |
-
metrics = _load_json_file(predict_file)
|
| 92 |
-
|
| 93 |
-
if not metrics:
|
| 94 |
-
# Try eval_results.json as fallback
|
| 95 |
-
metrics = _load_json_file(os.path.join(task_dir, "eval_results.json"))
|
| 96 |
-
|
| 97 |
-
if not metrics:
|
| 98 |
-
print(f" [WARN] No metrics found in {task_dir}", file=sys.stderr)
|
| 99 |
-
continue
|
| 100 |
-
|
| 101 |
-
R[i] = {}
|
| 102 |
-
# Extract score for EACH task visible at this training step (tasks 0..i)
|
| 103 |
-
for j in range(i + 1):
|
| 104 |
-
score = _get_score(metrics, task_order[j], is_long)
|
| 105 |
-
if score is not None:
|
| 106 |
-
R[i][j] = score
|
| 107 |
-
|
| 108 |
-
return R
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
def _find_task_dir(output_base, task_num, task_name):
|
| 112 |
-
"""Locate task output dir robustly: tries exact match, then prefix match."""
|
| 113 |
-
# Try exact name: "1-task1572_samsum_summary"
|
| 114 |
-
candidate = os.path.join(output_base, f"{task_num}-{task_name}")
|
| 115 |
-
if os.path.isdir(candidate):
|
| 116 |
-
return candidate
|
| 117 |
-
|
| 118 |
-
# Try prefix match
|
| 119 |
-
if os.path.isdir(output_base):
|
| 120 |
-
prefix = f"{task_num}-"
|
| 121 |
-
matches = [d for d in os.listdir(output_base)
|
| 122 |
-
if d.startswith(prefix) and os.path.isdir(os.path.join(output_base, d))]
|
| 123 |
-
if matches:
|
| 124 |
-
return os.path.join(output_base, sorted(matches)[0])
|
| 125 |
-
return None
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
# ββ AP / FT computation βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 129 |
-
|
| 130 |
-
def compute_ap_ft(R, task_order):
|
| 131 |
-
"""
|
| 132 |
-
Args:
|
| 133 |
-
R: dict {i: {j: score}} β result matrix
|
| 134 |
-
task_order: list of task names
|
| 135 |
-
Returns:
|
| 136 |
-
ap, ft as floats (already rounded to 2 dp)
|
| 137 |
-
"""
|
| 138 |
-
T = len(task_order)
|
| 139 |
-
final_row = T - 1
|
| 140 |
-
|
| 141 |
-
# AP: average over final row
|
| 142 |
-
final_scores = [R.get(final_row, {}).get(j) for j in range(T)]
|
| 143 |
-
valid_final = [s for s in final_scores if s is not None]
|
| 144 |
-
ap = round(sum(valid_final) / len(valid_final), 2) if valid_final else 0.0
|
| 145 |
-
|
| 146 |
-
# FT: mean drop from diagonal to final row (exclude last task by convention)
|
| 147 |
-
drops = []
|
| 148 |
-
for j in range(T - 1):
|
| 149 |
-
diag = R.get(j, {}).get(j)
|
| 150 |
-
final = R.get(final_row, {}).get(j)
|
| 151 |
-
if diag is not None and final is not None:
|
| 152 |
-
drops.append(diag - final)
|
| 153 |
-
ft = round(sum(drops) / len(drops), 2) if drops else 0.0
|
| 154 |
-
|
| 155 |
-
return ap, ft
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
# ββ Output formatter ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 159 |
-
|
| 160 |
-
def print_comparison_table(R, task_order, method_name, ap, ft):
|
| 161 |
-
T = len(task_order)
|
| 162 |
-
final_row = T - 1
|
| 163 |
-
sep = "β" * 72
|
| 164 |
-
|
| 165 |
-
print(f"\n{'β' * 72}")
|
| 166 |
-
print(f" {method_name}")
|
| 167 |
-
print(f"{'β' * 72}")
|
| 168 |
-
print(f" {'#':<3} {'Task':<46} {'Peak':>6} {'Final':>6} {'Drop':>6}")
|
| 169 |
-
print(sep)
|
| 170 |
-
|
| 171 |
-
for j, tname in enumerate(task_order):
|
| 172 |
-
diag = R.get(j, {}).get(j)
|
| 173 |
-
final = R.get(final_row, {}).get(j)
|
| 174 |
-
drop = round(diag - final, 2) if diag is not None and final is not None else None
|
| 175 |
-
d_str = f"{diag:.2f}" if diag is not None else " ββ"
|
| 176 |
-
f_str = f"{final:.2f}" if final is not None else " ββ"
|
| 177 |
-
r_str = f"{drop:.2f}" if drop is not None else " ββ"
|
| 178 |
-
print(f" {j+1:<3} {tname:<46} {d_str:>6} {f_str:>6} {r_str:>6}")
|
| 179 |
-
|
| 180 |
-
print(sep)
|
| 181 |
-
print(f" AP = {ap:>6.2f} β FT = {ft:>5.2f}")
|
| 182 |
-
print(f"{'β' * 72}\n")
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
def save_results_json(R, task_order, method_name, ap, ft, output_base):
|
| 186 |
-
out = {
|
| 187 |
-
"method": method_name,
|
| 188 |
-
"ap": ap,
|
| 189 |
-
"ft": ft,
|
| 190 |
-
"per_task": {}
|
| 191 |
-
}
|
| 192 |
-
T = len(task_order)
|
| 193 |
-
final_row = T - 1
|
| 194 |
-
for j, tname in enumerate(task_order):
|
| 195 |
-
out["per_task"][tname] = {
|
| 196 |
-
"peak": R.get(j, {}).get(j),
|
| 197 |
-
"final": R.get(final_row, {}).get(j),
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
result_path = os.path.join(output_base, "..", "ap_ft_result.json")
|
| 201 |
-
result_path = os.path.normpath(result_path)
|
| 202 |
-
with open(result_path, 'w') as f:
|
| 203 |
-
json.dump(out, f, indent=2)
|
| 204 |
-
print(f"[compute_ap_ft] Saved results to {result_path}")
|
| 205 |
-
return result_path
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
# ββ Main βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 209 |
-
|
| 210 |
-
def main():
|
| 211 |
-
parser = argparse.ArgumentParser(description="Compute AP/FT from GainLoRA output directories")
|
| 212 |
-
parser.add_argument("--output_base", required=True,
|
| 213 |
-
help="Path to the outputs/ directory containing task subdirectories")
|
| 214 |
-
parser.add_argument("--task_order", required=True,
|
| 215 |
-
help="Comma-separated list of task names in training order")
|
| 216 |
-
parser.add_argument("--method_name", default="OT-SIGN+GainLoRA",
|
| 217 |
-
help="Label shown in the result table")
|
| 218 |
-
parser.add_argument("--save", action="store_true",
|
| 219 |
-
help="Also save results to ap_ft_result.json")
|
| 220 |
-
args = parser.parse_args()
|
| 221 |
-
|
| 222 |
-
task_order = [t.strip() for t in args.task_order.split(',') if t.strip()]
|
| 223 |
-
is_long = _is_long_benchmark(task_order)
|
| 224 |
-
|
| 225 |
-
print(f"[compute_ap_ft] Benchmark type: {'long' if is_long else 'superni'}")
|
| 226 |
-
print(f"[compute_ap_ft] Tasks: {len(task_order)} | Output base: {args.output_base}")
|
| 227 |
-
|
| 228 |
-
R = build_result_matrix(args.output_base, task_order, is_long)
|
| 229 |
-
|
| 230 |
-
if not R:
|
| 231 |
-
print("[compute_ap_ft] ERROR: No results found. Check --output_base path.", file=sys.stderr)
|
| 232 |
-
sys.exit(1)
|
| 233 |
-
|
| 234 |
-
ap, ft = compute_ap_ft(R, task_order)
|
| 235 |
-
print_comparison_table(R, task_order, args.method_name, ap, ft)
|
| 236 |
-
|
| 237 |
-
if args.save:
|
| 238 |
-
save_results_json(R, task_order, args.method_name, ap, ft, args.output_base)
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
if __name__ == "__main__":
|
| 242 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/ot_sign_utils.py
DELETED
|
@@ -1,289 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
OT-SIGN: Statistical Signatures + Optimal Transport Routing for GainLoRA
|
| 3 |
-
=========================================================================
|
| 4 |
-
Utility functions for:
|
| 5 |
-
1. vMF (von Mises-Fisher) knowledge signatures
|
| 6 |
-
2. Sinkhorn OT routing with vMF log-likelihood cost
|
| 7 |
-
3. Anti-drift and anti-invasion losses
|
| 8 |
-
|
| 9 |
-
Author: OT-SIGN implementation for GainLoRA continual learning
|
| 10 |
-
"""
|
| 11 |
-
|
| 12 |
-
import torch
|
| 13 |
-
import torch.nn as nn
|
| 14 |
-
import torch.nn.functional as F
|
| 15 |
-
import math
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# ============================================================================
|
| 19 |
-
# 1. Sinkhorn Optimal Transport (log-domain for numerical stability)
|
| 20 |
-
# ============================================================================
|
| 21 |
-
|
| 22 |
-
def sinkhorn_log(C, epsilon=0.05, n_iter=10):
|
| 23 |
-
"""
|
| 24 |
-
Log-domain Sinkhorn algorithm for entropic OT.
|
| 25 |
-
|
| 26 |
-
Args:
|
| 27 |
-
C: Cost matrix of shape (B, N) β cost of assigning sample b to expert n
|
| 28 |
-
epsilon: Entropic regularization strength (lower = sharper assignment)
|
| 29 |
-
n_iter: Number of Sinkhorn iterations
|
| 30 |
-
|
| 31 |
-
Returns:
|
| 32 |
-
Transport plan of shape (B, N), rows sum to ~1
|
| 33 |
-
"""
|
| 34 |
-
B, N = C.shape
|
| 35 |
-
|
| 36 |
-
# Log kernel: K = exp(-C / epsilon)
|
| 37 |
-
log_K = -C / epsilon # (B, N)
|
| 38 |
-
|
| 39 |
-
# Initialize dual variables
|
| 40 |
-
u = torch.zeros(B, device=C.device, dtype=C.dtype)
|
| 41 |
-
v = torch.zeros(N, device=C.device, dtype=C.dtype)
|
| 42 |
-
|
| 43 |
-
for _ in range(n_iter):
|
| 44 |
-
# Update u (row normalization in log domain)
|
| 45 |
-
u = -torch.logsumexp(log_K + v.unsqueeze(0), dim=1) # (B,)
|
| 46 |
-
# Update v (column normalization in log domain)
|
| 47 |
-
v = -torch.logsumexp(log_K + u.unsqueeze(1), dim=0) # (N,)
|
| 48 |
-
|
| 49 |
-
# Compute transport plan
|
| 50 |
-
log_pi = log_K + u.unsqueeze(1) + v.unsqueeze(0) # (B, N)
|
| 51 |
-
pi = log_pi.exp()
|
| 52 |
-
|
| 53 |
-
# Normalize rows to sum to 1 (for routing weights)
|
| 54 |
-
pi = pi / (pi.sum(dim=1, keepdim=True) + 1e-8)
|
| 55 |
-
|
| 56 |
-
return pi # (B, N)
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# ============================================================================
|
| 60 |
-
# 2. vMF Parameter Estimation (MLE)
|
| 61 |
-
# ============================================================================
|
| 62 |
-
|
| 63 |
-
def compute_vmf_params(features, d_model, kappa_min=0.1, kappa_max=50.0):
|
| 64 |
-
"""
|
| 65 |
-
Compute vMF MLE parameters from features on unit sphere.
|
| 66 |
-
|
| 67 |
-
Args:
|
| 68 |
-
features: Tensor of shape (num_samples, d) β L2-normalized features
|
| 69 |
-
d_model: Feature dimension
|
| 70 |
-
kappa_min: Minimum allowed kappa (prevents numerical issues)
|
| 71 |
-
kappa_max: Maximum allowed kappa (prevents overflow)
|
| 72 |
-
|
| 73 |
-
Returns:
|
| 74 |
-
mu: Mean direction (d,) β unit vector
|
| 75 |
-
kappa: Concentration parameter β scalar tensor
|
| 76 |
-
"""
|
| 77 |
-
# Mean resultant vector
|
| 78 |
-
x_bar = features.mean(dim=0) # (d,)
|
| 79 |
-
r_bar = x_bar.norm() # scalar β mean resultant length
|
| 80 |
-
|
| 81 |
-
# Mean direction
|
| 82 |
-
mu = F.normalize(x_bar, dim=0) # (d,)
|
| 83 |
-
|
| 84 |
-
# Concentration parameter (Banerjee et al. 2005 approximation)
|
| 85 |
-
d = d_model
|
| 86 |
-
r_bar_clamped = r_bar.clamp(min=1e-6, max=1.0 - 1e-6)
|
| 87 |
-
kappa = r_bar_clamped * (d - r_bar_clamped ** 2) / (1 - r_bar_clamped ** 2)
|
| 88 |
-
|
| 89 |
-
# Clamp kappa for numerical stability
|
| 90 |
-
kappa = kappa.clamp(min=kappa_min, max=kappa_max)
|
| 91 |
-
|
| 92 |
-
return mu.detach(), kappa.detach()
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
# ============================================================================
|
| 96 |
-
# 3. Cost Matrix Construction
|
| 97 |
-
# ============================================================================
|
| 98 |
-
|
| 99 |
-
def vmf_cost_matrix(x, vmf_signatures, prompt_key=None, default_kappa=10.0):
|
| 100 |
-
"""
|
| 101 |
-
Build OT cost matrix from vMF signatures.
|
| 102 |
-
|
| 103 |
-
ORDERING: Current task FIRST, then previous tasks sorted by task_id.
|
| 104 |
-
This matches GainLoRA's agg_lora_states ordering:
|
| 105 |
-
concat_q = cat([cur_lora, prev_lora_0, prev_lora_1, ...])
|
| 106 |
-
|
| 107 |
-
For current task: C[b, 0] = -default_kappa * (prompt_key Β· x_b)
|
| 108 |
-
For previous tasks: C[b, t+1] = -kappa_t * (mu_t Β· x_b)
|
| 109 |
-
|
| 110 |
-
Args:
|
| 111 |
-
x: Normalized input features (B, d)
|
| 112 |
-
vmf_signatures: Dict {task_id: (mu, kappa)} for previous tasks
|
| 113 |
-
prompt_key: Current task's prompt key (1, d) or None
|
| 114 |
-
default_kappa: Kappa value used for the current task's proxy
|
| 115 |
-
|
| 116 |
-
Returns:
|
| 117 |
-
C: Cost matrix (B, N_total) where N_total = 1 + len(signatures)
|
| 118 |
-
Position 0 = current task, positions 1..N-1 = prev tasks in order
|
| 119 |
-
"""
|
| 120 |
-
device = x.device
|
| 121 |
-
dtype = x.dtype
|
| 122 |
-
costs = []
|
| 123 |
-
|
| 124 |
-
# Position 0: Cost for current task (using prompt_key as proxy direction)
|
| 125 |
-
if prompt_key is not None:
|
| 126 |
-
pk = prompt_key.squeeze() # (d,)
|
| 127 |
-
pk = F.normalize(pk, dim=-1)
|
| 128 |
-
dot_product = (x * pk.unsqueeze(0)).sum(dim=-1) # (B,)
|
| 129 |
-
default_kappa_t = torch.tensor(default_kappa, device=device, dtype=dtype)
|
| 130 |
-
cost_cur = -default_kappa_t * dot_product # (B,)
|
| 131 |
-
costs.append(cost_cur)
|
| 132 |
-
|
| 133 |
-
# Positions 1..N: Cost from vMF signatures (previous tasks) β sorted by task_id
|
| 134 |
-
for task_id in sorted(vmf_signatures.keys()):
|
| 135 |
-
mu_t, kappa_t = vmf_signatures[task_id]
|
| 136 |
-
mu_t = mu_t.to(device=device, dtype=dtype)
|
| 137 |
-
kappa_t_val = kappa_t.to(device=device, dtype=dtype) if isinstance(kappa_t, torch.Tensor) else torch.tensor(kappa_t, device=device, dtype=dtype)
|
| 138 |
-
|
| 139 |
-
# vMF negative log-likelihood (ignoring constant normalization)
|
| 140 |
-
dot_product = (x * mu_t.unsqueeze(0)).sum(dim=-1) # (B,)
|
| 141 |
-
cost_t = -kappa_t_val * dot_product # (B,) β lower cost = higher likelihood
|
| 142 |
-
costs.append(cost_t)
|
| 143 |
-
|
| 144 |
-
if len(costs) == 0:
|
| 145 |
-
raise ValueError("No signatures or prompt_key provided for cost matrix")
|
| 146 |
-
|
| 147 |
-
C = torch.stack(costs, dim=1) # (B, N_total)
|
| 148 |
-
return C
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
# ============================================================================
|
| 152 |
-
# 4. Anti-Drift Loss
|
| 153 |
-
# ============================================================================
|
| 154 |
-
|
| 155 |
-
def compute_anti_drift_loss(model_encoder, ref_trans_input_state, input_ids, attention_mask):
|
| 156 |
-
"""
|
| 157 |
-
MSE between current and reference trans_input outputs on replay data.
|
| 158 |
-
Protects the shared MLP from drifting away from old task representations.
|
| 159 |
-
|
| 160 |
-
Args:
|
| 161 |
-
model_encoder: The model's encoder (has embed_tokens, trans_input)
|
| 162 |
-
ref_trans_input_state: Frozen state dict of trans_input from previous task
|
| 163 |
-
input_ids: Replay input token IDs (B, seq_len)
|
| 164 |
-
attention_mask: Replay attention mask (B, seq_len)
|
| 165 |
-
|
| 166 |
-
Returns:
|
| 167 |
-
drift_loss: Scalar MSE loss
|
| 168 |
-
"""
|
| 169 |
-
# Get current trans_input output
|
| 170 |
-
with torch.no_grad():
|
| 171 |
-
embeddings = model_encoder.embed_tokens(input_ids)
|
| 172 |
-
avg_emb = (attention_mask.unsqueeze(-1) * embeddings).mean(dim=1, keepdim=True) # (B, 1, d)
|
| 173 |
-
|
| 174 |
-
# Current trans_input output
|
| 175 |
-
medium_curr = model_encoder.trans_input[1](model_encoder.trans_input[0](avg_emb))
|
| 176 |
-
x_curr = model_encoder.trans_input[3](model_encoder.trans_input[2](medium_curr))
|
| 177 |
-
x_curr = F.normalize(x_curr, dim=-1) # (B, 1, d)
|
| 178 |
-
|
| 179 |
-
# Reference trans_input output (frozen copy)
|
| 180 |
-
ref_trans_input = nn.Sequential(
|
| 181 |
-
nn.Linear(model_encoder.trans_input[0].in_features, model_encoder.trans_input[0].out_features, bias=False),
|
| 182 |
-
nn.SiLU(),
|
| 183 |
-
nn.Linear(model_encoder.trans_input[2].in_features, model_encoder.trans_input[2].out_features, bias=False),
|
| 184 |
-
nn.SiLU(),
|
| 185 |
-
).to(device=avg_emb.device, dtype=avg_emb.dtype)
|
| 186 |
-
ref_trans_input.load_state_dict(ref_trans_input_state)
|
| 187 |
-
for p in ref_trans_input.parameters():
|
| 188 |
-
p.requires_grad = False
|
| 189 |
-
|
| 190 |
-
with torch.no_grad():
|
| 191 |
-
medium_ref = ref_trans_input[1](ref_trans_input[0](avg_emb))
|
| 192 |
-
x_ref = ref_trans_input[3](ref_trans_input[2](medium_ref))
|
| 193 |
-
x_ref = F.normalize(x_ref, dim=-1) # (B, 1, d)
|
| 194 |
-
|
| 195 |
-
drift_loss = F.mse_loss(x_curr, x_ref)
|
| 196 |
-
return drift_loss
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
class CachedRefTransInput(nn.Module):
|
| 200 |
-
"""
|
| 201 |
-
Cached frozen copy of trans_input for efficient anti-drift computation.
|
| 202 |
-
Avoids recreating nn.Sequential every step.
|
| 203 |
-
"""
|
| 204 |
-
def __init__(self, trans_input_module):
|
| 205 |
-
super().__init__()
|
| 206 |
-
import copy
|
| 207 |
-
self.ref = copy.deepcopy(trans_input_module)
|
| 208 |
-
for p in self.ref.parameters():
|
| 209 |
-
p.requires_grad = False
|
| 210 |
-
|
| 211 |
-
def forward(self, x):
|
| 212 |
-
with torch.no_grad():
|
| 213 |
-
medium = self.ref[1](self.ref[0](x))
|
| 214 |
-
out = self.ref[3](self.ref[2](medium))
|
| 215 |
-
return F.normalize(out, dim=-1)
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
def compute_anti_drift_loss_cached(model_encoder, ref_trans_input_cached, input_ids, attention_mask):
|
| 219 |
-
"""
|
| 220 |
-
Efficient anti-drift loss using a pre-cached frozen trans_input.
|
| 221 |
-
|
| 222 |
-
Args:
|
| 223 |
-
model_encoder: Model encoder with embed_tokens and trans_input
|
| 224 |
-
ref_trans_input_cached: CachedRefTransInput instance
|
| 225 |
-
input_ids: Replay input IDs (B, seq_len)
|
| 226 |
-
attention_mask: Replay attention mask (B, seq_len)
|
| 227 |
-
|
| 228 |
-
Returns:
|
| 229 |
-
Scalar MSE loss
|
| 230 |
-
"""
|
| 231 |
-
with torch.no_grad():
|
| 232 |
-
embeddings = model_encoder.embed_tokens(input_ids)
|
| 233 |
-
avg_emb = (attention_mask.unsqueeze(-1) * embeddings).mean(dim=1, keepdim=True)
|
| 234 |
-
|
| 235 |
-
# Current trans_input output
|
| 236 |
-
medium_curr = model_encoder.trans_input[1](model_encoder.trans_input[0](avg_emb))
|
| 237 |
-
x_curr = model_encoder.trans_input[3](model_encoder.trans_input[2](medium_curr))
|
| 238 |
-
x_curr = F.normalize(x_curr, dim=-1)
|
| 239 |
-
|
| 240 |
-
# Reference output (frozen)
|
| 241 |
-
x_ref = ref_trans_input_cached(avg_emb)
|
| 242 |
-
|
| 243 |
-
return F.mse_loss(x_curr, x_ref)
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
# ============================================================================
|
| 247 |
-
# 5. Anti-Invasion Loss
|
| 248 |
-
# ============================================================================
|
| 249 |
-
|
| 250 |
-
def compute_anti_invasion_loss(x_normalized, vmf_signatures, current_task_id, threshold=2.3):
|
| 251 |
-
"""
|
| 252 |
-
Hinge loss penalizing current task features that invade old task regions.
|
| 253 |
-
|
| 254 |
-
Args:
|
| 255 |
-
x_normalized: Current task's normalized features (B, d) or (B, 1, d)
|
| 256 |
-
vmf_signatures: Dict {task_id: (mu, kappa)}
|
| 257 |
-
current_task_id: Current task index
|
| 258 |
-
threshold: vMF log-likelihood threshold (default -log(0.1) β 2.3)
|
| 259 |
-
|
| 260 |
-
Returns:
|
| 261 |
-
invasion_loss: Scalar hinge loss
|
| 262 |
-
"""
|
| 263 |
-
if x_normalized.dim() == 3:
|
| 264 |
-
x_normalized = x_normalized.squeeze(1) # (B, d)
|
| 265 |
-
|
| 266 |
-
device = x_normalized.device
|
| 267 |
-
dtype = x_normalized.dtype
|
| 268 |
-
invasion_loss = torch.tensor(0.0, device=device, dtype=dtype)
|
| 269 |
-
n_old_tasks = 0
|
| 270 |
-
|
| 271 |
-
for task_id, (mu_s, kappa_s) in vmf_signatures.items():
|
| 272 |
-
if task_id >= current_task_id:
|
| 273 |
-
continue
|
| 274 |
-
|
| 275 |
-
mu_s = mu_s.to(device=device, dtype=dtype)
|
| 276 |
-
kappa_val = kappa_s.item() if isinstance(kappa_s, torch.Tensor) else kappa_s
|
| 277 |
-
|
| 278 |
-
# Log-likelihood of x_new under vMF(mu_s, kappa_s): kappa_s * (mu_s Β· x_new)
|
| 279 |
-
log_lik = kappa_val * (x_normalized * mu_s.unsqueeze(0)).sum(dim=-1) # (B,)
|
| 280 |
-
|
| 281 |
-
# Hinge: penalize when log_lik > threshold (feature too close to old task)
|
| 282 |
-
violation = F.relu(log_lik - threshold) # (B,)
|
| 283 |
-
invasion_loss = invasion_loss + violation.mean()
|
| 284 |
-
n_old_tasks += 1
|
| 285 |
-
|
| 286 |
-
if n_old_tasks > 0:
|
| 287 |
-
invasion_loss = invasion_loss / n_old_tasks
|
| 288 |
-
|
| 289 |
-
return invasion_loss
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/preflight_check.py
DELETED
|
@@ -1,199 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Fast preflight checks for GainLoRA training compatibility.
|
| 3 |
-
|
| 4 |
-
This script catches common breakages in seconds before launching long runs:
|
| 5 |
-
- Python syntax/import issues in critical source files
|
| 6 |
-
- transformers/accelerate API mismatches
|
| 7 |
-
- Trainer init signature mismatches (processing_class vs tokenizer)
|
| 8 |
-
- Known bad patterns that caused recent runtime failures
|
| 9 |
-
"""
|
| 10 |
-
|
| 11 |
-
import glob
|
| 12 |
-
import importlib
|
| 13 |
-
import inspect
|
| 14 |
-
import os
|
| 15 |
-
import py_compile
|
| 16 |
-
import sys
|
| 17 |
-
from typing import List
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 21 |
-
SRC_DIR = os.path.join(ROOT, "src")
|
| 22 |
-
|
| 23 |
-
CRITICAL_FILES = [
|
| 24 |
-
"run_t5.py",
|
| 25 |
-
"run_llama.py",
|
| 26 |
-
"compat_transformers.py",
|
| 27 |
-
"cl_trainer_gainlora_inflora.py",
|
| 28 |
-
"cl_trainer_gainlora_inflora_llama.py",
|
| 29 |
-
"cl_trainer_gainlora_olora.py",
|
| 30 |
-
"cl_trainer_gainlora_olora_llama.py",
|
| 31 |
-
]
|
| 32 |
-
|
| 33 |
-
GAINLORA_TRAINERS = [
|
| 34 |
-
"cl_trainer_gainlora_inflora.py",
|
| 35 |
-
"cl_trainer_gainlora_inflora_llama.py",
|
| 36 |
-
"cl_trainer_gainlora_olora.py",
|
| 37 |
-
"cl_trainer_gainlora_olora_llama.py",
|
| 38 |
-
]
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def _ok(msg: str) -> None:
|
| 42 |
-
print(f"[OK] {msg}")
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
def _warn(msg: str) -> None:
|
| 46 |
-
print(f"[WARN] {msg}")
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
def _fail(msg: str, failures: List[str]) -> None:
|
| 50 |
-
print(f"[FAIL] {msg}")
|
| 51 |
-
failures.append(msg)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
def check_syntax(failures: List[str]) -> None:
|
| 55 |
-
for rel in CRITICAL_FILES:
|
| 56 |
-
path = os.path.join(SRC_DIR, rel)
|
| 57 |
-
if not os.path.exists(path):
|
| 58 |
-
_fail(f"Missing file: {rel}", failures)
|
| 59 |
-
continue
|
| 60 |
-
try:
|
| 61 |
-
py_compile.compile(path, doraise=True)
|
| 62 |
-
_ok(f"Syntax compile: {rel}")
|
| 63 |
-
except Exception as exc:
|
| 64 |
-
_fail(f"Syntax error in {rel}: {exc}", failures)
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
def check_core_api(failures: List[str]) -> None:
|
| 68 |
-
try:
|
| 69 |
-
import transformers
|
| 70 |
-
from transformers import Trainer
|
| 71 |
-
|
| 72 |
-
sig = inspect.signature(Trainer.__init__)
|
| 73 |
-
params = sig.parameters
|
| 74 |
-
version_str = transformers.__version__
|
| 75 |
-
major = int(version_str.split(".")[0])
|
| 76 |
-
|
| 77 |
-
if major >= 5:
|
| 78 |
-
if "processing_class" not in params:
|
| 79 |
-
_fail("transformers>=5 requires Trainer.__init__.processing_class", failures)
|
| 80 |
-
else:
|
| 81 |
-
_ok("Trainer.__init__ has processing_class (transformers>=5)")
|
| 82 |
-
else:
|
| 83 |
-
if "tokenizer" not in params:
|
| 84 |
-
_fail("transformers<5 expected Trainer.__init__.tokenizer", failures)
|
| 85 |
-
else:
|
| 86 |
-
_ok("Trainer.__init__ has tokenizer (transformers<5)")
|
| 87 |
-
|
| 88 |
-
_ok(f"transformers version: {version_str}")
|
| 89 |
-
except Exception as exc:
|
| 90 |
-
_fail(f"transformers API check failed: {exc}", failures)
|
| 91 |
-
|
| 92 |
-
try:
|
| 93 |
-
import accelerate
|
| 94 |
-
from accelerate import Accelerator
|
| 95 |
-
|
| 96 |
-
clip_sig = inspect.signature(Accelerator.clip_grad_norm_)
|
| 97 |
-
clip_params = set(clip_sig.parameters.keys())
|
| 98 |
-
if "check_grad_overflow" in clip_params:
|
| 99 |
-
_warn("Accelerator.clip_grad_norm_ supports check_grad_overflow")
|
| 100 |
-
else:
|
| 101 |
-
_ok("Accelerator.clip_grad_norm_ does not support check_grad_overflow")
|
| 102 |
-
_ok(f"accelerate version: {accelerate.__version__}")
|
| 103 |
-
except Exception as exc:
|
| 104 |
-
_fail(f"accelerate API check failed: {exc}", failures)
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
def check_text_patterns(failures: List[str]) -> None:
|
| 108 |
-
# Patterns that recently caused failures in this codebase.
|
| 109 |
-
bad_patterns = {
|
| 110 |
-
"check_grad_overflow=": "Unsupported kwarg for accelerate.clip_grad_norm_ in many envs",
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
for rel in GAINLORA_TRAINERS:
|
| 114 |
-
path = os.path.join(SRC_DIR, rel)
|
| 115 |
-
try:
|
| 116 |
-
text = open(path, "r", encoding="utf-8").read()
|
| 117 |
-
except Exception as exc:
|
| 118 |
-
_fail(f"Cannot read {rel}: {exc}", failures)
|
| 119 |
-
continue
|
| 120 |
-
|
| 121 |
-
for pattern, reason in bad_patterns.items():
|
| 122 |
-
if pattern in text:
|
| 123 |
-
_fail(f"{rel} contains '{pattern}' ({reason})", failures)
|
| 124 |
-
|
| 125 |
-
if "self.accelerator.clip_grad_norm_(" in text:
|
| 126 |
-
_fail(
|
| 127 |
-
f"{rel} still uses self.accelerator.clip_grad_norm_ (can trigger double unscale)",
|
| 128 |
-
failures,
|
| 129 |
-
)
|
| 130 |
-
elif "nn.utils.clip_grad_norm_(" in text:
|
| 131 |
-
_ok(f"{rel} uses nn.utils.clip_grad_norm_")
|
| 132 |
-
|
| 133 |
-
# Check Trainer API migration in run scripts.
|
| 134 |
-
for rel in ["run_t5.py", "run_llama.py"]:
|
| 135 |
-
path = os.path.join(SRC_DIR, rel)
|
| 136 |
-
try:
|
| 137 |
-
text = open(path, "r", encoding="utf-8").read()
|
| 138 |
-
except Exception as exc:
|
| 139 |
-
_fail(f"Cannot read {rel}: {exc}", failures)
|
| 140 |
-
continue
|
| 141 |
-
|
| 142 |
-
if "tokenizer=tokenizer" in text:
|
| 143 |
-
_fail(f"{rel} still contains tokenizer=tokenizer (should be processing_class=tokenizer)", failures)
|
| 144 |
-
if "processing_class=tokenizer" in text:
|
| 145 |
-
_ok(f"{rel} uses processing_class=tokenizer")
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
def check_custom_trainer_signatures(failures: List[str]) -> None:
|
| 149 |
-
sys.path.insert(0, SRC_DIR)
|
| 150 |
-
trainer_mods = sorted(glob.glob(os.path.join(SRC_DIR, "cl_trainer_*.py")))
|
| 151 |
-
|
| 152 |
-
for mod_path in trainer_mods:
|
| 153 |
-
mod_name = os.path.splitext(os.path.basename(mod_path))[0]
|
| 154 |
-
try:
|
| 155 |
-
mod = importlib.import_module(mod_name)
|
| 156 |
-
except Exception as exc:
|
| 157 |
-
_fail(f"Import failed for {mod_name}: {exc}", failures)
|
| 158 |
-
continue
|
| 159 |
-
|
| 160 |
-
for _, obj in inspect.getmembers(mod, inspect.isclass):
|
| 161 |
-
if obj.__module__ != mod_name:
|
| 162 |
-
continue
|
| 163 |
-
if not hasattr(obj, "__mro__"):
|
| 164 |
-
continue
|
| 165 |
-
if not any(base.__name__ == "Seq2SeqTrainer" for base in obj.__mro__):
|
| 166 |
-
continue
|
| 167 |
-
|
| 168 |
-
init_sig = inspect.signature(obj.__init__)
|
| 169 |
-
params = init_sig.parameters
|
| 170 |
-
if "processing_class" not in params:
|
| 171 |
-
_fail(f"{mod_name}.{obj.__name__}.__init__ missing processing_class", failures)
|
| 172 |
-
elif "tokenizer" in params:
|
| 173 |
-
_fail(f"{mod_name}.{obj.__name__}.__init__ still has tokenizer", failures)
|
| 174 |
-
else:
|
| 175 |
-
_ok(f"{mod_name}.{obj.__name__}.__init__ signature is compatible")
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
def main() -> int:
|
| 179 |
-
failures: List[str] = []
|
| 180 |
-
|
| 181 |
-
print("== GainLoRA Preflight Check ==")
|
| 182 |
-
print(f"Root: {ROOT}")
|
| 183 |
-
|
| 184 |
-
check_syntax(failures)
|
| 185 |
-
check_core_api(failures)
|
| 186 |
-
check_text_patterns(failures)
|
| 187 |
-
check_custom_trainer_signatures(failures)
|
| 188 |
-
|
| 189 |
-
print("\n== Result ==")
|
| 190 |
-
if failures:
|
| 191 |
-
print(f"FAILED with {len(failures)} issue(s)")
|
| 192 |
-
return 1
|
| 193 |
-
|
| 194 |
-
print("PASS: no blocking issues found")
|
| 195 |
-
return 0
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
if __name__ == "__main__":
|
| 199 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/run_logger.py
DELETED
|
@@ -1,229 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
OT-SIGN Run Logger
|
| 3 |
-
==================
|
| 4 |
-
Logs each training run with config, vMF signatures, and per-task scores.
|
| 5 |
-
Computes AP (Average Performance) and FT (Forgetting) directly comparable
|
| 6 |
-
to GainLoRA paper Table 1 / Table 2.
|
| 7 |
-
|
| 8 |
-
Output files:
|
| 9 |
-
run_log.jsonl β machine-readable full log
|
| 10 |
-
scores_matrix.json β R[i][j] = score of task j after training task i
|
| 11 |
-
ap_ft_summary.md β final AP/FT table ready for paper comparison
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
import json
|
| 15 |
-
import os
|
| 16 |
-
from datetime import datetime
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Keys used for score extraction from HuggingFace Trainer metrics
|
| 20 |
-
SCORE_KEY_TEMPLATES = {
|
| 21 |
-
"superni": ["predict_rougeL_for_{task}", "eval_rougeL_for_{task}", "predict_rougeL"],
|
| 22 |
-
"long": ["predict_exact_match_for_{task}", "eval_exact_match_for_{task}", "predict_exact_match"],
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
def _extract_score(metrics_dict, task_name, benchmark_type="superni"):
|
| 27 |
-
"""Extract the primary score for a given task from a metrics dict."""
|
| 28 |
-
templates = SCORE_KEY_TEMPLATES.get(benchmark_type, SCORE_KEY_TEMPLATES["superni"])
|
| 29 |
-
for tmpl in templates:
|
| 30 |
-
key = tmpl.format(task=task_name)
|
| 31 |
-
if key in metrics_dict:
|
| 32 |
-
v = metrics_dict[key]
|
| 33 |
-
# rougeL is typically 0β1 from compute_metrics; multiply to get percentage
|
| 34 |
-
if v <= 1.0 and "rouge" in key.lower():
|
| 35 |
-
v = v * 100.0
|
| 36 |
-
return round(v, 2)
|
| 37 |
-
# fallback: look for any key containing the task name
|
| 38 |
-
for k, v in metrics_dict.items():
|
| 39 |
-
if task_name in k and isinstance(v, (int, float)):
|
| 40 |
-
if v <= 1.0 and "rouge" in k.lower():
|
| 41 |
-
v = v * 100.0
|
| 42 |
-
return round(v, 2)
|
| 43 |
-
return None
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
class RunLogger:
|
| 47 |
-
"""
|
| 48 |
-
Logs every task training run and builds the result matrix R[i][j].
|
| 49 |
-
|
| 50 |
-
Result matrix semantics (matching GainLoRA paper Table 1):
|
| 51 |
-
R[i][j] = score on task j after model has been trained on tasks 0..i
|
| 52 |
-
AP = (1/T) * sum_j R[T-1][j] (final row average)
|
| 53 |
-
FT = (1/(T-1)) * sum_j (R[j][j] - R[T-1][j]) (diagonal drop)
|
| 54 |
-
"""
|
| 55 |
-
|
| 56 |
-
def __init__(self, log_dir="logs_and_outputs/ot_sign_logs", benchmark_type="superni"):
|
| 57 |
-
self.log_dir = log_dir
|
| 58 |
-
self.benchmark_type = benchmark_type # "superni" or "long"
|
| 59 |
-
os.makedirs(log_dir, exist_ok=True)
|
| 60 |
-
self.log_file = os.path.join(log_dir, "run_log.jsonl")
|
| 61 |
-
self.matrix_file = os.path.join(log_dir, "scores_matrix.json")
|
| 62 |
-
self.summary_file = os.path.join(log_dir, "ap_ft_summary.md")
|
| 63 |
-
|
| 64 |
-
# In-memory score matrix: {trained_on_task_id: {eval_task_name: score}}
|
| 65 |
-
self._scores = self._load_scores_matrix()
|
| 66 |
-
|
| 67 |
-
# ------------------------------------------------------------------
|
| 68 |
-
# Public API
|
| 69 |
-
# ------------------------------------------------------------------
|
| 70 |
-
|
| 71 |
-
def log_run(self, task_name, task_id, config, vmf_signature=None, metrics=None, extra=None):
|
| 72 |
-
"""Log a single task's training metadata (config, vMF, train metrics)."""
|
| 73 |
-
entry = {
|
| 74 |
-
"timestamp": datetime.now().isoformat(),
|
| 75 |
-
"task_name": task_name,
|
| 76 |
-
"task_id": task_id,
|
| 77 |
-
"config": config,
|
| 78 |
-
"vmf_signature": vmf_signature,
|
| 79 |
-
"metrics": metrics,
|
| 80 |
-
"extra": extra,
|
| 81 |
-
}
|
| 82 |
-
with open(self.log_file, 'a') as f:
|
| 83 |
-
f.write(json.dumps(entry, default=str) + "\n")
|
| 84 |
-
self._update_md_log(entry)
|
| 85 |
-
print(f"[RunLogger] Logged task {task_id}: {task_name}")
|
| 86 |
-
|
| 87 |
-
def log_predict_scores(self, trained_on_task_id, predict_metrics_dict, task_order_list):
|
| 88 |
-
"""
|
| 89 |
-
After training on task `trained_on_task_id`, log prediction scores for all
|
| 90 |
-
tasks evaluated so far.
|
| 91 |
-
|
| 92 |
-
Args:
|
| 93 |
-
trained_on_task_id: index of the just-trained task (0-based)
|
| 94 |
-
predict_metrics_dict: HF Trainer predict_results.metrics
|
| 95 |
-
task_order_list: full list of task names in sequence order
|
| 96 |
-
"""
|
| 97 |
-
row = {}
|
| 98 |
-
for j, tname in enumerate(task_order_list[:trained_on_task_id + 1]):
|
| 99 |
-
score = _extract_score(predict_metrics_dict, tname, self.benchmark_type)
|
| 100 |
-
if score is not None:
|
| 101 |
-
row[tname] = score
|
| 102 |
-
|
| 103 |
-
self._scores[trained_on_task_id] = row
|
| 104 |
-
self._save_scores_matrix()
|
| 105 |
-
|
| 106 |
-
# Print progress table
|
| 107 |
-
self._print_current_scores(trained_on_task_id, task_order_list)
|
| 108 |
-
|
| 109 |
-
def print_ap_ft(self, task_order_list, method_name="OT-SIGN+GainLoRA"):
|
| 110 |
-
"""
|
| 111 |
-
Compute and print AP / FT from the accumulated score matrix.
|
| 112 |
-
Prints a table directly comparable to GainLoRA paper.
|
| 113 |
-
|
| 114 |
-
Returns:
|
| 115 |
-
(ap, ft) as floats
|
| 116 |
-
"""
|
| 117 |
-
T = len(task_order_list)
|
| 118 |
-
if T not in self._scores and (T - 1) not in self._scores:
|
| 119 |
-
print("[RunLogger] Not enough data to compute AP/FT yet.")
|
| 120 |
-
return None, None
|
| 121 |
-
|
| 122 |
-
final_row_id = T - 1
|
| 123 |
-
if final_row_id not in self._scores:
|
| 124 |
-
print("[RunLogger] Final task scores not found.")
|
| 125 |
-
return None, None
|
| 126 |
-
|
| 127 |
-
final_scores = [self._scores[final_row_id].get(t) for t in task_order_list]
|
| 128 |
-
final_scores_valid = [s for s in final_scores if s is not None]
|
| 129 |
-
ap = round(sum(final_scores_valid) / len(final_scores_valid), 2) if final_scores_valid else 0.0
|
| 130 |
-
|
| 131 |
-
# FT = mean of (diagonal - final row), skip first task
|
| 132 |
-
ft_values = []
|
| 133 |
-
for j in range(T - 1):
|
| 134 |
-
tname = task_order_list[j]
|
| 135 |
-
diag = self._scores.get(j, {}).get(tname)
|
| 136 |
-
final = self._scores.get(final_row_id, {}).get(tname)
|
| 137 |
-
if diag is not None and final is not None:
|
| 138 |
-
ft_values.append(diag - final)
|
| 139 |
-
ft = round(sum(ft_values) / len(ft_values), 2) if ft_values else 0.0
|
| 140 |
-
|
| 141 |
-
# ---- Console output ----
|
| 142 |
-
sep = "-" * 60
|
| 143 |
-
print(f"\n{sep}")
|
| 144 |
-
print(f" FINAL RESULTS β {method_name}")
|
| 145 |
-
print(sep)
|
| 146 |
-
print(f" {'Task':<45} {'Peak':>6} {'Final':>6} {'Drop':>6}")
|
| 147 |
-
print(sep)
|
| 148 |
-
for j, tname in enumerate(task_order_list):
|
| 149 |
-
diag = self._scores.get(j, {}).get(tname, "-")
|
| 150 |
-
final = self._scores.get(final_row_id, {}).get(tname, "-")
|
| 151 |
-
drop = f"{diag - final:.2f}" if isinstance(diag, float) and isinstance(final, float) else "-"
|
| 152 |
-
diag_s = f"{diag:.2f}" if isinstance(diag, float) else str(diag)
|
| 153 |
-
final_s = f"{final:.2f}" if isinstance(final, float) else str(final)
|
| 154 |
-
print(f" {tname:<45} {diag_s:>6} {final_s:>6} {drop:>6}")
|
| 155 |
-
print(sep)
|
| 156 |
-
print(f" AP = {ap:.2f} | FT = {ft:.2f}")
|
| 157 |
-
print(f"{sep}\n")
|
| 158 |
-
|
| 159 |
-
# ---- File output ----
|
| 160 |
-
self._write_ap_ft_summary(task_order_list, method_name, ap, ft)
|
| 161 |
-
return ap, ft
|
| 162 |
-
|
| 163 |
-
# ------------------------------------------------------------------
|
| 164 |
-
# Internal helpers
|
| 165 |
-
# ------------------------------------------------------------------
|
| 166 |
-
|
| 167 |
-
def _load_scores_matrix(self):
|
| 168 |
-
if os.path.exists(self.matrix_file):
|
| 169 |
-
with open(self.matrix_file) as f:
|
| 170 |
-
raw = json.load(f)
|
| 171 |
-
return {int(k): v for k, v in raw.items()}
|
| 172 |
-
return {}
|
| 173 |
-
|
| 174 |
-
def _save_scores_matrix(self):
|
| 175 |
-
with open(self.matrix_file, 'w') as f:
|
| 176 |
-
json.dump({str(k): v for k, v in self._scores.items()}, f, indent=2)
|
| 177 |
-
|
| 178 |
-
def _print_current_scores(self, trained_on_task_id, task_order_list):
|
| 179 |
-
row = self._scores.get(trained_on_task_id, {})
|
| 180 |
-
tname = task_order_list[trained_on_task_id] if trained_on_task_id < len(task_order_list) else "?"
|
| 181 |
-
print(f"\n[RunLogger] After task {trained_on_task_id} ({tname}) β predict scores:")
|
| 182 |
-
for t, s in row.items():
|
| 183 |
-
print(f" {t:<50} {s:.2f}")
|
| 184 |
-
|
| 185 |
-
def _update_md_log(self, entry):
|
| 186 |
-
"""Append human-readable training info only (not the score matrix)."""
|
| 187 |
-
with open(self.log_file.replace(".jsonl", "_detail.md"), 'a') as f:
|
| 188 |
-
f.write(f"\n## Task {entry['task_id']}: {entry['task_name']}\n")
|
| 189 |
-
f.write(f"*{entry['timestamp']}*\n\n")
|
| 190 |
-
if entry.get('vmf_signature'):
|
| 191 |
-
f.write(f"- vMF kappa: `{entry['vmf_signature'].get('kappa', '?')}` "
|
| 192 |
-
f"mu_norm: `{entry['vmf_signature'].get('mu_norm', '?')}`\n")
|
| 193 |
-
if entry.get('metrics'):
|
| 194 |
-
f.write("| Metric | Value |\n|--------|-------|\n")
|
| 195 |
-
for k, v in entry['metrics'].items():
|
| 196 |
-
val = f"{v:.4f}" if isinstance(v, float) else str(v)
|
| 197 |
-
f.write(f"| `{k}` | {val} |\n")
|
| 198 |
-
f.write("\n")
|
| 199 |
-
|
| 200 |
-
def _write_ap_ft_summary(self, task_order_list, method_name, ap, ft):
|
| 201 |
-
"""Write a markdown file ready to paste into the comparison table."""
|
| 202 |
-
T = len(task_order_list)
|
| 203 |
-
final_row_id = T - 1
|
| 204 |
-
with open(self.summary_file, 'a') as f:
|
| 205 |
-
f.write(f"\n## {method_name}\n")
|
| 206 |
-
f.write(f"*Generated: {datetime.now().strftime('%Y-%m-%d %H:%M')}*\n\n")
|
| 207 |
-
f.write("| Task | Peak Score (R[i,i]) | Final Score (R[T,i]) | Forgetting |\n")
|
| 208 |
-
f.write("|------|---------------------|----------------------|------------|\n")
|
| 209 |
-
for j, tname in enumerate(task_order_list):
|
| 210 |
-
diag = self._scores.get(j, {}).get(tname, "-")
|
| 211 |
-
final = self._scores.get(final_row_id, {}).get(tname, "-")
|
| 212 |
-
drop = f"{diag - final:.2f}" if isinstance(diag, float) and isinstance(final, float) else "-"
|
| 213 |
-
f.write(f"| {tname} | {diag} | {final} | {drop} |\n")
|
| 214 |
-
f.write(f"\n**AP = {ap:.2f}** | **FT = {ft:.2f}**\n\n")
|
| 215 |
-
|
| 216 |
-
# ---- Legacy compat ----
|
| 217 |
-
def load_all_runs(self):
|
| 218 |
-
runs = []
|
| 219 |
-
if os.path.exists(self.log_file):
|
| 220 |
-
with open(self.log_file) as f:
|
| 221 |
-
for line in f:
|
| 222 |
-
line = line.strip()
|
| 223 |
-
if line:
|
| 224 |
-
runs.append(json.loads(line))
|
| 225 |
-
return runs
|
| 226 |
-
|
| 227 |
-
def get_latest_run(self):
|
| 228 |
-
runs = self.load_all_runs()
|
| 229 |
-
return runs[-1] if runs else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gainlora_OT_vMF/src/test_ot_sign.py
DELETED
|
@@ -1,54 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python
|
| 2 |
-
"""Quick unit test for OT-SIGN components."""
|
| 3 |
-
import torch
|
| 4 |
-
import torch.nn.functional as F
|
| 5 |
-
import sys
|
| 6 |
-
sys.path.insert(0, '.')
|
| 7 |
-
|
| 8 |
-
from ot_sign_utils import sinkhorn_log, vmf_cost_matrix, compute_vmf_params, compute_anti_invasion_loss
|
| 9 |
-
|
| 10 |
-
print('=== Test 1: Sinkhorn OT ===')
|
| 11 |
-
C = torch.randn(4, 3)
|
| 12 |
-
weights = sinkhorn_log(C, epsilon=0.05, n_iter=10)
|
| 13 |
-
print(f'Cost shape: {C.shape}, Weights shape: {weights.shape}')
|
| 14 |
-
print(f'Row sums: {weights.sum(dim=1)}')
|
| 15 |
-
print(f'Weights:\n{weights}')
|
| 16 |
-
|
| 17 |
-
print()
|
| 18 |
-
print('=== Test 2: vMF Parameter Estimation ===')
|
| 19 |
-
d = 1024
|
| 20 |
-
n = 100
|
| 21 |
-
raw = torch.randn(n, d)
|
| 22 |
-
features = F.normalize(raw, dim=-1)
|
| 23 |
-
mu, kappa = compute_vmf_params(features, d)
|
| 24 |
-
print(f'mu shape: {mu.shape}, norm: {mu.norm():.4f}')
|
| 25 |
-
print(f'kappa: {kappa.item():.4f}')
|
| 26 |
-
|
| 27 |
-
print()
|
| 28 |
-
print('=== Test 3: vmf_cost_matrix ===')
|
| 29 |
-
x = F.normalize(torch.randn(4, d), dim=-1)
|
| 30 |
-
sigs = {0: (mu, kappa)}
|
| 31 |
-
prompt_key = torch.randn(1, d)
|
| 32 |
-
C2 = vmf_cost_matrix(x, sigs, prompt_key=prompt_key, default_kappa=10.0)
|
| 33 |
-
print(f'Cost matrix shape: {C2.shape}')
|
| 34 |
-
|
| 35 |
-
weights2 = sinkhorn_log(C2, epsilon=0.05, n_iter=10)
|
| 36 |
-
print(f'OT weights shape: {weights2.shape}, row sums: {weights2.sum(dim=1)}')
|
| 37 |
-
print(f'Weights:\n{weights2}')
|
| 38 |
-
|
| 39 |
-
print()
|
| 40 |
-
print('=== Test 4: Anti-invasion loss ===')
|
| 41 |
-
x_new = F.normalize(torch.randn(8, d), dim=-1)
|
| 42 |
-
sigs2 = {0: (mu, torch.tensor(5.0)), 1: (F.normalize(torch.randn(d), dim=-1), torch.tensor(8.0))}
|
| 43 |
-
inv_loss = compute_anti_invasion_loss(x_new, sigs2, current_task_id=2, threshold=2.3)
|
| 44 |
-
print(f'Invasion loss: {inv_loss.item():.6f}')
|
| 45 |
-
|
| 46 |
-
print()
|
| 47 |
-
print('=== Test 5: FP16 compatibility ===')
|
| 48 |
-
C_fp16 = torch.randn(8, 5, dtype=torch.float16)
|
| 49 |
-
w_fp16 = sinkhorn_log(C_fp16.float(), epsilon=0.05, n_iter=10).half()
|
| 50 |
-
print(f'FP16 output: {w_fp16.shape}, dtype: {w_fp16.dtype}')
|
| 51 |
-
print(f'Row sums: {w_fp16.sum(dim=1)}')
|
| 52 |
-
|
| 53 |
-
print()
|
| 54 |
-
print('=== All tests passed! ===')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/agnews/dev.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/agnews/labels.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/agnews/test.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/agnews/train.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/amazon/dev.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/amazon/labels.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/amazon/test.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/amazon/train.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/boolq/dev.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/boolq/labels.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/boolq/test.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/boolq/train.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/cb/dev.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/cb/labels.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/cb/test.json
RENAMED
|
File without changes
|
{gainlora_OT_vMF β root_gainlora}/CL_Benchmark/Long_Sequence/cb/train.json
RENAMED
|
File without changes
|