Configuration for recording outputs from a model via hooks. Attributes: target_class (Type): The class (e.g., nn.Module) to which the hook will be attached. index (Optional[int]): If the output is a tuple/list, optionally record only at a specific index. layer_name
| 39 | @dataclass |
| 40 | @requires(backends=("torch",)) |
| 41 | class OutputRecorder: |
| 42 | """ |
| 43 | Configuration for recording outputs from a model via hooks. |
| 44 | |
| 45 | Attributes: |
| 46 | target_class (Type): The class (e.g., nn.Module) to which the hook will be attached. |
| 47 | index (Optional[int]): If the output is a tuple/list, optionally record only at a specific index. |
| 48 | layer_name (Optional[str]): Name of the submodule to target (if needed), e.g., "transformer.layer.3.attn". |
| 49 | class_name (Optional[str]): Name of the class to which the hook will be attached. Could be the suffix of class name in some cases. |
| 50 | capture_initial_hidden_state (bool): Whether to prepend the first module's input as the initial hidden state. |
| 51 | """ |
| 52 | |
| 53 | target_class: type[nn.Module] |
| 54 | index: int = 0 |
| 55 | layer_name: str | None = None |
| 56 | class_name: str | None = None |
| 57 | capture_initial_hidden_state: bool = True |
| 58 | |
| 59 | |
| 60 | class CompileableContextVar: |
no outgoing calls
no test coverage detected