我正试图编码GNN示例问题,如给定链接所示:https://towardsdatascience.com/hands-on-graph-neural-networks-with-pytorch-pytorch-geometric-359487e221a8
我用的是Macbook Pro 2016版,没有Nvidia显卡!
示例问题是实现'CUDA'工具包。我可以修改代码并在我现在的笔记本电脑上运行吗?我已经使数据集足够小,这样它就不需要高计算,可以在我的PC上运行!
给出错误的部分代码如下!
def train():
model.train()
loss_all = 0
for data in train_loader:
data = data.to(device)
optimizer.zero_grad()
output = model(data)
label = data.y.to(device)
loss = crit(output, label)
loss.backward()
loss_all += data.num_graphs * loss.item()
optimizer.step()
return loss_all / len(train_dataset)
device = torch.device('cuda')
model = Net().to(device) # Net = A class inherited from torch.nn.Module
optimizer = torch.optim.Adam(model.parameters(), lr=0.005)
crit = torch.nn.BCELoss()
train_loader = DataLoader(train_dataset, batch_size=batch_size)
for epoch in range(num_epochs):
train()
错误如下
AssertionError: Torch not compiled with CUDA enabled
您正在使用:
device = torch.device('cuda')
如果您想使用cpu,请更改为:
device = torch.device('cpu')