(output)
| 71 | |
| 72 | |
| 73 | def _get_hook_tensor(output): |
| 74 | if isinstance(output, torch.Tensor): |
| 75 | return output |
| 76 | if isinstance(output, (tuple, list)) and output: |
| 77 | first = output[0] |
| 78 | if isinstance(first, torch.Tensor): |
| 79 | return first |
| 80 | raise TypeError(f"Unsupported target hook output type: {type(output)!r}") |
| 81 | |
| 82 | |
| 83 | def run_target_forward_with_hooks( |