import torch


def flatten_parameters_wg(model):
    """
    Flattens parameters of a model but retains the gradient
    :return: 1D torch tensor with size N, with N the model paramters
    """
    return torch.cat([p.view(-1) for p in model.parameters()])