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

Simply concatenating the source indices and condition indices even when they are from different codebooks? #228

Open
abcqmars opened this issue Oct 5, 2023 · 2 comments

Comments

@abcqmars
Copy link

abcqmars commented Oct 5, 2023

Hi, I got a puzzle when I was reading the code of Net2NetTransformer
cond_transformer.py:80

    def forward(self, x, c):
        # one step to produce the logits
        _, z_indices = self.encode_to_z(x)
        _, c_indices = self.encode_to_c(c)

        if self.training and self.pkeep < 1.0:
            mask = torch.bernoulli(self.pkeep*torch.ones(z_indices.shape,
                                                         device=z_indices.device))
            mask = mask.round().to(dtype=torch.int64)
            r_indices = torch.randint_like(z_indices, self.transformer.config.vocab_size)
            a_indices = mask*z_indices+(1-mask)*r_indices
        else:
            a_indices = z_indices

        cz_indices = torch.cat((c_indices, a_indices), dim=1)

        # target includes all sequence elements (no need to handle first one
        # differently because we are conditioning)
        target = z_indices
        # make the prediction
        logits, _ = self.transformer(cz_indices[:, :-1])

The condition like depth images has thier own specifically trained codebook, so their indices should have different meanings with that of rgb image code book.
But in this code snippet above, It seems that we simply concatenate them and feed into transformer.

Where the transformer will process them in one shared token embeding layer as shown in mingpt.py:162

   def forward(self, idx, embeddings=None, targets=None):
        # forward the GPT model
        token_embeddings = self.tok_emb(idx) # each index maps to a (learnable) vector

Is this implementation correct? Or I have a wrong understanding of it?

@zch42
Copy link

zch42 commented Dec 8, 2023

I have the same question

1 similar comment
@qinxiangyujiayou
Copy link

I have the same question

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