fix: add explicit imports for DistributedSampler, DataLoader, IterableDatasetShard, ipdb
Browse files
root_gainlora/runtest_colab.ipynb
CHANGED
|
@@ -226,10 +226,18 @@
|
|
| 226 |
},
|
| 227 |
{
|
| 228 |
"cell_type": "code",
|
| 229 |
-
"execution_count":
|
| 230 |
"id": "6257b4db",
|
| 231 |
"metadata": {},
|
| 232 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
"source": [
|
| 234 |
"# Cell for remove run\n",
|
| 235 |
"%cd ../..\n",
|
|
@@ -288,7 +296,7 @@
|
|
| 288 |
},
|
| 289 |
{
|
| 290 |
"cell_type": "code",
|
| 291 |
-
"execution_count":
|
| 292 |
"id": "ad592075",
|
| 293 |
"metadata": {},
|
| 294 |
"outputs": [
|
|
@@ -296,67 +304,49 @@
|
|
| 296 |
"name": "stdout",
|
| 297 |
"output_type": "stream",
|
| 298 |
"text": [
|
| 299 |
-
"
|
| 300 |
-
"\n",
|
| 301 |
"Traceback (most recent call last):\n",
|
| 302 |
-
" File \"/content/Continual/root_gainlora/src/run_t5.py\", line
|
| 303 |
" main()\n",
|
| 304 |
-
" File \"/content/Continual/root_gainlora/src/run_t5.py\", line
|
| 305 |
-
"
|
| 306 |
-
"
|
| 307 |
-
"
|
| 308 |
-
"
|
| 309 |
-
"
|
| 310 |
-
"
|
| 311 |
-
"
|
| 312 |
-
"
|
| 313 |
-
" File \"/usr/local/lib/python3.12/dist-packages/datasets/load.py\", line 1823, in dataset_module_factory\n",
|
| 314 |
-
" ).get_module()\n",
|
| 315 |
-
" ^^^^^^^^^^^^\n",
|
| 316 |
-
" File \"/usr/local/lib/python3.12/dist-packages/datasets/load.py\", line 968, in get_module\n",
|
| 317 |
-
" trust_remote_code = resolve_trust_remote_code(self.trust_remote_code, self.name)\n",
|
| 318 |
-
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
| 319 |
-
" File \"/usr/local/lib/python3.12/dist-packages/datasets/load.py\", line 134, in resolve_trust_remote_code\n",
|
| 320 |
-
" raise ValueError(\n",
|
| 321 |
-
"ValueError: The repository for cl_dataset contains custom code which must be executed to correctly load the dataset. You can inspect the repository content at https://hf.co/datasets/cl_dataset.\n",
|
| 322 |
-
"Please pass the argument `trust_remote_code=True` to allow custom code to be run.\n",
|
| 323 |
"\n",
|
| 324 |
"RC: 0\n"
|
| 325 |
]
|
| 326 |
}
|
| 327 |
],
|
| 328 |
"source": [
|
| 329 |
-
"#
|
| 330 |
"import subprocess\n",
|
| 331 |
-
"
|
| 332 |
-
" ['bash', '-c', '''\n",
|
| 333 |
"cd /content/Continual/root_gainlora\n",
|
|
|
|
| 334 |
"CUDA_VISIBLE_DEVICES=0 python src/run_t5.py \\\n",
|
| 335 |
-
" --do_train --predict_with_generate \\\n",
|
| 336 |
-
" --model_name_or_path google/flan-t5-large \\\n",
|
| 337 |
" --data_dir CL_Benchmark \\\n",
|
| 338 |
" --task_order yelp,amazon,mnli,cb,copa,qqp,rte,imdb,sst2,dbpedia,agnews,yahoo,multirc,boolq,wic \\\n",
|
| 339 |
" --task_config_dir configs/gen_script_long_order3_t5_configs/yelp \\\n",
|
| 340 |
-
" --output_dir /
|
| 341 |
-
" --per_device_train_batch_size 8 --per_device_eval_batch_size 128 \\\n",
|
| 342 |
-
" --
|
| 343 |
-
" --
|
| 344 |
-
" --
|
| 345 |
-
" --
|
| 346 |
-
" --
|
| 347 |
-
" --
|
| 348 |
-
" --
|
| 349 |
-
" --
|
| 350 |
-
"
|
| 351 |
-
"
|
| 352 |
-
"
|
| 353 |
-
")\n",
|
| 354 |
-
"# Only print last 1500 chars\n",
|
| 355 |
-
"out = result.stdout[-1500:] if result.stdout else \"\"\n",
|
| 356 |
-
"err = result.stderr[-500:] if result.stderr else \"\"\n",
|
| 357 |
-
"print(out)\n",
|
| 358 |
-
"if err: print(\"ERR:\", err)\n",
|
| 359 |
-
"print(\"RC:\", result.returncode)"
|
| 360 |
]
|
| 361 |
}
|
| 362 |
],
|
|
|
|
| 226 |
},
|
| 227 |
{
|
| 228 |
"cell_type": "code",
|
| 229 |
+
"execution_count": 8,
|
| 230 |
"id": "6257b4db",
|
| 231 |
"metadata": {},
|
| 232 |
+
"outputs": [
|
| 233 |
+
{
|
| 234 |
+
"name": "stdout",
|
| 235 |
+
"output_type": "stream",
|
| 236 |
+
"text": [
|
| 237 |
+
"/content\n"
|
| 238 |
+
]
|
| 239 |
+
}
|
| 240 |
+
],
|
| 241 |
"source": [
|
| 242 |
"# Cell for remove run\n",
|
| 243 |
"%cd ../..\n",
|
|
|
|
| 296 |
},
|
| 297 |
{
|
| 298 |
"cell_type": "code",
|
| 299 |
+
"execution_count": null,
|
| 300 |
"id": "ad592075",
|
| 301 |
"metadata": {},
|
| 302 |
"outputs": [
|
|
|
|
| 304 |
"name": "stdout",
|
| 305 |
"output_type": "stream",
|
| 306 |
"text": [
|
| 307 |
+
"ing: False -----\n",
|
| 308 |
+
"tmp\n",
|
| 309 |
"Traceback (most recent call last):\n",
|
| 310 |
+
" File \"/content/Continual/root_gainlora/src/run_t5.py\", line 923, in <module>\n",
|
| 311 |
" main()\n",
|
| 312 |
+
" File \"/content/Continual/root_gainlora/src/run_t5.py\", line 743, in main\n",
|
| 313 |
+
" trainer.get_reg_matrix()\n",
|
| 314 |
+
" File \"/content/Continual/root_gainlora/src/cl_trainer_gainlora_inflora.py\", line 143, in get_reg_matrix\n",
|
| 315 |
+
" self.feature_list, self.feature_trans_list, self._cur_task = self.load_previous_reg_matrix()\n",
|
| 316 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
| 317 |
+
" File \"/content/Continual/root_gainlora/src/cl_trainer_gainlora_inflora.py\", line 118, in load_previous_reg_matrix\n",
|
| 318 |
+
" all_dirs = os.listdir(log_path)\n",
|
| 319 |
+
" ^^^^^^^^^^^^^^^^^^^^\n",
|
| 320 |
+
"FileNotFoundError: [Errno 2] No such file or directory: 'tmp'\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
"\n",
|
| 322 |
"RC: 0\n"
|
| 323 |
]
|
| 324 |
}
|
| 325 |
],
|
| 326 |
"source": [
|
| 327 |
+
"# Test with real output path and --max_steps 3\n",
|
| 328 |
"import subprocess\n",
|
| 329 |
+
"r = subprocess.run(['bash', '-c', '''\n",
|
|
|
|
| 330 |
"cd /content/Continual/root_gainlora\n",
|
| 331 |
+
"rm -rf /root/.cache/huggingface/modules/datasets_modules/ 2>/dev/null || true\n",
|
| 332 |
"CUDA_VISIBLE_DEVICES=0 python src/run_t5.py \\\n",
|
| 333 |
+
" --do_train --predict_with_generate --model_name_or_path google/flan-t5-large \\\n",
|
|
|
|
| 334 |
" --data_dir CL_Benchmark \\\n",
|
| 335 |
" --task_order yelp,amazon,mnli,cb,copa,qqp,rte,imdb,sst2,dbpedia,agnews,yahoo,multirc,boolq,wic \\\n",
|
| 336 |
" --task_config_dir configs/gen_script_long_order3_t5_configs/yelp \\\n",
|
| 337 |
+
" --output_dir logs_and_outputs/gen_script_long_order3_t5_gainlora_inflora/outputs/1-yelp \\\n",
|
| 338 |
+
" --per_device_train_batch_size 8 --per_device_eval_batch_size 128 --gradient_accumulation_steps 4 \\\n",
|
| 339 |
+
" --learning_rate 0.0003 --num_train_epochs 1 --run_name test --max_source_length 512 \\\n",
|
| 340 |
+
" --max_target_length 50 --generation_max_length 50 --add_task_name False --add_dataset_name False \\\n",
|
| 341 |
+
" --overwrite_output_dir --overwrite_cache --lr_scheduler_type constant --warmup_steps 0 \\\n",
|
| 342 |
+
" --logging_strategy steps --logging_steps 10 --metric_for_best_model eval_exact_match \\\n",
|
| 343 |
+
" --evaluation_strategy steps --save_strategy steps --save_total_limit 1 --load_best_model_at_end \\\n",
|
| 344 |
+
" --lora_r 8 --lora_alpha 32 --lora_dropout 0.0 --add_instruction_replay --data_replay_freq -1 \\\n",
|
| 345 |
+
" --replay_after_n_epoch 0 --mlp_hidden_dim 100 --model_name gainlora_inflora \\\n",
|
| 346 |
+
" --threshold 0.995 --transthreshold 0.995 --max_steps 3 2>&1 | tail -15\n",
|
| 347 |
+
"'''], capture_output=True, text=True, timeout=300, cwd='/content')\n",
|
| 348 |
+
"print(r.stdout[-800:])\n",
|
| 349 |
+
"print(\"RC:\", r.returncode)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
]
|
| 351 |
}
|
| 352 |
],
|
root_gainlora/src/cl_trainer_gainlora_inflora.py
CHANGED
|
@@ -4,13 +4,22 @@ from transformers.trainer_seq2seq import Seq2SeqTrainer
|
|
| 4 |
from transformers.trainer import *
|
| 5 |
from transformers.trainer_callback import TrainerCallback
|
| 6 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
from cl_collator import SUPPORTED_DECODER_MODELS, check_model
|
| 9 |
from cl_dataset import ANSWER_PREFIX
|
| 10 |
import cupy as cp
|
| 11 |
from torch.utils.dlpack import to_dlpack, from_dlpack
|
| 12 |
from cupy import fromDlpack
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def skip_instructions(model, predictions_ids, tokenizer, ignore_idx=-100):
|
| 16 |
predictions_ids = np.where(predictions_ids == ignore_idx, tokenizer.pad_token_id, predictions_ids)
|
|
|
|
| 4 |
from transformers.trainer import *
|
| 5 |
from transformers.trainer_callback import TrainerCallback
|
| 6 |
import numpy as np
|
| 7 |
+
from torch.utils.data import DataLoader
|
| 8 |
+
from torch.utils.data.distributed import DistributedSampler
|
| 9 |
+
try:
|
| 10 |
+
from transformers.trainer_pt_utils import IterableDatasetShard
|
| 11 |
+
except ImportError:
|
| 12 |
+
from torch.utils.data import IterableDataset as IterableDatasetShard
|
| 13 |
|
| 14 |
from cl_collator import SUPPORTED_DECODER_MODELS, check_model
|
| 15 |
from cl_dataset import ANSWER_PREFIX
|
| 16 |
import cupy as cp
|
| 17 |
from torch.utils.dlpack import to_dlpack, from_dlpack
|
| 18 |
from cupy import fromDlpack
|
| 19 |
+
try:
|
| 20 |
+
import ipdb
|
| 21 |
+
except ImportError:
|
| 22 |
+
ipdb = None
|
| 23 |
|
| 24 |
def skip_instructions(model, predictions_ids, tokenizer, ignore_idx=-100):
|
| 25 |
predictions_ids = np.where(predictions_ids == ignore_idx, tokenizer.pad_token_id, predictions_ids)
|