File size: 2,008 Bytes
a2ffd07 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | from typing import NamedTuple
import torch
from jaxtyping import Float, Int
class TopK(NamedTuple):
"""The k largest latents. Wraps 'torch.return_types.topk'."""
values: Float[torch.Tensor, "batch pos k"]
"""The values of the k largest latents."""
indices: Int[torch.Tensor, "batch pos k"]
"""The indices of the k largest latents."""
class SAEOut(NamedTuple):
"""The output of the autoencoder forward pass."""
topk: TopK
"""The k largest latents."""
recons: torch.Tensor
"""The reconstructions from the k largest latents."""
auxk: TopK | None
"""If auxk is not None, the auxk largest dead latents."""
auxk_recons: torch.Tensor | None
"""If auxk is not None, the reconstructions from the auxk largest dead latents."""
dead: torch.Tensor
"""The fraction of dead latents."""
addtional_loss: torch.Tensor | float
"""The additional loss to backward."""
additional_log_dict: dict[str, torch.Tensor | float] = {}
"""The additional log dictionary to log."""
class CrosscoderOut(NamedTuple):
"""The output of the autoencoder forward pass."""
topk: TopK
"""The k largest latents."""
recons: torch.Tensor
"""The reconstructions from the k largest latents."""
cross_recons: list[torch.Tensor]
"""The cross-layer-reconstructions from the k largest latents."""
auxk: TopK | None
"""If auxk is not None, the auxk largest dead latents."""
auxk_recons: torch.Tensor | None
"""If auxk is not None, the reconstructions from the auxk largest dead latents."""
dead: torch.Tensor
"""The fraction of dead latents."""
addtional_loss: torch.Tensor | float
"""The additional loss to backward."""
additional_log_dict: dict[str, torch.Tensor | float] = {}
"""The additional log dictionary to log."""
class Stats(NamedTuple):
"""Used to standardize the input activation vectors."""
mean: torch.Tensor
std: torch.Tensor
|