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

How to use "src_key_padding_mask" #253

Closed
LutherLin opened this issue May 20, 2024 · 2 comments
Closed

How to use "src_key_padding_mask" #253

LutherLin opened this issue May 20, 2024 · 2 comments

Comments

@LutherLin
Copy link

LutherLin commented May 20, 2024

In PyTorch's official nn.TransformerEncoder, there is a parameter called src_key_padding_mask, which represents the mask for source data keys in each batch (optional). Does the x_transformers library offer a similar optional masking method, specifically designed to mask only the keys?

        self.seqTransEncoder = ContinuousTransformerWrapper(
            dim_in = self.latent_dim, dim_out = self.latent_dim,
            emb_dropout = self.dropout,
            max_seq_len = 1024,
            attn_layers = Encoder(
                dim = self.latent_dim,
                depth = num_layers,
                heads = num_heads,
                ff_mult = int(np.round(ff_size / self.latent_dim)), 
                layer_dropout = self.dropout, cross_attn_tokens_dropout = 0,
            )
        )

I have defined the network structure above,then I want to use as:

padding_mask = ...#torch.Size([32, 50]) 
xseq = ... #torch.Size([50, 32, 384])
output = self.seqTransEncoder(xseq, .........=padding_mask)[1:] 

Which mask should I use?

@lucidrains
Copy link
Owner

@LutherLin yup of course

in this repository, it is simply mask for the key padding mask, the shape accepted is (batch, seq), and True denotes attend, False not attend

@lucidrains
Copy link
Owner

lucidrains commented May 28, 2024

in your example

padding_mask #   (batch, seq) - (50, 32)
xseq #   (batch, seq, feature dimension) - (50, 32, 384)

all my repositories adopt batch-first

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

2 participants