def duplicate_interleave(m):
    """
    A simple version of `torch.repeat_interleave` for duplicating a matrix while interleaving the copy.
    """
    dim0 = m.shape[0]
    m = m.view(-1, 1)  # flatten the matrix
    m = m.repeat(1, 2)  # repeat all elements into the 2nd dimension
    m = m.view(dim0, -1)  # reshape into a matrix, interleaving the copy
    return m

    A simple version of `torch.repeat_interleave` for duplicating a matrix while interleaving the copy.
    
dpkd/transformers/src/transformers/models/gptj_parallel/modeling_gptj_parallel.py