def apply_to(x, device, non_blocking=False):
    """Apply `to` function to object x only if it has `to`."""

    if device == "pinned" and hasattr(x, "pin_memory"):
        return x.pin_memory()
    if not hasattr(x, "to"):
        return x
    if not non_blocking:
        return x.to(device)
    return x.to(device, non_blocking=True)
Apply `to` function to object x only if it has `to`.
python/dgl/graphbolt/base.py