Skip to content

Commit

Permalink
add test of optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock committed Oct 27, 2024
1 parent b8c2bde commit bacd269
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_forward(self):

def test_loss_and_grad(self):
model = FSRS(DEFAULT_PARAMETER)
optimizer = torch.optim.Adam(model.parameters(), lr=4e-2)
loss_fn = nn.BCELoss(reduction="none")
t_histories = torch.tensor(
[
Expand Down Expand Up @@ -135,3 +136,31 @@ def test_loss_and_grad(self):
),
atol=1e-4,
)
optimizer.step()
assert torch.allclose(
model.w,
torch.tensor(
[
0.44255,
1.22385,
3.2129998,
15.65105,
7.2349,
0.4945,
1.4204,
0.0446,
1.5057501,
0.1592,
0.97925,
1.9794999,
0.07000001,
0.33605,
2.3097994,
0.2715,
2.9498,
0.47655,
0.62210006,
]
),
atol=1e-4,
)

0 comments on commit bacd269

Please sign in to comment.