import torch


def flatten_grad(grad):
    """
    Flattens the gradient tensor to a rank 1 tensor
    """
    tuple_to_list = []
    for tensor in grad:
        tuple_to_list.append(tensor.view(-1))
    all_flattened = torch.cat(tuple_to_list)
    return all_flattened