def unwrap_model(model):
    """
    Unwrap a model from a DataParallel or DistributedDataParallel wrapper.
    """
    if isinstance(model, (nn.DataParallel, nn.parallel.DistributedDataParallel)):
        return model.module
    else:
        return model
Unwrap a model from a DataParallel or DistributedDataParallel wrapper.
open_flamingo/eval/utils.py