Skip to content

Commit

Permalink
added time logging
Browse files Browse the repository at this point in the history
  • Loading branch information
eljanmahammadli committed Dec 11, 2023
1 parent d8d8e9d commit a15ae20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions examples/alexnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
et = timeit.default_timer()
print(f"Predicted in {et-st:.3f} seconds. Idx: {idx}, Logit: {value:.3f}, Category: {cls}")

import matplotlib.pyplot as plt

plt.plot(logits.transpose().data)
plt.show()

if args.test:
expected_idx = 36
expected_value = 24.387
Expand Down
5 changes: 4 additions & 1 deletion examples/mnist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import timeit
import numpy as np
from gradipy.tensor import Tensor
import gradipy.nn as nn
Expand Down Expand Up @@ -51,6 +52,7 @@ def forward(self, X):
optimizer = optim.Adam([model.W1, model.W2], lr=lr)


st = timeit.default_timer()
# training loop
for epoch in range(epochs + 1):
optimizer.zero_grad()
Expand All @@ -67,6 +69,7 @@ def forward(self, X):
f"Epoch [{epoch+1}/{epochs}], Train Accuracy: {train_accuracy:.4f}, Val Accuracy: {val_accuracy:.4f}"
)


et = timeit.default_timer()
print(f"Trained in {et-st:.3f} seconds")
print(evaluate("train"))
print(evaluate("val"))
1 change: 0 additions & 1 deletion gradipy/nn/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(self, in_features: int, out_features: int, bias: bool = True) -> No
self.bias = Tensor(np.zeros(out_features, dtype=np.float32))

def forward(self, x: Tensor) -> Tensor:
# TODO: implement bias
if self.bias_ is True:
return x.matmul(self.weight) + self.bias
return x.matmul(self.weight) + self.bias
Expand Down

0 comments on commit a15ae20

Please sign in to comment.