Skip to content

Commit

Permalink
Added proper unit test failure case
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyTheSouthernSnowman committed Jul 2, 2024
1 parent f269031 commit c2cde95
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/test_oddly_specific_issue_i_found.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
OUTPUT_DIMS = 220

class TestBug(unittest.TestCase):
ALPHA = 10

def optimal_mse(self, y_pred: Tensor, y_true: Tensor, weights: Tensor) -> Tensor:
"""
This is sort of the core of what I was trying to do. I'm trying to avoid overfitting for
Expand All @@ -20,7 +18,7 @@ def optimal_mse(self, y_pred: Tensor, y_true: Tensor, weights: Tensor) -> Tensor
"""
mse = (y_pred - y_true).pow(2).mean()

nonzero_penalty = (self.ALPHA * weights).abs().sum() / (weights.shape[0]) # If this is removed, the bug disappears.
nonzero_penalty = weights.abs().sum() / (weights.shape[0]) # If this is removed, the bug disappears.

return mse + nonzero_penalty # Add it so if it is smaller, loss is smaller

Expand Down Expand Up @@ -50,7 +48,11 @@ def test_bug(self):
loss = self.optimal_mse(output_pred, output, flat_l3.cat(flat_l4))
loss.backward()
opt.step()
print(loss.numpy())
try:
print(loss.numpy())

except Exception as e:
self.fail(f"Strange bug detected: {e}")


if __name__ == '__main__':
Expand Down

0 comments on commit c2cde95

Please sign in to comment.