Skip to content

Commit

Permalink
avoid division by 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jbloom-md committed Apr 10, 2024
1 parent e1ad1aa commit 2c7c6d8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sae_lens/training/sparse_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,6 @@ def _per_item_mse_loss_with_target_norm(
"""
target_centered = target - target.mean(dim=0, keepdim=True)
normalization = target_centered.norm(dim=-1, keepdim=True)
return torch.nn.functional.mse_loss(preds, target, reduction="none") / normalization
return torch.nn.functional.mse_loss(preds, target, reduction="none") / (
normalization + 1e-6
)

0 comments on commit 2c7c6d8

Please sign in to comment.