def get_device(module):
    """Returns the device of the module's parameters."""
    device = None
    for param in module.parameters():
        if device is None:
            device = param.device
            continue
        if device != param.device:
            raise ValueError("Parameters are allocated on different devices.")
    if device is None:
        raise ValueError("No parameters are available in the module.")
    return device