UserWarning: __floordiv__is deprecated, and its behavior will change in a future version of pytorch.

Error message:

UserWarning: __floordiv__is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the ‘trunc’ function NOT ‘floor’). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode=‘trunc’), or for actual floor division, use torch.div(a, b, rounding_mode=‘floor’).
dim_t = self.temperature ** (2 * (dim_t // 2) / self.num_pos_feats)

The wrong code:

dim_t = self.temperature ** (2 * (dim_t // 2) / self.num_pos_feats)

solution:

This warning is caused by a behavior change in the new version of Pytorch. It is recommended to replace the operator "//" with "torch.div()" in the code to avoid this warning.
For example, my code has the following operations:

dim_t = self.temperature ** (2 * (dim_t // 2) / self.num_pos_feats)

Then it can be modified to:

dim_t = self.temperature ** (2 * torch.div(dim_t, 2, rounding_mode='trunc') / self.num_pos_feats)

problem solved! ! !

Guess you like

Origin blog.csdn.net/Ayu147258/article/details/129903137