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