def repeat_interleave(context, node):
    """
    For now, we only support scalar repeats + None or 0 dim
    """

    def _parse_positional_args(context, node) -> Tuple[Var]:
        inputs = _get_inputs(
            context,
            node,
            expected={TorchFrontend.TORCHSCRIPT: 4},
            min_expected={TorchFrontend.TORCHEXPORT: 2, TorchFrontend.EXECUTORCH: 2},
        )
        nargs = len(inputs)

        x = inputs[0]
        repeats = inputs[1]
        dim = inputs[2] if nargs > 2 else None
        return x, repeats, dim

    def _parse_keyword_args(context, node, dim) -> Var:
        dim = _get_kwinputs(context, node, "dim", default=[dim])[0]
        return dim

    def repeat_interleave_dim0(x: Var, repeats_val: int, name: str = None) -> Var:
        """
        on a high level:
             x
             | tile in dim 0
             v
            [x, x, ...]
             | reshape to split the repeats
             v
            [[x],
             [x],
             ...]
             | transpose(1, 0)
             V
            [x^T, x^T, ...]
             | flatten
             V
            result
        """

        translation_kwargs = {}
        if name is not None:
            translation_kwargs["name"] = name

        x_shape = mb.shape(x=x)

        reps = [1] * x.rank
        reps[0] = repeats_val
        x_tiled = mb.tile(x=x, reps=reps)

        split_reps_shape = mb.concat(values=([repeats_val], x_shape), axis=0)
        x_reshaped = mb.reshape(x=x_tiled, shape=split_reps_shape)

        perm = [*range(x.rank + 1)]
        perm[0] = 1
        perm[1] = 0
        x_transposed = mb.transpose(x=x_reshaped, perm=perm)

        x_unaffected_sizes = mb.slice_by_index(x=x_shape, begin=[1], end=[x.rank])
        result_shape = mb.concat(values=([-1], x_unaffected_sizes), axis=0)
        result = mb.reshape(x=x_transposed, shape=result_shape, **translation_kwargs)

        return result

    x, repeats, dim = _parse_positional_args(context, node)
    dim = _parse_keyword_args(context, node, dim)

    repeats_val = repeats.val
    if isinstance(repeats_val, np.ndarray):
        repeats_val0 = np.expand_dims(repeats_val, 0).reshape(-1)[0]
        if np.any(repeats_val != repeats_val0):
            raise NotImplementedError(
                "Conversion for torch.repeat_interleave with Tensor repeats has not been implemented"
            )
        repeats_val = repeats_val0

    is_dim_0 = True
    # This would operate on the flattened input tensor
    if dim is None:
        x = mb.reshape(x=x, shape=(-1,))
    else:
        dim_val = dim.val
        assert dim_val is not None, "torch.repeat_interleave uses static dim"
        if dim_val < 0:
            dim_val += x.rank
        # non-0 dim requires additional pre and post treatment
        if dim_val != 0:
            is_dim_0 = False

    # quick return: repeat 1 is noop
    if repeats_val == 1:
        context.add(x, torch_name=node.name)
        return

    if is_dim_0:
        result = repeat_interleave_dim0(x, repeats_val, node.name)
    else:
        # pre treatment: permute to have dim 0
        perm2dim0 = [dim_val]
        for i in range(x.rank):
            if i != dim_val:
                perm2dim0.append(i)
        x = mb.transpose(x=x, perm=perm2dim0)

        result_of_dim0 = repeat_interleave_dim0(x, repeats_val)

        # post treatment: permute back to original dim
        perm_back = [0] * x.rank
        for i in range(x.rank):
            perm_back[perm2dim0[i]] = i
        result = mb.transpose(x=result_of_dim0, perm=perm_back, name=node.name)

    context.add(result)

    For now, we only support scalar repeats + None or 0 dim
    
coremltools/converters/mil/frontend/torch/ops.py