{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d5ac353e", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import argparse\n", "import os\n", "import shutil\n", "import random\n", "from PIL import Image\n", "\n", "import numpy as np\n", "import torch\n", "import torch.backends.cudnn as cudnn\n", "from transformers import StoppingCriteria, StoppingCriteriaList\n", "\n", "import lavis.tasks as tasks\n", "from lavis.common.config import Config\n", "from lavis.common.dist_utils import get_rank, init_distributed_mode\n", "from lavis.common.logger import setup_logger\n", "from lavis.common.optims import (\n", " LinearWarmupCosineLRScheduler,\n", " LinearWarmupStepLRScheduler,\n", ")\n", "from lavis.common.registry import registry\n", "from lavis.common.utils import now\n", "\n", "# imports modules for registration\n", "from lavis.datasets.builders import *\n", "from lavis.models import *\n", "from lavis.processors import *\n", "from lavis.runners import *\n", "from lavis.tasks import *" ] }, { "cell_type": "code", "execution_count": null, "id": "4fdef7a6", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "shutil.copytree('/ibex/project/c2133/vicuna', '/tmp/vicuna')" ] }, { "cell_type": "code", "execution_count": 2, "id": "661f9e80", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "class StoppingCriteriaSub(StoppingCriteria):\n", "\n", " def __init__(self, stops = [], encounters=1):\n", " super().__init__()\n", " self.stops = stops\n", "\n", " def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):\n", " for stop in self.stops:\n", " if torch.all((stop == input_ids[0][-len(stop):])).item():\n", " return True\n", "\n", " return False\n", "\n", "\n", "stop_words_ids = [torch.tensor([835]).to('cuda:0'), \n", " torch.tensor([2277, 29937]).to('cuda:0')] # '###' can be encoded in different ways.\n", "stopping_criteria = StoppingCriteriaList([StoppingCriteriaSub(stops=stop_words_ids)])" ] }, { "cell_type": "code", "execution_count": 6, "id": "1822a77a", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "parser = argparse.ArgumentParser(description=\"Training\")\n", "\n", "parser.add_argument(\"--cfg-path\", required=True, help=\"path to configuration file.\")\n", "parser.add_argument(\n", " \"--options\",\n", " nargs=\"+\",\n", " help=\"override some settings in the used config, the key-value pair \"\n", " \"in xxx=yyy format will be merged into config file (deprecate), \"\n", " \"change to --cfg-options instead.\",\n", ")\n", "\n", "args = parser.parse_args([\"--cfg-path\", \"lavis/projects/blip2/train/vicuna_pretrain_stage2_cc.yaml\"])\n", "\n", "cfg = Config(args)\n", "device = 'cuda:0'" ] }, { "cell_type": "code", "execution_count": 4, "id": "57e90f19", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "vis_processor_cfg = cfg.datasets_cfg.cc_combine.vis_processor.train\n", "vis_processor = registry.get_processor_class(vis_processor_cfg.name).from_config(vis_processor_cfg)" ] }, { "cell_type": "code", "execution_count": 7, "id": "4cc521da", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading LLAMA\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "abeac6970d914446adc1fb73f7e5b5f9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading checkpoint shards: 0%| | 0/3 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Loading LLAMA Done\n", "Load BLIP2-LLM Checkpoint: /home/zhud/project/blip2/lavis/output/BLIP2/Vicuna_pretrain_stage2_cc/20230405233/checkpoint_3.pth\n" ] }, { "data": { "text/html": [ "
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮\n", "│ in <module>:2 │\n", "│ │\n", "│ 1 task = tasks.setup_task(cfg) │\n", "│ ❱ 2 model = task.build_model(cfg) │\n", "│ 3 │\n", "│ │\n", "│ /home/zhud/project/blip2/lavis/tasks/base_task.py:33 in build_model │\n", "│ │\n", "│ 30 │ │ model_config = cfg.model_cfg │\n", "│ 31 │ │ │\n", "│ 32 │ │ model_cls = registry.get_model_class(model_config.arch) │\n", "│ ❱ 33 │ │ return model_cls.from_config(model_config) │\n", "│ 34 │ │\n", "│ 35 │ def build_datasets(self, cfg): │\n", "│ 36 │ │ \"\"\" │\n", "│ │\n", "│ /home/zhud/project/blip2/lavis/models/blip2_models/blip2_llama.py:315 in from_config │\n", "│ │\n", "│ 312 │ │ ckpt_path = cfg.get(\"ckpt\", \"\") │\n", "│ 313 │ │ if ckpt_path: │\n", "│ 314 │ │ │ print(\"Load BLIP2-LLM Checkpoint: {}\".format(ckpt_path)) │\n", "│ ❱ 315 │ │ │ ckpt = torch.load(ckpt_path, map_location=\"cpu\") │\n", "│ 316 │ │ │ msg = model.load_state_dict(ckpt['model'], strict=False) │\n", "│ 317 │ │ │\n", "│ 318 │ │ return model │\n", "│ │\n", "│ /home/zhud/anaconda3/envs/eye/lib/python3.9/site-packages/torch/serialization.py:791 in load │\n", "│ │\n", "│ 788 │ if 'encoding' not in pickle_load_args.keys(): │\n", "│ 789 │ │ pickle_load_args['encoding'] = 'utf-8' │\n", "│ 790 │ │\n", "│ ❱ 791 │ with _open_file_like(f, 'rb') as opened_file: │\n", "│ 792 │ │ if _is_zipfile(opened_file): │\n", "│ 793 │ │ │ # The zipfile reader is going to advance the current file position. │\n", "│ 794 │ │ │ # If we want to actually tail call to torch.jit.load, we need to │\n", "│ │\n", "│ /home/zhud/anaconda3/envs/eye/lib/python3.9/site-packages/torch/serialization.py:271 in │\n", "│ _open_file_like │\n", "│ │\n", "│ 268 │\n", "│ 269 def _open_file_like(name_or_buffer, mode): │\n", "│ 270 │ if _is_path(name_or_buffer): │\n", "│ ❱ 271 │ │ return _open_file(name_or_buffer, mode) │\n", "│ 272 │ else: │\n", "│ 273 │ │ if 'w' in mode: │\n", "│ 274 │ │ │ return _open_buffer_writer(name_or_buffer) │\n", "│ │\n", "│ /home/zhud/anaconda3/envs/eye/lib/python3.9/site-packages/torch/serialization.py:252 in __init__ │\n", "│ │\n", "│ 249 │\n", "│ 250 class _open_file(_opener): │\n", "│ 251 │ def __init__(self, name, mode): │\n", "│ ❱ 252 │ │ super().__init__(open(name, mode)) │\n", "│ 253 │ │\n", "│ 254 │ def __exit__(self, *args): │\n", "│ 255 │ │ self.file_like.close() │\n", "╰──────────────────────────────────────────────────────────────────────────────────────────────────╯\n", "FileNotFoundError: [Errno 2] No such file or directory: \n", "'/home/zhud/project/blip2/lavis/output/BLIP2/Vicuna_pretrain_stage2_cc/20230405233/checkpoint_3.pth'\n", "\n" ], "text/plain": [ "\u001B[31m╭─\u001B[0m\u001B[31m──────────────────────────────\u001B[0m\u001B[31m \u001B[0m\u001B[1;31mTraceback \u001B[0m\u001B[1;2;31m(most recent call last)\u001B[0m\u001B[31m \u001B[0m\u001B[31m───────────────────────────────\u001B[0m\u001B[31m─╮\u001B[0m\n", "\u001B[31m│\u001B[0m in \u001B[92m