Skip to content

expand

torch_to_nnef.op.aten.expand

expand

expand(node, inference_target, op_helper, **kwargs)

Translate operator aten::expand to NNEF.

Illustration of expand:. torch.arange(9).reshape(3, 3).expand(2, 3, 3)

Out[4]:
tensor([[[0, 1, 2],
         [3, 4, 5],
         [6, 7, 8]],

        [[0, 1, 2],
         [3, 4, 5],
         [6, 7, 8]]])
which can be re-expressed as

torch.arange(9).reshape(3, 3).repeat(2).reshape(2, 3, 3)

this allows us to express it as a NNEF tile followed by a reshape.

repeat

repeat(g, node, name_to_tensor, op_helper, inference_target, **kwargs)

Map PyTorch: 'aten:repeat' to NNEF.

repeat_interleave

repeat_interleave(g, node, name_to_tensor, inference_target, **kwargs)

This is same as np.repeat.

Equivalent with repeat

te = y new = te.unsqueeze(dim+1) new_repeats = [1] * (len(te.shape) + 1) new_repeats[ dim + 1 ] = n_repeat shapes = list(te.shape) shapes[dim] *= n_repeat new.repeat(new_repeats).reshape(shapes)