Coder Social home page Coder Social logo

Comments (12)

szxuhongye avatar szxuhongye commented on September 3, 2024 1

@szxuhongye also, can you give the full trace?
torch 1.13.1 and the following is the full trace:

Traceback (most recent call last):
File "playground.py", line 39, in
loss = coca(
File "/home/usr/anaconda3/envs/coca/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/home/usr/anaconda3/envs/coca/lib/python3.8/site-packages/coca_pytorch/coca_pytorch.py", line 433, in forward
image_embeds, image_tokens = self.embed_image(images=images, image_tokens=image_tokens)
File "/home/usr/anaconda3/envs/coca/lib/python3.8/site-packages/coca_pytorch/coca_pytorch.py", line 412, in embed_image
img_queries = self.img_attn_pool(img_queries, image_tokens)
File "/home/usr/anaconda3/envs/coca/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/home/usr/anaconda3/envs/coca/lib/python3.8/site-packages/coca_pytorch/coca_pytorch.py", line 245, in forward
context = self.context_norm(context)
File "/home/usr/anaconda3/envs/coca/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/home/usr/anaconda3/envs/coca/lib/python3.8/site-packages/coca_pytorch/coca_pytorch.py", line 25, in forward
return F.layer_norm(x, x.shape[-1:], self.gamma, self.beta)
File "/home/usr/anaconda3/envs/coca/lib/python3.8/site-packages/torch/nn/functional.py", line 2515, in layer_norm
return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled)
RuntimeError: Expected weight to be of same shape as normalized_shape, but got weight of shape [1024] and normalized_shape = [1000]

from coca-pytorch.

lucidrains avatar lucidrains commented on September 3, 2024

does your image_dim on CoCa init match up with the dim of the vit?

from coca-pytorch.

lucidrains avatar lucidrains commented on September 3, 2024

could you post a simple reproducible script?

from coca-pytorch.

szxuhongye avatar szxuhongye commented on September 3, 2024

could you post a simple reproducible script?

I just ran the code that you provide in the README.md

import torch

from vit_pytorch.simple_vit_with_patch_dropout import SimpleViT
from vit_pytorch.extractor import Extractor

vit = SimpleViT(
image_size = 256,
patch_size = 32,
num_classes = 1000,
dim = 1024,
depth = 6,
heads = 16,
mlp_dim = 2048,
patch_dropout = 0.5 # https://arxiv.org/abs/2212.00794
)

vit = Extractor(vit, return_embeddings_only = True, detach = False)

from coca_pytorch.coca_pytorch import CoCa

coca = CoCa(
dim = 512, # model dimension
img_encoder = vit, # vision transformer - image encoder, returning image embeddings as (batch, seq, dim)
image_dim = 1024, # image embedding dimension, if not the same as model dimensions
num_tokens = 20000, # number of text tokens
unimodal_depth = 6, # depth of the unimodal transformer
multimodal_depth = 6, # depth of the multimodal transformer
dim_head = 64, # dimension per attention head
heads = 8, # number of attention heads
caption_loss_weight = 1., # weight on the autoregressive caption loss
contrastive_loss_weight = 1., # weight on the contrastive loss between image and text CLS embeddings
).cuda()

text = torch.randint(0, 20000, (4, 512)).cuda()
images = torch.randn(4, 3, 256, 256).cuda()

loss = coca(
text = text,
images = images,
return_loss = True # set this to True to get the full caption + contrastive loss
)

loss.backward()

from coca-pytorch.

lucidrains avatar lucidrains commented on September 3, 2024

@szxuhongye it runs for me

which version of coca-pytorch are you on? and are you on the latest vit-pytorch?

from coca-pytorch.

szxuhongye avatar szxuhongye commented on September 3, 2024

@szxuhongye it runs for me

which version of coca-pytorch are you on? and are you on the latest vit-pytorch?

coca-pytorch 0.07 and vit-pytorch 0.40.2

from coca-pytorch.

lucidrains avatar lucidrains commented on September 3, 2024

@szxuhongye hmm, that looks ok

which version of pytorch?

from coca-pytorch.

lucidrains avatar lucidrains commented on September 3, 2024

@szxuhongye also, can you give the full trace?

from coca-pytorch.

lucidrains avatar lucidrains commented on September 3, 2024

@szxuhongye i see, the Extractor may be broken in pytorch 1.13.1 and not returning the embeddings, and instead, returning the logits

from coca-pytorch.

lucidrains avatar lucidrains commented on September 3, 2024

@szxuhongye hmm no, it still works for me try running all the cells in that colab. it is also on pytorch 1.13.0

from coca-pytorch.

szxuhongye avatar szxuhongye commented on September 3, 2024

@szxuhongye hmm no, it still works for me try running all the cells in that colab. it is also on pytorch 1.13.0

It is truly wired that it works after I uninstall and reinstall the entire environment. Thank you for your response.

from coca-pytorch.

lucidrains avatar lucidrains commented on September 3, 2024

glad it is working now 😁

from coca-pytorch.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.