How to modify the positional encoding in torch.nn.Transformer?

I am doing some experiments on positional encoding, and would like to use torch.nn.Transformer for my experiments.

But it seems there is no argument for me to change the positional encoding. I also cannot seem to find in the source code where the torch.nn.Transformer is handling tthe positional encoding.

How to change the default sin cos encoding to some of my custom-made encoding?

4 Likes