Coverage for transformer_lens/model_bridge/exceptions.py: 100%
6 statements
« prev ^ index » next coverage.py v7.10.1, created at 2026-04-30 01:33 +0000
« prev ^ index » next coverage.py v7.10.1, created at 2026-04-30 01:33 +0000
1"""Exceptions for TransformerBridge.
3This module contains custom exceptions used by the TransformerBridge.
4"""
5from __future__ import annotations
7import torch
10class StopAtLayerException(Exception):
11 """Exception raised when execution should stop at a specific layer.
13 This exception is used to implement stop_at_layer functionality by having
14 blocks check if they should stop and raise this exception, which is then
15 caught in the main forward pass.
16 """
18 def __init__(self, layer_output: torch.Tensor):
19 """Initialize with the output tensor from the layer where we stopped.
21 Args:
22 layer_output: The output tensor from the last layer that executed
23 """
24 self.layer_output = layer_output
25 super().__init__()