Skip to content

Commit 69fea8e

Browse files
committed
Fix loss computation error on cpu
1 parent c27e214 commit 69fea8e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pytorch_tutorial/logistic_regression/test_logistic_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_logistic_regression(show_plots=False):
4444

4545
# Convert dataset to PyTorch tensors and put them on GPU memory (if available)
4646
x_train = torch.from_numpy(inputs).float().to(device)
47-
y_train = torch.from_numpy(targets).int().to(device)
47+
y_train = torch.from_numpy(targets).long().to(device)
4848

4949
# Create data loader for loading data as batches
5050
blobs_dataloader = DataLoader(

pytorch_tutorial/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ def get_device():
1818

1919

2020
def get_parameter_count(model):
21-
"""Return the number of trainable parameters for a PyTorch model"""
21+
"""
22+
Return the number of trainable parameters for a PyTorch model
23+
24+
Args:
25+
model (torch.nn.Module): a PyTorch model
26+
"""
2227

2328
return sum(p.numel() for p in model.parameters() if p.requires_grad)
2429

@@ -81,7 +86,7 @@ def plot_decision_boundaries(model, x, y, title, device):
8186
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
8287

8388
# Convert mesh to PyTorch tensors and put it on device memory
84-
x_mesh = torch.FloatTensor(np.c_[xx.ravel(), yy.ravel()]).to(device)
89+
x_mesh = torch.tensor(np.c_[xx.ravel(), yy.ravel()], dtype=torch.float).to(device)
8590

8691
# Get predictions for mesh points
8792
with torch.no_grad():

0 commit comments

Comments
 (0)