Question about `relative_coords_table` buffer in Swin V2.

Author: BlueDruddigonCreated Aug 2, 2023Updated Nov 15, 2025

In Swin Transformer V2, as proposed using Log-Space CPB,

In the code implementation, log-spaced coordinates are generated when transferring across window sizes through relative_coords_table like in this code snippet.

https://github.com/microsoft/Swin-Transformer/blob/f92123a0035930d89cf53fcb8257199481c4428d/models/swin_transformer_v2.py#L109-L111

I have two questions:

  • Does it mean to be 8 and np.log2(8) ? Why do you do that ?
  • And if I do not multiply relative_coords_table by 8 and remove the afterwards divided by np.log2(8), what has changed?

Source: microsoft/Swin-Transformer