def model_device(model):
    """Determine the device the model is allocated on."""
    try:
        return str(next(model.parameters()).device)
    except StopIteration:
        pass
    return 'cpu'
