LAVIS icon indicating copy to clipboard operation
LAVIS copied to clipboard

TypeError: 'NoneType' object is not iterable

Open cactusycy opened this issue 2 years ago • 6 comments

Hey, guys. I just encountered a very annoying problem. After downloading the dataset and setting the path, I typed the "bash run_scripts/blip2/train/pretrain_stage1.sh"and hope it could work. However, the error comes. It may be dataset issues but I can not figure out why it happened after downloading the dataset and setting the path. Looking forward to your reply.

| distributed init (rank 0, world 1): env:// INFO - 2024-02-17 16:10:47,640 - config - ===== Running Parameters ===== INFO - 2024-02-17 16:10:47,641 - config - { "amp": true, "batch_size_eval": 64, "batch_size_train": 100, "device": "cuda", "dist_backend": "nccl", "dist_url": "env://", "distributed": true, "evaluate": false, "gpu": 0, "init_lr": 0.0001, "lr_sched": "linear_warmup_cosine_lr", "max_epoch": 10, "min_lr": 1e-05, "num_workers": 4, "output_dir": "output/BLIP2/Pretrain_stage1", "rank": 0, "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 } INFO - 2024-02-17 16:10:47,641 - config - ====== Dataset Attributes ====== INFO - 2024-02-17 16:10:47,641 - config - ======== coco_caption ======= INFO - 2024-02-17 16:10:47,642 - config - { "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": "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" } } } INFO - 2024-02-17 16:10:47,642 - config - ======== vg_caption ======= INFO - 2024-02-17 16:10:47,642 - config - { "build_info": { "annotations": { "train": { "storage": "vg/annotations/vg_caption.json", "url": "https://storage.googleapis.com/sfr-vision-language-research/LAVIS/datasets/visual_genome/vg_caption.json" } }, "images": { "storage": "vg/images/" } }, "data_type": "images", "text_processor": { "train": { "name": "blip_caption" } }, "vis_processor": { "train": { "image_size": 224, "name": "blip_image_train" } } } INFO - 2024-02-17 16:10:47,642 - config - ====== Model Attributes ====== INFO - 2024-02-17 16:10:47,642 - config - { "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: /root/autodl-tmp/lavis/coco/annotations/coco_karpathy_train.json Using downloaded and verified file: /root/autodl-tmp/lavis/coco/annotations/coco_karpathy_val.json Using downloaded and verified file: /root/autodl-tmp/lavis/coco/annotations/coco_karpathy_test.json INFO - 2024-02-17 16:10:47,643 - base_dataset_builder - Building datasets... Using downloaded and verified file: /root/autodl-tmp/lavis/vg/annotations/vg_caption.json INFO - 2024-02-17 16:10:48,682 - base_dataset_builder - Building datasets... INFO - 2024-02-17 16:11:18,378 - blip2_qformer - freeze vision encoder INFO - 2024-02-17 16:11:41,841 - runner_base - Start training INFO - 2024-02-17 16:11:42,834 - runner_base - dataset_ratios not specified, datasets will be concatenated (map-style datasets) or chained (webdataset.DataPipeline). INFO - 2024-02-17 16:11:42,834 - runner_base - Loaded 1388521 records for train split from the dataset. INFO - 2024-02-17 16:11:42,834 - runner_base - Loaded 5000 records for val split from the dataset. INFO - 2024-02-17 16:11:42,834 - runner_base - Loaded 5000 records for test split from the dataset. INFO - 2024-02-17 16:11:42,839 - runner_base - number of trainable parameters: 186705470 INFO - 2024-02-17 16:11:42,841 - base_task - Start training epoch 0, 13885 iters per inner epoch. Traceback (most recent call last): File "train.py", line 103, in main() File "train.py", line 99, in main runner.train() File "/root/LAVIS/lavis/runners/runner_base.py", line 384, in train train_stats = self.train_epoch(cur_epoch) File "/root/LAVIS/lavis/runners/runner_base.py", line 451, in train_epoch return self.task.train_epoch( File "/root/LAVIS/lavis/tasks/base_task.py", line 116, in train_epoch return self._train_inner_loop( File "/root/LAVIS/lavis/tasks/base_task.py", line 207, in _train_inner_loop samples = next(data_loader) File "/root/LAVIS/lavis/datasets/datasets/dataloader_utils.py", line 149, in next data = next(self.iter_loader) File "/root/LAVIS/lavis/datasets/datasets/dataloader_utils.py", line 59, in iter self.preload(loader_it) File "/root/LAVIS/lavis/datasets/datasets/dataloader_utils.py", line 77, in preload self.batch = next(it) File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 631, in next data = self._next_data() File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1346, in _next_data return self._process_data(data) File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1372, in _process_data data.reraise() File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/_utils.py", line 722, in reraise raise exception TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop data = fetcher.fetch(index) File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch return self.collate_fn(data) File "/root/LAVIS/lavis/datasets/datasets/base_dataset.py", line 85, in collater all_keys.update(s) TypeError: 'NoneType' object is not iterable

