Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'torch.dtype' object has no attribute 'kind' #286

Open
Coluding opened this issue Dec 2, 2024 · 0 comments
Open

AttributeError: 'torch.dtype' object has no attribute 'kind' #286

Coluding opened this issue Dec 2, 2024 · 0 comments

Comments

@Coluding
Copy link

Coluding commented Dec 2, 2024

Hi!

I am getting with torch=2.5.1, torch_geometric=2.4.0 and torch_geometric_temporal=0.54.0 and the following simple script:

from torch_geometric_temporal.signal import DynamicGraphTemporalSignal
import torch
import torch_geometric_temporal
import torch_geometric

print(torch_geometric_temporal.__version__)
print(torch_geometric.__version__)

# Node features for each time step (varying number of nodes)
node_features = [
    torch.tensor([[1, 2], [3, 4], [5, 6]], dtype=torch.float), 
    torch.tensor([[2, 3], [4, 5]], dtype=torch.float),         
    torch.tensor([[3, 4], [5, 6], [7, 8], [9, 10]], dtype=torch.float) 
]

# Edge indices for each time step
edge_indices = [
    torch.tensor([[0, 1], [1, 2]], dtype=torch.long).t(),  
    torch.tensor([[0, 1]], dtype=torch.long).t(),          
    torch.tensor([[0, 1], [1, 2], [2, 3]], dtype=torch.long).t()  
]

# Define edge attributes (optional)
edge_attributes = [
    torch.tensor([[0.1], [0.2]], dtype=torch.float), 
    torch.tensor([[0.3]], dtype=torch.float),        
    torch.tensor([[0.5], [0.6], [0.7]], dtype=torch.float)  
]

# Define targets for each time step (optional)
targets = [
    torch.tensor([0.5, 0.6, 0.7], dtype=torch.float), 
    torch.tensor([0.6, 0.7], dtype=torch.float),     
    torch.tensor([0.7, 0.8, 0.9, 1.0], dtype=torch.float)  
]

# Create a DynamicGraphTemporalSignal object
temporal_graph = DynamicGraphTemporalSignal(edge_indices, node_features, edge_attributes, targets)

print(temporal_graph[0])

The following error: AttributeError: 'torch.dtype' object has no attribute 'kind' stemming from the getitem call in temporal_graph[0].

It comes from this part in DynamicGraphTemporalSignal:


    def _get_target(self, time_index: int):
        if self.targets[time_index] is None:
            return self.targets[time_index]
        else:
            if not self.targets[time_index].dtype.kind == "i":
                return torch.LongTensor(self.targets[time_index])
            elif not self.targets[time_index].dtype.kind == "f":
                return torch.FloatTensor(self.targets[time_index])



Switching it to:

    def _get_target(self, time_index: int):
        if self.targets[time_index] is None:
            return self.targets[time_index]
        else:
            if not self.targets[time_index].dtype.is_floating_point:
                return torch.FloatTensor(self.targets[time_index])
            else:
                return torch.LongTensor(self.targets[time_index])

fixed it.

This is a probably a torch version mismatch. Can you validate my versions? Otherwise I will just keep the workaround.

Best regards and thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant