# Confusion about torch.nn.Transformer

**URL:** <https://discuss.pytorch.org/t/confusion-about-torch-nn-transformer/62198>\
**Category:** Uncategorized\
**Created:** [November 26, 2019, 7:41am UTC](https://discuss.pytorch.org/t/confusion-about-torch-nn-transformer/62198 "2019-11-26T07:41:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LiHaibo](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/898d66/32.png) [@LiHaibo](https://discuss.pytorch.org/u/LiHaibo)\
**Post date:** [November 26, 2019, 7:41am UTC](https://discuss.pytorch.org/t/confusion-about-torch-nn-transformer/62198/1 "2019-11-26T07:41:00Z")

</div>

hi, I’m a bit confusing with src\_mask and src\_key\_padding\_mask, the explanation on pytorch docs are  
**src\_mask** – the additive mask for the src sequence (optional).  
**src\_key\_padding\_mask** – the ByteTensor mask for src keys per batch (optional).  
In my opinion, src\_mask 's dimension is (S,S), and S is the max source length in batch, so i need to send input src\_mask (N,S,S) to the Transformer.I don’t know if i understand that correctly. I don’t understand the src\_key\_padding\_mask’s explanation on website docs, this is confusing me.  
for the provided example code ,  
output = transformer\_model(src, tgt, src\_mask=src\_mask, tgt\_mask=tgt\_mask)  
set the [src/tgt/memory]\_key\_padding\_mask are None as default, I’m a little confused about this operation.