[2024-02-17 16:11:50,735] torch.distributed.elastic.multiprocessing.api: [ERROR] failed (exitcode: 1) local_rank: 0 (pid: 1198) of binary: /root/miniconda3/envs/lavis/bin/python Traceback (most recent call last): File "/root/miniconda3/envs/lavis/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/root/miniconda3/envs/lavis/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/distributed/run.py", line 816, in main() File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/distributed/elastic/multiprocessing/errors/init.py", line 347, in wrapper return f(*args, **kwargs) File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/distributed/run.py", line 812, in main run(args) File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/distributed/run.py", line 803, in run elastic_launch( File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 135, in call return launch_agent(self._config, self._entrypoint, list(args)) File "/root/miniconda3/envs/lavis/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 268, in launch_agent raise ChildFailedError( torch.distributed.elastic.multiprocessing.errors.ChildFailedError:

train.py FAILED

Failures: <NO_OTHER_FAILURES>

Root Cause (first observed failure): [0]: time : 2024-02-17_16:11:50 host : autodl-container-5df045955b-762e857d rank : 0 (local_rank: 0) exitcode : 1 (pid: 1198) error_file: <N/A> traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html

cactusycy avatar Feb 17 '24 10:02 cactusycy

Using a single coco dataset can help solve this issue.

cactusycy avatar Feb 20 '24 10:02 cactusycy

Using a single coco dataset can help solve this issue.

Thank you! I came across the same problem and I use a single coco datset did solve it. However, If I use a single vg dataset, the same problem came out. Any idea to solve this problem thoroughly?

JasonCZH4 avatar Mar 10 '24 16:03 JasonCZH4

I figured out how this bug happens. When constructing the VG dataset, the __getitem__ method of ImageTextPairDataset class in datasets/image_text_pair_datasets.py do not handle the VG dataset images path properly. It simply read the path from the annotation file vg_caption.json without doing some string operation resulting in the read image path and the actual image path will never match. A thorough solution is adding a .split(''/)[-1] operation to get a complete image_path = os.path.join(self.vis_root, ann["image"].split('/')[-1]) operation like coco datset does. And add a assert in the following try-catch part instead of simply returning a None which causes the above TypeError.

JasonCZH4 avatar Mar 11 '24 05:03 JasonCZH4

Using a single coco dataset can help solve this issue.

hi, how to use a single coco dataset,

gzwo-O avatar Jun 11 '24 09:06 gzwo-O

use a single coco datset

Can I kindly ask how to use a single coco dataset? Thank you

hengdezhu avatar Sep 18 '24 17:09 hengdezhu

Hi, @JasonCZH4 @cactusycy I am getting the same error although using single coco dataset validation dataset from download_coco.py file for the training.

/content/LAVIS/env/lib/python3.10/site-packages/fairscale/experimental/nn/offload.py:19: FutureWarning: `torch.cuda.amp.custom_fwd(args...)` is deprecated. Please use `torch.amp.custom_fwd(args..., device_type='cuda')` instead.
  return torch.cuda.amp.custom_fwd(orig_func)  # type: ignore
/content/LAVIS/env/lib/python3.10/site-packages/fairscale/experimental/nn/offload.py:30: FutureWarning: `torch.cuda.amp.custom_bwd(args...)` is deprecated. Please use `torch.amp.custom_bwd(args..., device_type='cuda')` instead.
  return torch.cuda.amp.custom_bwd(orig_func)  # type: ignore
/content/LAVIS/env/lib/python3.10/site-packages/transformers/utils/generic.py:311: FutureWarning: `torch.utils._pytree._register_pytree_node` is deprecated. Please use `torch.utils._pytree.register_pytree_node` instead.
  torch.utils._pytree._register_pytree_node(
/content/LAVIS/env/lib/python3.10/site-packages/transformers/utils/generic.py:311: FutureWarning: `torch.utils._pytree._register_pytree_node` is deprecated. Please use `torch.utils._pytree.register_pytree_node` instead.
  torch.utils._pytree._register_pytree_node(
/content/LAVIS/env/lib/python3.10/site-packages/transformers/utils/generic.py:311: FutureWarning: `torch.utils._pytree._register_pytree_node` is deprecated. Please use `torch.utils._pytree.register_pytree_node` instead.
  torch.utils._pytree._register_pytree_node(
/content/LAVIS/env/lib/python3.10/site-packages/diffusers/models/cross_attention.py:30: FutureWarning: Importing from cross_attention is deprecated. Please import from diffusers.models.attention_processor instead.
  deprecate(
/content/LAVIS/env/lib/python3.10/site-packages/transformers/utils/generic.py:311: FutureWarning: `torch.utils._pytree._register_pytree_node` is deprecated. Please use `torch.utils._pytree.register_pytree_node` instead.
  torch.utils._pytree._register_pytree_node(
Not using distributed mode
2025-01-23 12:38:01,709 [INFO] 
=====  Running Parameters    =====
2025-01-23 12:38:01,710 [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:38:01,710 [INFO] 
======  Dataset Attributes  ======
2025-01-23 12:38:01,710 [INFO] 
======== coco_caption =======
2025-01-23 12:38:01,711 [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:38:01,711 [INFO] 
======  Model Attributes  ======
2025-01-23 12:38:01,711 [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:38:01,711 [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:38:19,477 [INFO] freeze vision encoder
2025-01-23 12:38:22,957 [INFO] Start training
2025-01-23 12:38:23,729 [INFO] dataset_ratios not specified, datasets will be concatenated (map-style datasets) or chained (webdataset.DataPipeline).
2025-01-23 12:38:23,730 [INFO] Loaded 566747 records for train split from the dataset.
2025-01-23 12:38:23,730 [INFO] Loaded 5000 records for val split from the dataset.
2025-01-23 12:38:23,730 [INFO] Loaded 5000 records for test split from the dataset.
2025-01-23 12:38:23,737 [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:38:23,738 [INFO] Start training epoch 0, 283373 iters per inner epoch.
Traceback (most recent call last):
  File "/content/LAVIS/train.py", line 104, in <module>
    main()
  File "/content/LAVIS/train.py", line 100, 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

Is there any other way to solve this?

parth1313 avatar Jan 23 '25 12:01 parth1313