class roll():
使用NPU亲和写法替换swin-transformer中的原生roll。
from torch_npu.contrib.function import roll shifted_x_npu = roll(input1, shifts=(-shift_size, -shift_size), dims=(1, 2))
>>> input1 = torch.randn(32, 56, 56, 16).npu() >>> shift_size = 3 >>> shifted_x_npu = roll(input1, shifts=(-shift_size, -shift_size), dims=(1, 2))