LAVIS icon indicating copy to clipboard operation
LAVIS copied to clipboard

[Bug] AttributeError: 'list' object has no attribute 'view'

Open SnowNation101 opened this issue 2 years ago • 8 comments

I tried to finetune blip2 for retrieval, using script train_retrieval_coco.sh. I got error:

Traceback (most recent call last):
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/train.py", line 103, in <module>
    main()
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/train.py", line 99, in main
    runner.train()
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/runners/runner_base.py", line 384, in train
    train_stats = self.train_epoch(cur_epoch)
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/runners/runner_base.py", line 451, in train_epoch
    return self.task.train_epoch(
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/tasks/base_task.py", line 116, in train_epoch
    return self._train_inner_loop(
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/tasks/base_task.py", line 226, in _train_inner_loop
    loss, loss_dict = self.train_step(model=model, samples=samples)
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/tasks/base_task.py", line 63, in train_step
    output = model(samples)
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/nn/parallel/distributed.py", line 1040, in forward
    output = self._run_ddp_forward(*inputs, **kwargs)
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/nn/parallel/distributed.py", line 1000, in _run_ddp_forward
    return module_to_run(*inputs[0], **kwargs[0])
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/models/blip2_models/blip2_qformer.py", line 160, in forward
    image_ids = samples["image_id"].view(-1,1)
AttributeError: 'list' object has no attribute 'view'

I tried to change line 160 in blip2_qformer.py from

image_ids = samples["image_id"].view(-1,1)

to

image_ids = torch.tensor(samples["image_id"]).view(-1,1)

but got error bellow instead:

Traceback (most recent call last):
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/train.py", line 103, in <module>
    main()
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/train.py", line 99, in main
    runner.train()
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/runners/runner_base.py", line 384, in train
    train_stats = self.train_epoch(cur_epoch)
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/runners/runner_base.py", line 451, in train_epoch
    return self.task.train_epoch(
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/tasks/base_task.py", line 116, in train_epoch
    return self._train_inner_loop(
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/tasks/base_task.py", line 226, in _train_inner_loop
    loss, loss_dict = self.train_step(model=model, samples=samples)
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/tasks/base_task.py", line 63, in train_step
    output = model(samples)
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/nn/parallel/distributed.py", line 1040, in forward
    output = self._run_ddp_forward(*inputs, **kwargs)
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/nn/parallel/distributed.py", line 1000, in _run_ddp_forward
    return module_to_run(*inputs[0], **kwargs[0])
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/models/blip2_models/blip2_qformer.py", line 161, in forward
    image_ids_all = concat_all_gather(image_ids)
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/bingxing2/home/scx6964/chenghao_zhang/lavis/lavis/models/base_model.py", line 253, in concat_all_gather
    torch.distributed.all_gather(tensors_gather, tensor, async_op=False)
  File "/home/bingxing2/home/scx6964/.local/lib/python3.9/site-packages/torch/distributed/distributed_c10d.py", line 2275, in all_gather
    work = default_pg.allgather([tensor_list], [tensor])
RuntimeError: Tensors must be CUDA and dense

Can you help me with this?

SnowNation101 avatar Feb 27 '24 10:02 SnowNation101

fixed by changing it to

image_ids = torch.tensor(samples["image_id"]).view(-1,1).to(image.device)

SnowNation101 avatar Feb 27 '24 15:02 SnowNation101

ValueError: too many dimensions 'str' 我用你的修改后又报了这个错误,想问一下是怎么回事

shaonian526-526 avatar Mar 04 '24 06:03 shaonian526-526

我的image_id是字符串形式,所以不能直接转换,但我下载的数据集也是这里推荐的,不知道一个怎么弄?

shaonian526-526 avatar Mar 04 '24 07:03 shaonian526-526

ValueError: too many dimensions 'str' 我的image_id是字符串形式,所以不能直接转换,但我下载的数据集也是这里推荐的,不知道一个怎么弄?

torch tensor cant accept strings. In the coco dataset provided, image_id is in a format like 'coco_522418', then it will be parsed into 522418, which is not a string. Maybe you can try to make it like this, hope this would help.

btw, I'm not familiar with github community, I think it would be more appropriate to disscuss in English 😄

SnowNation101 avatar Mar 04 '24 16:03 SnowNation101

ValueError: too many dimensions 'str' 我的image_id是字符串形式,所以不能直接转换,但我下载的数据集也是这里推荐的,不知道一个怎么弄?

torch tensor cant accept strings. In the coco dataset provided, image_id is in a format like 'coco_522418', then it will be parsed into 522418, which is not a string. Maybe you can try to make it like this, hope this would help.

btw, I'm not familiar with github community, I think it would be more appropriate to disscuss in English 😄

Thank you for your answer! I also solved the problem later on. And it is indeed more convenient to communicate in English on GitHub, I'm sorry.

shaonian526-526 avatar Mar 04 '24 16:03 shaonian526-526

ValueError: too many dimensions 'str' 我的image_id是字符串形式,所以不能直接转换,但我下载的数据集也是这里推荐的,不知道一个怎么弄?

torch tensor cant accept strings. In the coco dataset provided, image_id is in a format like 'coco_522418', then it will be parsed into 522418, which is not a string. Maybe you can try to make it like this, hope this would help. btw, I'm not familiar with github community, I think it would be more appropriate to disscuss in English 😄

Thank you for your answer! I also solved the problem later on. And it is indeed more convenient to communicate in English on GitHub, I'm sorry.

你好,我也碰到了相似的问题,请问你就是按照上述的方法解决的吗?还是有什么其他的改动呢?谢谢

gitac10 avatar Jul 19 '24 05:07 gitac10

ValueError: too many dimensions 'str' 我的image_id是字符串形式,所以不能直接转换,但我下载的数据集也是这里推荐的,不知道一个怎么弄?

torch tensor cant accept strings. In the coco dataset provided, image_id is in a format like 'coco_522418', then it will be parsed into 522418, which is not a string. Maybe you can try to make it like this, hope this would help. btw, I'm not familiar with github community, I think it would be more appropriate to disscuss in English 😄

Thank you for your answer! I also solved the problem later on. And it is indeed more convenient to communicate in English on GitHub, I'm sorry.

你好,我也碰到了相似的问题,请问你就是按照上述的方法解决的吗?还是有什么其他的改动呢?谢谢

Duplicate of #629

heegreis avatar Aug 30 '24 05:08 heegreis

@shaonian526-526

ValueError: too many dimensions 'str' 我的image_id是字符串形式,所以不能直接转换,但我下载的数据集也是这里推荐的,不知道一个怎么弄?

torch tensor cant accept strings. In the coco dataset provided, image_id is in a format like 'coco_522418', then it will be parsed into 522418, which is not a string. Maybe you can try to make it like this, hope this would help. btw, I'm not familiar with github community, I think it would be more appropriate to disscuss in English 😄

Thank you for your answer! I also solved the problem later on. And it is indeed more convenient to communicate in English on GitHub, I'm sorry.

你好,我遇到了相同的問題,請問您怎麼解決的呢??謝謝

zz1888 avatar Jun 29 '25 13:06 zz1888