LAVIS icon indicating copy to clipboard operation
LAVIS copied to clipboard

BLIP2 training Issue

Open parth1313 opened this issue 1 year ago • 1 comments

I am getting this error when start training script :

Not using distributed mode
2025-01-23 12:15:29,677 [INFO] 
=====  Running Parameters    =====
2025-01-23 12:15:29,678 [INFO] {
    "amp": true,
    "batch_size_eval": 1,
    "batch_size_train": 2,
    "device": "cuda",
    "dist_url": "env://",
    "distributed": false,
    "evaluate": false,
    "init_lr": 0.0001,
    "lr_sched": "linear_warmup_cosine_lr",
    "max_epoch": 2,
    "min_lr": 1e-05,
    "num_workers": 1,
    "output_dir": "output/BLIP2/Pretrain_stage1",
    "resume_ckpt_path": null,
    "seed": 42,
    "task": "image_text_pretrain",
    "train_splits": [
        "train"
    ],
    "warmup_lr": 1e-06,
    "warmup_steps": 5000,
    "weight_decay": 0.05,
    "world_size": 1
}
2025-01-23 12:15:29,678 [INFO] 
======  Dataset Attributes  ======
2025-01-23 12:15:29,678 [INFO] 
======== coco_caption =======
2025-01-23 12:15:29,679 [INFO] {
    "build_info": {
        "annotations": {
            "test": {
                "md5": "3ff34b0ef2db02d01c37399f6a2a6cd1",
                "storage": "coco/annotations/coco_karpathy_test.json",
                "url": "https://storage.googleapis.com/sfr-vision-language-research/datasets/coco_karpathy_test.json"
            },
            "train": {
                "md5": "aa31ac474cf6250ebb81d18348a07ed8",
                "storage": "coco/annotations/coco_karpathy_train.json",
                "url": "https://storage.googleapis.com/sfr-vision-language-research/datasets/coco_karpathy_train.json"
            },
            "val": {
                "md5": "b273847456ef5580e33713b1f7de52a0",
                "storage": "coco/annotations/coco_karpathy_val.json",
                "url": "https://storage.googleapis.com/sfr-vision-language-research/datasets/coco_karpathy_val.json"
            }
        },
        "images": {
            "storage": "/export/home/.cache/lavis/coco/images"
        }
    },
    "data_type": "images",
    "dataset_card": "dataset_card/coco_caption.md",
    "text_processor": {
        "train": {
            "name": "blip_caption"
        }
    },
    "vis_processor": {
        "train": {
            "image_size": 224,
            "name": "blip2_image_train"
        }
    }
}
2025-01-23 12:15:29,679 [INFO] 
======  Model Attributes  ======
2025-01-23 12:15:29,679 [INFO] {
    "arch": "blip2",
    "drop_path_rate": 0,
    "finetuned": "",
    "freeze_vit": true,
    "image_size": 224,
    "load_finetuned": false,
    "load_pretrained": false,
    "model_type": "pretrain",
    "num_query_token": 32,
    "pretrained": "https://storage.googleapis.com/sfr-vision-language-research/LAVIS/models/BLIP2/blip2_pretrained.pth",
    "use_grad_checkpoint": false,
    "vit_precision": "fp16"
}
Using downloaded and verified file: /export/home/.cache/lavis/coco/annotations/coco_karpathy_train.json
Using downloaded and verified file: /export/home/.cache/lavis/coco/annotations/coco_karpathy_val.json
Using downloaded and verified file: /export/home/.cache/lavis/coco/annotations/coco_karpathy_test.json
2025-01-23 12:15:29,680 [INFO] Building datasets...
/content/LAVIS/env/lib/python3.10/site-packages/huggingface_hub/file_download.py:1142: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
  warnings.warn(
/content/LAVIS/lavis/models/eva_vit.py:446: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  state_dict = torch.load(cached_file, map_location="cpu")
2025-01-23 12:15:47,776 [INFO] freeze vision encoder

2025-01-23 12:15:51,346 [INFO] Start training
2025-01-23 12:15:52,116 [INFO] dataset_ratios not specified, datasets will be concatenated (map-style datasets) or chained (webdataset.DataPipeline).
2025-01-23 12:15:52,116 [INFO] Loaded 566747 records for train split from the dataset.
2025-01-23 12:15:52,116 [INFO] Loaded 5000 records for val split from the dataset.
2025-01-23 12:15:52,116 [INFO] Loaded 5000 records for test split from the dataset.
2025-01-23 12:15:52,123 [INFO] number of trainable parameters: 186705470
/content/LAVIS/lavis/runners/runner_base.py:128: FutureWarning: `torch.cuda.amp.GradScaler(args...)` is deprecated. Please use `torch.amp.GradScaler('cuda', args...)` instead.
  self._scaler = torch.cuda.amp.GradScaler()
2025-01-23 12:15:52,125 [INFO] Start training epoch 0, 283373 iters per inner epoch.
Traceback (most recent call last):
  File "/content/LAVIS/train.py", line 107, in <module>
    main()
  File "/content/LAVIS/train.py", line 103, in main
    runner.train()
  File "/content/LAVIS/lavis/runners/runner_base.py", line 384, in train
    train_stats = self.train_epoch(cur_epoch)
  File "/content/LAVIS/lavis/runners/runner_base.py", line 451, in train_epoch
    return self.task.train_epoch(
  File "/content/LAVIS/lavis/tasks/base_task.py", line 116, in train_epoch
    return self._train_inner_loop(
  File "/content/LAVIS/lavis/tasks/base_task.py", line 207, in _train_inner_loop
    samples = next(data_loader)
  File "/content/LAVIS/lavis/datasets/datasets/dataloader_utils.py", line 149, in __next__
    data = next(self.iter_loader)
  File "/content/LAVIS/lavis/datasets/datasets/dataloader_utils.py", line 59, in __iter__
    self.preload(loader_it)
  File "/content/LAVIS/lavis/datasets/datasets/dataloader_utils.py", line 77, in preload
    self.batch = next(it)
  File "/content/LAVIS/env/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 701, in __next__
    data = self._next_data()
  File "/content/LAVIS/env/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1465, in _next_data
    return self._process_data(data)
  File "/content/LAVIS/env/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1491, in _process_data
    data.reraise()
  File "/content/LAVIS/env/lib/python3.10/site-packages/torch/_utils.py", line 715, in reraise
    raise exception
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/content/LAVIS/env/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py", line 351, in _worker_loop
    data = fetcher.fetch(index)  # type: ignore[possibly-undefined]
  File "/content/LAVIS/env/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 55, in fetch
    return self.collate_fn(data)
  File "/content/LAVIS/lavis/datasets/datasets/base_dataset.py", line 85, in collater
    all_keys.update(s)
TypeError: 'NoneType' object is not iterable

I have tried with both Coco captions and vg captions datasets. Anyone know the solution?

parth1313 avatar Jan 23 '25 12:01 parth1313

@parth1313 hi,sorry to bother you. I'm a student trying to train BLIP2. how did you solve this problem?? I have tried this for thousand times.Thank you. my English is not good,so if my expression is not clear,I would try to text again.

zz1888 avatar Jun 28 '25 13:06 zz1888