import torch


def flatten(params):
    """
    Turns a module's parameters (or gradients) into a flat numpy array
        
    params: the module's parameters (or gradients)
    """
    with torch.no_grad():
        return torch.cat([p.data.view(-1) for p in params])