Solved by 111414 in post #2 
              
              
                I found this code works:  
def get_orth_matrix(M, N):
    m = torch.randn(N, N)
    return torch.qr(m)[0].t()[:M]  # orthogonal matrix with shape of (M, N)