Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cls_head 计算特征时维度不匹配? #16

Open
lichen14 opened this issue Jul 10, 2024 · 2 comments
Open

cls_head 计算特征时维度不匹配? #16

lichen14 opened this issue Jul 10, 2024 · 2 comments

Comments

@lichen14
Copy link

lichen14 commented Jul 10, 2024

cls_outs = cls_head(features, anchor_boxes, query_features)

我在跑这行代码的时候总是会遇到embeddings和prompts特征维度不匹配的问题,导致

pred_logits = (embeddings * prompts.unsqueeze(1)).sum(dim=-1)

这里无法直接矩阵乘

比如:

  • 计算
    cls_outs = cls_head(features, anchor_boxes, query_features)

    时,embeddings 和 prompts.unsqueeze(1) 的shape 分别是 torch.Size([8192, 3, 512]) torch.Size([8192, 1, 3, 512]) ,这样直接计算会显存爆炸,需要384G ** 我试过把prompts.unsqueeze(1) 去掉unsqueeze(1) ,这样不报显存OOM的bug了,但是下面的代码会报错:
  • 计算
    cls_outs2 = cls_head(features_a, clip_boxes, clip_target_features)

    时,embeddings 和 prompts的shape是torch.Size([1536, 3, 512]) torch.Size([1536, 512]),这时候就会有 RuntimeError: The size of tensor a (3) must match the size of tensor b (1536) at non-singleton dimension 1 。此时如果加上prompts.unsqueeze(1)就不会报错了

所以,是否是代码历史版本的问题?有无最新版的可行代码呀?

@lichen14 lichen14 changed the title CUDA out of memory. Tried to allocate 384.00 GiB ! ! ?? cls_head 计算特征时维度不匹配? Jul 11, 2024
@gs-max
Copy link

gs-max commented Nov 11, 2024

cls_outs = cls_head(features, anchor_boxes, query_features)

我在跑这行代码的时候总是会遇到embeddings和prompts特征维度不匹配的问题,导致

pred_logits = (embeddings * prompts.unsqueeze(1)).sum(dim=-1)

这里无法直接矩阵乘
比如:

  • 计算

    cls_outs = cls_head(features, anchor_boxes, query_features)

    时,embeddings 和 prompts.unsqueeze(1) 的shape 分别是 torch.Size([8192, 3, 512]) torch.Size([8192, 1, 3, 512]) ,这样直接计算会显存爆炸,需要384G ** 我试过把prompts.unsqueeze(1) 去掉unsqueeze(1) ,这样不报显存OOM的bug了,但是下面的代码会报错:

  • 计算

    cls_outs2 = cls_head(features_a, clip_boxes, clip_target_features)

    时,embeddings 和 prompts的shape是torch.Size([1536, 3, 512]) torch.Size([1536, 512]),这时候就会有 RuntimeError: The size of tensor a (3) must match the size of tensor b (1536) at non-singleton dimension 1 。此时如果加上prompts.unsqueeze(1)就不会报错了

所以,是否是代码历史版本的问题?有无最新版的可行代码呀?

你好,请问问题解决了吗?

@Hzzone
Copy link
Owner

Hzzone commented Nov 12, 2024

这个问题我测试过了,用我上传的处理好的数据没有问题,应该是做数据这一部分我在整理的时候shape不一致导致的。
解决的方法也很简单:

if len(prompts.size()) == 2:

加上一两行就好了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants