Skip to content

Commit

Permalink
Update test.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Okerew authored Aug 30, 2024
1 parent 32b9593 commit bc66016
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from okrolearn.okrolearn import *
from okrolearn.optimizers import SGDOptimizer
from okrolearn.optimizers import SGDOptimizer, RMSPropOptimizer

def print_epoch_start(epoch, total_epochs):
print(f"Starting epoch {epoch + 1}/{total_epochs}")
Expand Down Expand Up @@ -28,10 +28,39 @@ def print_epoch_start(epoch, total_epochs):
network.add(GELUActivationLayer())
inputs = Tensor(np.random.rand(100, 3))
targets = Tensor(np.random.randint(0, 3, size=(100,)))
hyperparameters = [
{
'lr_scheduler': LearningRateScheduler(initial_lr=0.01),
'optimizer': SGDOptimizer(lr=0.01),
'temperature': 1.0
},
{
'lr_scheduler': StepLRScheduler(initial_lr=0.001, step_size=30, gamma=0.1),
'optimizer': AdamOptimizer(lr=0.001, beta1=0.9, beta2=0.999, epsilon=1e-8),
'temperature': 1.0
},
{
'lr_scheduler': ExponentialDecayScheduler(initial_lr=0.001, decay_rate=0.1),
'optimizer': NadamOptimizer(epsilon=1e-8),
'temperature': 0.5
},
{
'lr_scheduler': LinearDecayScheduler(initial_lr=0.001, final_lr=0.0001, total_epochs=100),
'optimizer': AdadeltaOptimizer(epsilon=1e-8),
'temperature': 1.5
},
{
'lr_scheduler': TimeBasedDecayScheduler(initial_lr=0.001, decay_rate=0.01),
'optimizer': RMSPropOptimizer(lr=0.001, epsilon=1e-8),
'temperature': 1.0
}
]

network.hyperparameter_tuning(inputs, targets, batch_size=10, epochs=30, loss_function=CrossEntropyLoss(), hyperparameters=hyperparameters)
loss_function = CrossEntropyLoss()
optimizer = SGDOptimizer(lr=0.01)

losses = network.train(inputs, targets, epochs=50, lr=0.01, optimizer=optimizer, batch_size=10, loss_function=loss_function, )
losses = network.train(inputs, targets, epochs=50, lr_scheduler=LearningRateScheduler(0.01), optimizer=optimizer, batch_size=10, loss_function=loss_function, )
network.plot_parameter_changes()
network.analyze_gradients()
network.print_profile_stats()
Expand Down Expand Up @@ -61,7 +90,7 @@ def print_epoch_start(epoch, total_epochs):
test_network.add(GELUActivationLayer())

test_network.load_weights('model.pt')
test_network.train(inputs, targets, epochs=50, lr=0.01, optimizer=optimizer, batch_size=10, loss_function=loss_function)
test_network.train(inputs, targets, epochs=50, lr_scheduler=LearningRateScheduler(0.01), optimizer=optimizer, batch_size=10, loss_function=loss_function)
test_network.save("model2.pt")

test_inputs = Tensor(np.random.rand(10, 3))
Expand Down

0 comments on commit bc66016

Please sign in to comment.