Skip to content

[feature request] hash of torch.Device #7228

@mariogeiger

Description

@mariogeiger

Do you think it is a good idea that torch.Device support hashing ?

hash(torch.device("cpu"))
TypeError: unhashable type: 'torch.Device'

On my side, it would be useful for cached functions like

@lru_cache()
def big_constant_tensor(x, y, device):
    return torch.tensor((1000, 1000), math.pi, device=device)

Currently I do this to avoid the problem

@lru_cache()
def big_constant_tensor(x, y, device_type, device_index):
    return torch.tensor((1000, 1000), math.pi, device=torch.device(device_type, device_index))

Metadata

Metadata

Assignees

No one assigned

    Labels

    todoNot as important as medium or high priority tasks, but we will work on these.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions